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

Open
danakj opened this issue May 1, 2023 · 7 comments
Open

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

danakj opened this issue May 1, 2023 · 7 comments
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

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 <deso@posteo.net>
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 <deso@posteo.net>
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 <deso@posteo.net>
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 <deso@posteo.net>
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 <deso@posteo.net>
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 <deso@posteo.net>
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 <deso@posteo.net>
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants