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

proc-macro + -Zsanitizer=address = Linking error #10666

Closed
Volker-Weissmann opened this issue May 12, 2022 · 1 comment
Closed

proc-macro + -Zsanitizer=address = Linking error #10666

Volker-Weissmann opened this issue May 12, 2022 · 1 comment
Labels
C-bug Category: bug

Comments

@Volker-Weissmann
Copy link

Problem

If you give -Zsanitizer=address and use a proc-macro crate, you get an ugly linking error. It should either compile, or give a nicer error message.

Steps

Take this example crate

cargo build works fine, but

$  RUSTFLAGS="-Zsanitizer=address" cargo build                                                                                                                                                         
   Compiling otherlib v1.0.0 (/home/volker/Documents/bug/mycrate/otherlib)
   Compiling mycrate v1.0.0 (/home/volker/Documents/bug/mycrate)
error: /home/volker/Documents/bug/mycrate/target/debug/deps/libotherlib-b3d905195a09f55e.so: undefined symbol: __asan_register_elf_globals
 --> src/lib.rs:1:5
  |
1 | use otherlib;
  |     ^^^^^^^^

error: could not compile `mycrate` due to previous error

Possible Solution(s)

No response

Notes

$ rustc --version -v                                                                                                                                                                            
rustc 1.62.0-nightly (52ca603da 2022-04-12)
binary: rustc
commit-hash: 52ca603da73ae9eaddf96f77953b33ad8c47cc8e
commit-date: 2022-04-12
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.0

Version

cargo 1.62.0-nightly (e2e2ddd 2022-04-05)
release: 1.62.0-nightly
commit-hash: e2e2dddebe66dfc1403a312653557e332445308b
commit-date: 2022-04-05
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1m)
os: Arch Linux Rolling Release [64-bit]
@Volker-Weissmann Volker-Weissmann added the C-bug Category: bug label May 12, 2022
@ehuss
Copy link
Contributor

ehuss commented May 13, 2022

Thanks for the report! The issue is that RUSTFLAGS is passed to proc-macros without the --target flag. The workaround is to use --target. I believe sanitizers only fully work with build-std as well. This is discussed a bit in the documentation here.

I'm going to close as a duplicate of rust-lang/rust#63986, rust-lang/rust#48199, #3739 and others. If you have further issues with using sanitizers, I would recommend filing issues at https://github.com/rust-lang/rust/issues as Cargo doesn't really have any interaction with them.

@ehuss ehuss closed this as completed May 13, 2022
Volker-Weissmann added a commit to Volker-Weissmann/rust that referenced this issue May 13, 2022
I added this note, because if you forget the `--target` flags, you get a really ugly error message.
rust-lang/cargo#10666
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue May 15, 2022
Added note in documentation

I added this note, because if you forget the `--target` flags, you get a really ugly error message.
rust-lang/cargo#10666
krobelus added a commit to fish-shell/fish-shell that referenced this issue Jan 13, 2024
They are probably not terribly useful for us but let's see what happens.

Unfortunately cargo does not properly forward the combination of "RUSTFLAGS"
and "--target" that is currently required to build with ASan [1].  Hence doctests
will fail to link on ASan builds. Let's disable doctests when ASan is active.

[1]: rust-lang/cargo#10666 et al
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants