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: Don't link system libraries when building a static library #22878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jayschwa
Copy link
Contributor

@jayschwa jayschwa commented Feb 13, 2025

Previously, system libraries like libX11.so were passed to ar rcs. Consumers of the archive receive warnings about invalid contents.

Fixes #20476

@jayschwa
Copy link
Contributor Author

An alternate solution might remove the non-object comp.link_inputs earlier in the call stack, but I am unfamiliar with this code and don't know which is better.

@jayschwa
Copy link
Contributor Author

I'm not positive, but the CI failure seems unrelated to my change:

test
+- test-c-abi
   +- run test-c-abi-x86_64-linux.4.19...6.11.5-musl.2.28-x86_64-Debug-selfhosted-no-lld
      +- zig test test-c-abi-x86_64-linux.4.19...6.11.5-musl.2.28-x86_64-Debug-selfhosted-no-lld Debug x86_64-linux-musl 1 errors
:1:1: error: clang frontend command failed with exit code 139 (use -v to see invocation)
:1:1: note: diagnostic msg: 
            ********************
            
            PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
            Preprocessed source(s) and associated run script(s) are located at:
:1:1: note: diagnostic msg: /tmp/cfuncs-2640e2.c
:1:1: note: diagnostic msg: /tmp/cfuncs-2640e2.sh
:1:1: note: diagnostic msg: 
            
            ********************
error: warning(compilation): failed to delete '/home/ci/actions-runner2/_work/zig/zig/zig-local-cache/tmp/9fc7f0b5d2a4f502-cfuncs.o.d': FileNotFound

@alexrp alexrp added this to the 0.14.0 milestone Feb 15, 2025
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummm shouldn't this happen much earlier?

If shared libraries are specified on the CLI when outputting a static archive, then the user should receive an error.

If those shared libraries are coming from the frontend, then the frontend should refrain from adding that work into the pipeline in the first place.

Previously, system libraries like `libX11.so` were passed to `ar rcs`.
Consumers of the archive receive warnings about invalid contents.

Fixes ziglang#20476
@jayschwa jayschwa changed the title link: Limit ar rcs input to objects build: Don't link system libraries when building a static library Feb 26, 2025
@jayschwa
Copy link
Contributor Author

I reworked this so the build system does not pass -lfoo to zig build-lib ... -static. It does not produce an error if someone were to manually zig build-lib ... -lfoo ... -static from the command line. I can try that too, but I need more time to acquaint myself with that code. As-is, this seems to resolve the issue I was seeing in the wild with development builds of Zig.

@jayschwa jayschwa requested a review from andrewrk February 26, 2025 08:02
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

Successfully merging this pull request may close these issues.

Incorrect archiver Command Line Call When Linking a Static "System" Library to another Static Library
3 participants