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

Build fails with cargo zigbuild #179

Open
mistydemeo opened this issue Dec 9, 2024 · 3 comments
Open

Build fails with cargo zigbuild #179

mistydemeo opened this issue Dec 9, 2024 · 3 comments

Comments

@mistydemeo
Copy link

As sort of a followup to #167, I've been trying out cargo-auditable with cargo-zigbuild. The subcommand part works fine, but it looks like it fails at the linker stage.

zig uses its own linker, which messes with auditable's assumption that there will always be a GNU-compatible linker on a Linux target. I've been looking into the zig linker and trying to see if there's a good option. zig lld-link -help shows relevant-looking flags with similar syntax to MSVC:

  /include:<value>        Force symbol to be added to symbol table as undefined one
  /includeoptional:<value>
                          Add symbol as undefined, but allow it to remain undefined

I haven't worked out how to get it to actually use them yet though - zig cc -Wl,/include:blah complains with the same error: unsupported linker arg error as with --undefined.

Here's the end of the output from a cargo auditable zigbuild build run:

   Compiling axolotlsay v0.2.298 (/__w/cargodisttest/cargodisttest)
error: linking with `/github/home/.cache/cargo-zigbuild/0.19.5/zigcc-aarch64-unknown-linux-gnu-aef7.sh` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/github/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/github/home/.cargo/bin:/opt/rh/gcc-toolset-13/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "/github/home/.cache/cargo-zigbuild/0.19.5/zigcc-aarch64-unknown-linux-gnu-aef7.sh" "/tmp/rustcLqYfds/symbols.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.9py8jh32h2cb0ivw779tg9i4g.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.addr2line-ed18c7e0b38b6a17.addr2line.dcb0e78a6b830a1f-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.adler-8fb8290c85cd5c7c.adler.1a8a2226f22e233c-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.alloc-e9c810686fe1c036.alloc.c8c5caedfd6a6f0-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.anstream-37cfdd350fa8c583.anstream.9cf2ce826526455a-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.anstream-37cfdd350fa8c583.anstream.9cf2ce826526455a-cgu.1.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.anstyle-c137a25921cb3546.anstyle.3e9a0bcc136da8df-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.anstyle_parse-7c7a15a325285a0f.anstyle_parse.a78b36ff2a25c24a-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.anstyle_query-e8135a96fdbafa0a.anstyle_query.52fe0fed27c61c0a-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.axolotlsay.4172ef2a1044718d-cgu.0.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.axolotlsay.4172ef2a1044718d-cgu.1.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.axolotlsay.4172ef2a1044718d-cgu.2.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.axolotlsay.4172ef2a1044718d-cgu.3.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.axolotlsay.4172ef2a1044718d-cgu.4.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.axolotlsay.4172ef2a1044718d-cgu.5.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.bitflags-13c2de39cae1c086.bitflags.9d7711d7bb7414f6-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.cfg_if-5c1562eddc983801.cfg_if.a0c1d432c552786a-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap-daba1211be2b59c4.clap.654d5bc4f95544a1-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.00.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.01.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.02.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.03.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.04.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.05.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.06.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.07.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.08.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.09.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.10.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.11.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.12.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.13.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.14.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_builder-3e787df4da50f307.clap_builder.d3e099ffa7786381-cgu.15.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.clap_lex-22e3e5de64da862c.clap_lex.da904fe00c3d006b-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.colorchoice-842a2a9b83256f4f.colorchoice.6dfba7ce3678ea87-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.core-7930636387874415.core.d5024c8150c5a5ee-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.gimli-5cbb446b3b26b1c9.gimli.d9996c4362eb5f0f-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.hashbrown-d4e58edb08cbd4f4.hashbrown.f22378847d5e2110-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.is_terminal-22e1cee977784ba4.is_terminal.9290ec5843131b6c-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.libc-1ff5c9b6079577e0.libc.9195248b68efe267-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.linux_raw_sys-efb67d7da9b9fdf2.linux_raw_sys.907d7869205bc215-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.memchr-33a84071306b4456.memchr.47e9c50244d86e18-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.miniz_oxide-25bb268d2bc63db2.miniz_oxide.8022a72c8d31c4b8-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.object-082b7755a27e9161.object.7d38c62475c4687b-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.once_cell-a2fe6628b26ab90c.once_cell.c9a13821cc820bd-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.panic_unwind-47c9dea6317daa9b.panic_unwind.c258f86b7ebd153b-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustc_demangle-0880bcdf77605aa1.rustc_demangle.9fee288bba9a50f7-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustc_std_workspace_alloc-a2f8ab699e7c1d36.rustc_std_workspace_alloc.fe786e6402702d27-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustc_std_workspace_core-fe7f8f1322fd0ddf.rustc_std_workspace_core.cb6c5af805269f9a-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustix-a4c0c793f520eacc.rustix.1cb238a806b56ea1-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustix-a4c0c793f520eacc.rustix.1cb238a806b56ea1-cgu.1.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustix-a4c0c793f520eacc.rustix.1cb238a806b56ea1-cgu.2.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.rustix-a4c0c793f520eacc.rustix.1cb238a806b56ea1-cgu.3.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.std-346e3cabb9c58815.std.a0846cfe10f65351-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.std_detect-1e204028eba31834.std_detect.ac7987477116a30-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.strsim-e96764abd5e43f58.strsim.a0635c6ce475d55d-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.strsim-e96764abd5e43f58.strsim.a0635c6ce475d55d-cgu.1.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.strsim-e96764abd5e43f58.strsim.a0635c6ce475d55d-cgu.2.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.strsim-e96764abd5e43f58.strsim.a0635c6ce475d55d-cgu.3.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.strsim-e96764abd5e43f58.strsim.a0635c6ce475d55d-cgu.4.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.unicode_width-90b1112de69b784f.unicode_width.ba1ceb7a00218101-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.unwind-4009a45ae155a494.unwind.3603900f77f52d90-cgu.0.rcgu.o.rcgu.o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb.utf8parse-61cc558fc9f21c05.utf8parse.af1a10e31097bfa0-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-Wl,-Bstatic" "/github/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-87871e2835343b94.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/github/home/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay-ba5eab422bcabfdb" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "/__w/cargodisttest/cargodisttest/target/aarch64-unknown-linux-gnu/dist/deps/axolotlsay_audit_data.o" "-Wl,--undefined=AUDITABLE_VERSION_INFO"
  = note: error: unsupported linker arg: --undefined
@mistydemeo
Copy link
Author

Found the linker options in zig cc; looks like the specific one we want might not be exposed. https://github.com/ziglang/zig/blob/1b0e913e0fcc63b48778be300b0705ceb1fd84f1/src/main.zig#L2048-L2403

@bjorn3
Copy link

bjorn3 commented Dec 9, 2024

zig lld-link -help shows relevant-looking flags with similar syntax to MSVC:

That is because zig lld-link is literally for calling LLD's counterpart to MSVC link.exe. zig ld.lld would be a bare Unix linker, though on Unix you need a wrapper like gcc, clang or zig cc around the bare linker to successfully link.

Found the linker options in zig cc; looks like the specific one we want might not be exposed.

That is unfortunate.

@Shnatsel
Copy link
Member

Yes, it seems this is an issue on the Zig side - it doesn't recognize the --undefined argument at all, which we need to reliably inject audit data and make sure it's not removed by the linker as unused, e.g. when performing LTO.

Unfortunately there seems to be nothing I can do about this in cargo auditable. This flag needs to be added to Zig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants