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

Address sanitiser fails to link on x86_64-apple-darwin nightly toolchain #99428

Closed
samkevich opened this issue Jul 18, 2022 · 2 comments
Closed
Labels
A-linkage Area: linking into static, shared libraries and binaries A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. O-macos Operating system: macOS O-x86_64 Target: x86-64 processors (like x86_64-*) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@samkevich
Copy link

Hello,
I tried to build this small project which calls C function from Rust code with enabled address sanitiser:

RUSTFLAGS=-Zsanitizer=address cargo +nightly build -Z build-std --target x86_64-apple-darwin

and I got the following link error:

Undefined symbols for architecture x86_64:
            "___asan_version_mismatch_check_apple_clang_1316", referenced from:
                _asan.module_ctor in libfoo.a(foo.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

The same code compiles fine on Linux.

Meta

rustc +nightly --version --verbose:

rustc 1.64.0-nightly (263edd43c 2022-07-17)
binary: rustc
commit-hash: 263edd43c5255084292329423c61a9d69715ebfa
commit-date: 2022-07-17
host: x86_64-apple-darwin
release: 1.64.0-nightly
LLVM version: 14.0.6

clang --version:

Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
@samkevich samkevich added the C-bug Category: This is a bug. label Jul 18, 2022
@samkevich
Copy link
Author

It looks like asan embeds a versioned function __asan_version_mismatch_check_vXXX to ensure that the compiler ABI
version and runtime ABI version are compatible.
When I compile the project on Linux I see the same name of function in libfoo.a and asan library from rust toolchain:

$ nm target/x86_64-unknown-linux-gnu/debug/build/rust-ffi-example-33b490ff2f531d69/out/libfoo.a | grep asan_version
    U __asan_version_mismatch_check_v8
$ nm ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc-nightly_rt.asan.a | grep asan_version
0000000000000000 T __asan_version_mismatch_check_v8

However on MacOS they are not the same:

$ nm target/x86_64-apple-darwin/debug/build/rust-ffi-example-5c0ccd7bf3020489/out/libfoo.a | grep asan_version
    U ___asan_version_mismatch_check_apple_clang_1316
$ nm ~/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc-nightly_rt.asan.dylib | grep asan_version 
0000000000053770 T ___asan_version_mismatch_check_v8

Is there a way to force rustc use the same version of asan that clang uses or vice versa?

@fmease fmease added O-macos Operating system: macOS O-x86_64 Target: x86-64 processors (like x86_64-*) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-linkage Area: linking into static, shared libraries and binaries A-sanitizers Area: Sanitizers for correctness and code quality and removed needs-triage-legacy labels Jan 26, 2024
@bjorn3
Copy link
Member

bjorn3 commented Jan 26, 2024

I would guess that the only way for rustc to use the specific asan ABI that apple clang uses is to make rustc use the exact LLVM version that apple uses for their clang. You could compile rustc against it yourself, but I think it is unlikely that the official builds will ever do this as we do need bugfixes for miscompilations caused by LLVM, apple LLVM lags behind upstream and we need to support cross-lang LTO with the official LLVM releases. It is probably easier to get a matching non-apple clang version to compile your C code with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. O-macos Operating system: macOS O-x86_64 Target: x86-64 processors (like x86_64-*) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants