Skip to content

Undefined reference to __tsan_init when using thread sanitizer #91968

@NobodyXu

Description

@NobodyXu

Problem

I am trying to use thread sanitizer in my fork of triomphe and it has link errors when trying to use thread sanitizer, complaining that a lot of symbols started with __tsan_ is not found.

Here is the log for the errors (it also failed on my computer).

Looking at the command used in linking, it seems that rustc didn't enable thread sanitizer using -fsanitize=thread.

  = note: "cc" "-m64" "/tmp/rustdoctestbg4CHc/rust_out.rust_out.1376475e-cgu.0.rcgu.o" "/tmp/rustdoctestbg4CHc/rust_out.3oi7hjnjienb8flc.rcgu.o" "-Wl,--as-needed" "-L" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/runner/work/triomphe/triomphe/target/debug/deps" "-L" "/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libtriomphe-4868d43b5964945c.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libstable_deref_trait-62193f8fb5c13074.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libserde-d532e61b9a54ea8f.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libmemoffset-793678c9d116a3a9.rlib" "-Wl,--start-group" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libstd-e6aec2a875c401ae.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_unwind-27978ec139b8e8b6.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libminiz_oxide-7ac06f911a3d6b26.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libadler-587439a6ae9f9fae.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libobject-a68a19d2fe64c521.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libmemchr-862919f7416845ee.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libaddr2line-61bd6bdfa82e83a2.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libgimli-3bf1af53ac54ff93.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libstd_detect-c4183b6f70b69172.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/librustc_demangle-fae3b074d6cde041.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libhashbrown-c7328df30f706e1c.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_alloc-ee176d63441f1d9c.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libunwind-b48f6fd7afb5ff65.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libcfg_if-124043d27ba65b25.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/liblibc-26e5cdbe255d5639.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-496de79ccc19be0a.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_core-56980bdf30abc751.rlib" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libcore-a7bb8f77359f7f7d.rlib" "-Wl,--end-group" "/home/runner/work/triomphe/triomphe/target/x86_64-unknown-linux-gnu/debug/deps/libcompiler_builtins-6fe0500162851140.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/tmp/rustdoctestbg4CHc/rust_out" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"

Steps

  1. git clone https://github.com/NobodyXu/triomphe
  2. RUSTFLAGS='-Zsanitizer=thread' cargo +nightly test -Z build-std --target --target $(uname -m)-unknown-linux-gnu -- --nocapture

Possible Solution(s)

No response

Notes

No response

Version

rustc on my laptop:

rustc 1.59.0-nightly (404c8471a 2021-12-14)
binary: rustc
commit-hash: 404c8471aba60c2d837fa728e7c729a0f52d5830
commit-date: 2021-12-14
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions