cargo-zigbuild icon indicating copy to clipboard operation
cargo-zigbuild copied to clipboard

error: unsupported linker arg: --undefined

Open NobodyXu opened this issue 2 years ago • 7 comments
trafficstars

In CI of https://github.com/cargo-bins/cargo-quickinstall/pull/225 :

error: linking with `/home/runner/.cache/cargo-zigbuild/0.17.1/zigcc-aarch64-unknown-linux-gnu.sh` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/lib/llvm-17/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" VSLANG="1033" "/home/runner/.cache/cargo-zigbuild/0.17.1/zigcc-aarch64-unknown-linux-gnu.sh" "/tmp/rustcyQOQeV/symbols.o" "/tmp/cargo-installYEv6Xb/aarch64-unknown-linux-gnu/release/deps/cargo_quickinstall-f5fa84c441e696c6.cargo_quickinstall.b0e05ecc437846b8-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/cargo-installYEv6Xb/aarch64-unknown-linux-gnu/release/deps" "-L" "/tmp/cargo-installYEv6Xb/release/deps" "-L" "/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-c1be0fe9bd14e073.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/tmp/cargo-installYEv6Xb/aarch64-unknown-linux-gnu/release/deps/cargo_quickinstall-f5fa84c441e696c6" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "/tmp/cargo-installYEv6Xb/aarch64-unknown-linux-gnu/release/deps/cargo_quickinstall_audit_data.o" "-Wl,--undefined=AUDITABLE_VERSION_INFO"
  = note: error: unsupported linker arg: --undefined

It runs the command:

export CARGO_ROOT=/tmp/tmp.NcnCOgGQVC
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_LTO=fat
export OPENSSL_STATIC=1
export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

cargo-auditable auditable install cargo-quickinstall --version 0.2.9 --target aarch64-unknown-linux-gnu --root /tmp/tmp.NcnCOgGQVC

NobodyXu avatar Aug 21 '23 11:08 NobodyXu

See https://github.com/ziglang/zig/pull/11906, consider open a PR to filter it out like https://github.com/rust-cross/cargo-zigbuild/pull/97.

messense avatar Aug 21 '23 11:08 messense

So the flag is added by cargo-auditable, simply remove it might have other unintended effects?

https://github.com/rust-secure-code/cargo-auditable/blob/da85607fb1a09435d77288ccf05a92b2e8ec3f71/cargo-auditable/src/rustc_wrapper.rs#L56

messense avatar Sep 10 '23 05:09 messense

Hmmm, it seems like so.

Not sure how this to approach this problem, cc @Shnatsel

NobodyXu avatar Sep 10 '23 05:09 NobodyXu

The flag is needed to make sure the audit info is not removed by the linker. Without --undefined the linker would notice that the symbol is never used and remove it.

It does seem like an instance of https://github.com/ziglang/zig/pull/11906. The flag should be simply forwarded to the linker as-is.

Shnatsel avatar Sep 10 '23 10:09 Shnatsel

Is there any workaround? cc @Shnatsel @messense

We want to update ziglang v0.11 https://github.com/cargo-bins/cargo-binstall/pull/1564 but failed.

NobodyXu avatar Jan 12 '24 12:01 NobodyXu

I believe this is an issue with Zig, and it needs to be modified to recognize this flag and pass it along to the linker. Other similar PRs dealing with linker flags:

https://github.com/ziglang/zig/pull/11679 https://github.com/ziglang/zig/pull/11875 https://github.com/ziglang/zig/pull/11874

I am not aware of any workarounds.

Shnatsel avatar Jan 12 '24 13:01 Shnatsel

I will probably have to stay on ziglang v0.10 and instead zlib-ng on aarch64 to fix the error mentioned in #210

NobodyXu avatar Jan 13 '24 00:01 NobodyXu