Normally -Wl, should be passed to the compiler to signify the following argument is a linker argument, but when we specify the linker as rust-lld instead of (e.g., cc), we no longer need -Wl,.
Here's a sample error:
error: linking with `rust-lld` failed: exit status: 1
|
= note: "rust-lld" "-flavor" "gnu" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/rcrt1.o" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbeginS.o" "/tmp/rustcpkcTj2/symbols.o" "<1 object files omitted>" "--as-needed" "-Bstatic" "-lunwind" "-lc" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/{libcompiler_builtins-*}.rlib" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/home/fox/prj/rayhunter/target/x86_64-unknown-linux-musl/release/deps/rayhunter_check-553f8aa90a9bc0bb" "--gc-sections" "-static" "-pie" "--no-dynamic-linker" "-z" "text" "-z" "relro" "-z" "now" "--strip-all" "/home/fox/prj/rayhunter/target/x86_64-unknown-linux-musl/release/deps/rayhunter_check_audit_data.o" "-Wl,--undefined=AUDITABLE_VERSION_INFO" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "<sysroot>/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: rust-lld: error: unknown argument '-Wl,--undefined=AUDITABLE_VERSION_INFO'
And just for sanity checking here's the relevant part of our project's .cargo/config.toml (we build for a bunch of targets with these same flags):
[target.x86_64-unknown-linux-musl]
linker = "rust-lld"
rustflags = ["-C", "target-feature=+crt-static"]
The following quick and dirty change was sufficient to get cargo auditable build working for our project, but this would need to be tweaked to check the linker executable before being mainlined:
diff --git a/cargo-auditable/src/rustc_wrapper.rs b/cargo-auditable/src/rustc_wrapper.rs
index 6291dee..790ac27 100644
--- a/cargo-auditable/src/rustc_wrapper.rs
+++ b/cargo-auditable/src/rustc_wrapper.rs
@@ -63,7 +63,7 @@ pub fn main(rustc_path: &OsStr) {
} else if is_wasm(&target_info) {
// We don't emit the symbol name in WASM, so nothing to do
} else {
- command.arg("-Clink-arg=-Wl,--undefined=AUDITABLE_VERSION_INFO");
+ command.arg("-Clink-arg=--undefined=AUDITABLE_VERSION_INFO");
}
} else {
// create_binary_file() returned None, indicating an unsupported architecture
Normally
-Wl,should be passed to the compiler to signify the following argument is a linker argument, but when we specify the linker asrust-lldinstead of (e.g.,cc), we no longer need-Wl,.Here's a sample error:
And just for sanity checking here's the relevant part of our project's
.cargo/config.toml(we build for a bunch of targets with these same flags):The following quick and dirty change was sufficient to get
cargo auditable buildworking for our project, but this would need to be tweaked to check the linker executable before being mainlined: