Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/ui/sanitize/leak.rs fails on Linux with sanitizers = true #111073

Closed
danakj opened this issue May 1, 2023 · 11 comments · Fixed by #135484
Closed

tests/ui/sanitize/leak.rs fails on Linux with sanitizers = true #111073

danakj opened this issue May 1, 2023 · 11 comments · Fixed by #135484
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danakj
Copy link
Contributor

danakj commented May 1, 2023

Chromium bug discussion here: https://bugs.chromium.org/p/chromium/issues/detail?id=1441181#c5

We want to build rustc with sanitizers = true in config.toml in order to get sanitizer runtimes. However when we do, the leak.rs test fails with a CHECK failure in LLVM.

error: error pattern ' LeakSanitizer: detected memory leaks' not found!
status: exit status: 23
command: cd "/home/danakj/s/c/src/third_party/rust_src/src/build/x86_64-unknown-linux-gnu/test/ui/sanitize/leak" && RUST_TEST_THREADS="72" "/home/danakj/s/c/src/third_party/rust_src/src/build/x86_64-unknown-linux-gnu/test/ui/sanitize/leak/a"
stdout: none
--- stderr -------------------------------
LeakSanitizer: CHECK failed: lsan_interceptors.cpp:82 "((!lsan_init_is_running)) != (0)" (0x0, 0x0) (tid=309157)
------------------------------------------

Which is failing a check inside the ENSURE_LSAN_INITED macro here: https://github.com/llvm/llvm-project/blob/89a44b0faee0ca6b741e1f0ef31163374887b6ed/compiler-rt/lib/lsan/lsan_interceptors.cpp#L82

We're building against LLVM HEAD-ish, so I tried with upstream rustc and the test fails when compiled with that as well (reduced command line from the actual test invocation):

% rustc --version
rustc 1.71.0-nightly (9ecda8de8 2023-04-30)
% rustc ~/s/c/src/third_party/rust_src/src/tests/ui/sanitize/leak.rs -Zthreads=1 --target=x86_64-unknown-linux-gnu --error-format json --json future-incompat -Ccodegen-units=1 -Zui-testing -o ~/s/c/src/third_party/rust_src/src/build/x86_64-unknown-linux-gnu/test/ui/sanitize/leak/a -A unused -Crpath -Z sanitizer=leak -O
% cd ~/s/c/src/third_party/rust_src/src/build/x86_64-unknown-linux-gnu/test/ui/sanitize/leak && RUST_TEST_THREADS="72" ~/s/c/src/third_party/rust_src/src/build/x86_64-unknown-linux-gnu/test/ui/sanitize/leak/a
LeakSanitizer: CHECK failed: lsan_interceptors.cpp:82 "((!lsan_init_is_running)) != (0)" (0x0, 0x0) (tid=911869)
@danakj danakj added the C-bug Category: This is a bug. label May 1, 2023
@jyn514 jyn514 added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc requires-custom-config This issue requires custom config/build for rustc in some way labels May 1, 2023
@aaronmondal
Copy link

Been running into this for a while as well. This breaks both the leak sanitizer in rules_ll and prevents turbo-cache from using leak sanitizer.

@danakj Did you find out anything that could be helpful here yet?

@danakj
Copy link
Contributor Author

danakj commented Jul 15, 2023

Sorry no I have not looked further. For Chromium, we ended up using Clang's sanitizer runtimes and just making empty archive placeholders for the Rust ones (as we can't have both anyway).

@nikic
Copy link
Contributor

nikic commented Jul 25, 2023

Backtrace:

Breakpoint 1, 0x0000555555565dc0 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ()
(gdb) bt
#0  0x0000555555565dc0 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ()
#1  0x000055555557ddc5 in __interceptor_free ()
#2  0x00007ffff7c70dfc in dl_error_free (ptr=<optimized out>) at ./dlerror.h:54
#3  dl_action_result_errstring_free (result=<optimized out>) at ./dlerror.h:72
#4  dl_action_result_errstring_free (result=0x7ffff6f00780) at ./dlerror.h:65
#5  _dlerror_run (operate=operate@entry=0x7ffff7c71320 <dlsym_doit>, 
    args=args@entry=0x7fffffffde90) at dlerror.c:183
#6  0x00007ffff7c713c5 in dlsym_implementation (dl_caller=<optimized out>, name=<optimized out>, 
    handle=<optimized out>) at dlsym.c:54
#7  ___dlsym (handle=<optimized out>, name=<optimized out>) at dlsym.c:68
#8  0x0000555555557422 in __interception::InterceptFunction(char const*, unsigned long*, unsigned long, unsigned long) ()
#9  0x000055555557d78d in __lsan::InitializeInterceptors() ()
#10 0x000055555557715b in __lsan_init ()
#11 0x00007ffff7fcce12 in _dl_init (main_map=0x7ffff7ffe2c0, argc=1, argv=0x7fffffffdf88, 
    env=0x7fffffffdf98) at dl-init.c:102
#12 0x00007ffff7fe38e0 in _dl_start_user () from /lib64/ld-linux-x86-64.so.2

We can see that we end up calling __interceptor_free as part of __lsan_init via __dlsym.

@Jules-Bertholet
Copy link
Contributor

@rustbot label A-sanitizers

@rustbot rustbot added the A-sanitizers Area: Sanitizers for correctness and code quality label Apr 8, 2024
@intgr
Copy link
Contributor

intgr commented Apr 9, 2024

rustix project also fails to build with LeakSanitizer. Repro:

git clone https://github.com/bytecodealliance/rustix
cd rustix
rustup override set nightly
RUSTFLAGS="-Z sanitizer=leak" cargo build

Output:

[...]
   Compiling rustix v0.38.32 (/home/marti/src/rustix)
   Compiling linux-raw-sys v0.4.13
   Compiling bitflags v2.5.0
error: failed to run custom build command for `rustix v0.38.32 (/home/marti/src/rustix)`

Caused by:
  process didn't exit successfully: `rustix/target/debug/build/rustix-dad2410e95903b2f/build-script-build` (exit status: 23)
  --- stderr
  LeakSanitizer: CHECK failed: lsan_interceptors.cpp:82 "((!lsan_init_is_running)) != (0)" (0x0, 0x0) (tid=75319)

intgr added a commit to intgr/posix-acl that referenced this issue Apr 9, 2024
@tmiasko tmiasko removed the requires-custom-config This issue requires custom config/build for rustc in some way label May 10, 2024
@tmiasko
Copy link
Contributor

tmiasko commented May 10, 2024

When linking a static sanitizer runtime clang also adds --dynamic-list=... or --export-dynamic.

-Clink-args=--export-dynamic or -Zexport-executable-symbols can be used as a workaround in rustc.

rcvalle added a commit to rcvalle/rust that referenced this issue Aug 26, 2024
Fix rust-lang#111073 by checking if `-Zexport-executable-symbols` is passed when
LeakSanitizer is enabled.
rcvalle added a commit to rcvalle/rust that referenced this issue Aug 26, 2024
Fix rust-lang#111073 by checking if `-Zexport-executable-symbols` is passed when
LeakSanitizer is enabled.
rcvalle added a commit to rcvalle/rust that referenced this issue Aug 26, 2024
Fix rust-lang#111073 by checking if `-Zexport-executable-symbols` is passed when
LeakSanitizer is enabled.
@tmiasko
Copy link
Contributor

tmiasko commented Sep 6, 2024

Should be fixed by llvm/llvm-project#106912.

@tmiasko tmiasko added the llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes label Sep 12, 2024
d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Oct 4, 2024
Running with LeakSanitizer enabled is a mess: we are seeing spurious
failures in CI on completely unrelated changes to the
symbolize_process_symbolic_paths test. Attempting to reproduce them
locally is denied with line noise such as:

> LeakSanitizer: CHECK failed: lsan_interceptors.cpp:82 "((!lsan_init_is_running)) != (0)" (0x0, 0x0) (tid=29001)

This seems to be rust-lang/rust#111073.

In any event, AddressSanitizer comes with leak detection support and so
let's just use that instead -- it hasn't caused any problems and we
haven't seen any issues using it locally either.

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to libbpf/blazesym that referenced this issue Oct 4, 2024
Running with LeakSanitizer enabled is a mess: we are seeing spurious
failures in CI on completely unrelated changes to the
symbolize_process_symbolic_paths test. Attempting to reproduce them
locally is denied with line noise such as:

> LeakSanitizer: CHECK failed: lsan_interceptors.cpp:82 "((!lsan_init_is_running)) != (0)" (0x0, 0x0) (tid=29001)

This seems to be rust-lang/rust#111073.

In any event, AddressSanitizer comes with leak detection support and so
let's just use that instead -- it hasn't caused any problems and we
haven't seen any issues using it locally either.

Signed-off-by: Daniel Müller <[email protected]>
danielocfb pushed a commit to d-e-s-o/libbpf-rs that referenced this issue Oct 11, 2024
Leak sanitizer infrastructure in Rust is badly broken [0]. Disable it
until it resembles something of a working piece of software again.

[0] rust-lang/rust#111073

Signed-off-by: Daniel Müller <[email protected]>
danielocfb pushed a commit to d-e-s-o/libbpf-rs that referenced this issue Oct 11, 2024
Leak sanitizer infrastructure in Rust is badly broken [0]. Disable it
until it resembles something of a working piece of software again.

[0] rust-lang/rust#111073

Signed-off-by: Daniel Müller <[email protected]>
danielocfb pushed a commit to d-e-s-o/libbpf-rs that referenced this issue Nov 19, 2024
Leak sanitizer infrastructure in Rust is badly broken [0]. Disable it
until it resembles something of a working piece of software again.

[0] rust-lang/rust#111073

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue Dec 11, 2024
Leak sanitizer infrastructure in Rust is badly broken [0]. Disable it
until it resembles something of a working piece of software again.

[0] rust-lang/rust#111073

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to libbpf/libbpf-rs that referenced this issue Dec 11, 2024
Leak sanitizer infrastructure in Rust is badly broken [0]. Disable it
until it resembles something of a working piece of software again.

[0] rust-lang/rust#111073

Signed-off-by: Daniel Müller <[email protected]>
Thomasdezeeuw added a commit to Thomasdezeeuw/heph that referenced this issue Dec 22, 2024
Thomasdezeeuw added a commit to Thomasdezeeuw/heph that referenced this issue Dec 22, 2024
Thomasdezeeuw added a commit to Thomasdezeeuw/heph that referenced this issue Dec 22, 2024
Thomasdezeeuw added a commit to Thomasdezeeuw/heph that referenced this issue Dec 22, 2024
Thomasdezeeuw added a commit to Thomasdezeeuw/heph that referenced this issue Dec 22, 2024
lopopolo added a commit to artichoke/intaglio that referenced this issue Dec 24, 2024
lopopolo added a commit to artichoke/cactusref that referenced this issue Dec 25, 2024
lopopolo added a commit to artichoke/artichoke that referenced this issue Dec 25, 2024
@lopopolo
Copy link
Contributor

LeakSanitizer started failing across all of my repositories starting with nightly runs on ~December 16 2024 with this error:

    Finished `test` profile [unoptimized + debuginfo] target(s) in 37.73s
     Running unittests src/lib.rs (target/x86_64-unknown-linux-gnu/debug/deps/artichoke-be925fa724157ef9)
LeakSanitizer: CHECK failed: lsan_interceptors.cpp:82 "((!lsan_init_is_running)) != (0)" (0x0, 0x0) (tid=4086)
error: test failed, to rerun pass `-p artichoke --lib`

The first failure is on this nightly:

$ rustc +nightly -Vv
rustc 1.85.0-nightly (c26db435b 2024-12-15)
binary: rustc
commit-hash: c26db435bf8aee2efc397aab50f3a21eb351d6e5
commit-date: 2024-12-15
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
$ cargo +nightly version --verbose
cargo 1.85.0-nightly (769f622e1 2024-12-14)
release: 1.85.0-nightly
commit-hash: 769f622e12db0001431d8ae36d1093fb8727c5d9
commit-date: 2024-12-14
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 24.4.0 (noble) [64-bit]

This coincides with my repositories being upgraded to Image: ubuntu-24.04 GitHub Actions runner image.

@fzyzcjy
Copy link

fzyzcjy commented Jan 16, 2025

+1 Seeing same issue in https://github.com/fzyzcjy/flutter_rust_bridge recently, is there any updates? Thanks!

@jieyouxu jieyouxu added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 16, 2025
@jieyouxu
Copy link
Member

This might be waiting on llvm 19.x series backport llvm/llvm-project#121100?

@DianQK
Copy link
Member

DianQK commented Jan 16, 2025

This might be waiting on llvm 19.x series backport llvm/llvm-project#121100?

The PR is #135484.

@bors bors closed this as completed in d61f55d Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet