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

fix: make zig cc pass -l/-L like Clang/GCC for ELF #19818

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

Conversation

a-khabarov
Copy link

This PR is my attempt to fix #19699 by making the way zig cc passes -l/-L flags for ELF linking consistent with Clang and GCC.
I've added a test case that mimics the example in the issue description. Without the changes this PR makes to src, the new test case fails as expected with

========= expected to find: ==========================
NEEDED libfoo.so
========= but parsed file does not contain it: =======
dynamic section
RUNPATH foo
NEEDED foo/libfoo.so
NEEDED libc.so.6

I am not sure if test/tests.zig is the best place for it - I couldn't find a good way to test this in test/link/elf.zig or test/standalone.

This commit makes the way `zig cc` passes `-l/-L` flags for ELF linking
consistent with Clang and GCC.

Closes ziglang#19699
@a-khabarov
Copy link
Author

@motiejus @kubkon This PR builds on the functionality implemented in #15743 and should also fix cc_test not working correctly when using hermetic_cc_toolchain as mentioned in #15743 (comment).

@@ -769,6 +769,54 @@ pub fn addCliTests(b: *std.Build) *Step {
step.dependOn(&cleanup.step);
}

{
Copy link
Member

Choose a reason for hiding this comment

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

This set of tests belongs in linker tests in test/link/elf.zig. I also don't understand why can't it be orchestrated using the build system? Why do you need to invoke zig exe via addSystemCommand? exe.linkSystemLibrary("foo") emits as -lfoo fwiw. Did you actually have a look at test/link/elf.zig? We do have a substantial amount of tests that rely on emitting and linking against system libs.

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.

zig cc -l example sets the DSO paths incorrectly
2 participants