Skip to content

Add zig cc support for LLVM flag --no-undefined-version #17326

Closed
DhashS wants to merge 33 commits into
ziglang:masterfrom
DhashS:add-no-undefined-version-linker-arg
Closed

Add zig cc support for LLVM flag --no-undefined-version #17326
DhashS wants to merge 33 commits into
ziglang:masterfrom
DhashS:add-no-undefined-version-linker-arg

Conversation

@DhashS
Copy link
Copy Markdown
Contributor

@DhashS DhashS commented Sep 29, 2023

I'm pretty sure this is not all I need to do, so would appreciate some guidance from the broader zig community.

This issue is what i'm trying to tackle #16855 by punching that flag through to LLVM.

I've also seen it invoked as -Wl,--no-undefined-version, so i'm wondering if to parse it in the .Wl section as well. I didn't initially since it seems like there's a catch-all append call that gets parsed where I specified.

@andrewrk
Copy link
Copy Markdown
Member

Thanks for working on this.

What does this do? The ld --help menu isn't particularly helpful:

  --undefined-version         Allow undefined version
  --no-undefined-version      Disallow undefined version

@motiejus
Copy link
Copy Markdown
Contributor

I'm pretty sure this is not all I need to do, so would appreciate some guidance from the broader zig community.

You will need to add a case in src/link/Elf.zig. See a833bdc for a simple isolated example.

I've also seen it invoked as -Wl,--no-undefined-version, so i'm wondering if to parse it in the .Wl section as well. I didn't initially since it seems like there's a catch-all append call that gets parsed where I specified.

Looking at the man pages of gcc and clang, I think this is the only valid way to call it (via -Wl,). And seems like you did it correctly for that case.

After you've built zig, you can poke at it:

$ ZIG_VERBOSE_LINK=1 zig cc -Wl,--no-undefined-version <...>

... and then observe that the flag is present in the line that starts with ld (then it's calling the underlying linker).

Thanks for working on this.

What does this do? The ld --help menu isn't particularly helpful:

  --undefined-version         Allow undefined version
  --no-undefined-version      Disallow undefined version

from gcc man page:

       Normally when a symbol has an undefined version, the linker will ignore it. This option disallows symbols with
       undefined version and a fatal error will be issued instead.

Also a relevant lld commit: https://reviews.llvm.org/D135402

@motiejus
Copy link
Copy Markdown
Contributor

Comment thread src/Compilation.zig Outdated
Comment thread src/main.zig Outdated
@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Sep 30, 2023

Thanks for the pointer to that commit @motiejus i've done as requested

Copy link
Copy Markdown
Contributor

@motiejus motiejus left a comment

Choose a reason for hiding this comment

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

I am leaving the suggestion "strange" with double-negatives (i.e. no_undefined_version instead of undefined_version), because that's the exact flag that man ld offers.

Comment thread src/Compilation.zig Outdated
Comment thread src/Compilation.zig Outdated
Comment thread src/link/Elf.zig Outdated
Comment thread src/link.zig Outdated
DhashS and others added 4 commits September 30, 2023 10:09
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Sep 30, 2023

makes sense, yeah i can't imagine a case where you're specifying both of them and it's correct.
looks like you left the parsing logic in though, so it'll handle both flags.

@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Sep 30, 2023

Cool, now that i know what you're looking for, i'll give this PR a once over in the morning to make sure it's decent given the back and forth.

Copy link
Copy Markdown
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

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

In addition to my code suggestions, it is also necessary to bump the hash version, and check that everywhere we hit a compile error we have correctly added the flag to relevant caches. Notably here and here.

Comment thread src/link/Elf.zig Outdated
Comment thread src/link.zig Outdated
Comment thread src/main.zig Outdated
Comment thread src/main.zig Outdated
Comment thread src/main.zig Outdated
Comment thread src/main.zig Outdated
Comment thread src/Compilation.zig Outdated
Comment thread src/Compilation.zig Outdated
Comment thread src/main.zig Outdated
@kubkon
Copy link
Copy Markdown
Member

kubkon commented Sep 30, 2023

I am also thinking that I might start requiring folks enabling new linker features to come up with linker tests and them here. This will help me in the long run as I will be able to simply change the test case from use_lld = true to use_lld = false and see if my implementation passes the test.

DhashS and others added 4 commits October 7, 2023 00:46
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Oct 7, 2023

In my understanding, things that y'all would like

  • use the LLD docstring
  • make sure caches are happy
  • make build.zig (zig build system) has test coverage for new code paths

@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Oct 9, 2023

okay, not sure how to do those last two, cc @motiejus @kubkon

@motiejus
Copy link
Copy Markdown
Contributor

In my understanding, things that y'all would like

* [x]  use the LLD docstring

* [ ]  make sure caches are happy

You are very close. What's missing:

* [ ]  make build.zig (zig build system) has test coverage for new code paths

@kubkon I totally see why this would make sense, but I think it's unfair to ask to write such test for newcomers: @DhashS already is shaving the n'th yak by coming from from hermetic_cc_toolchain, because his builds stopped working after Rust upgrade (when it started using this new flag).

Even though I feel like I know something in Zig by now (both the language and how it's wired up), I would certainly spend more than a day writing such test. So it would be nice to have, but perhaps too early or much to ask.

@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Oct 15, 2023

sorry, took me a second to figure out what y'all meant.

@DhashS DhashS requested review from kubkon and motiejus October 18, 2023 13:53
@scanterog
Copy link
Copy Markdown
Contributor

We're hitting the same issue. Thanks for the fix @DhashS :) @motiejus @kubkon would you be able to review/merge/release this one 🙏 ?

@motiejus
Copy link
Copy Markdown
Contributor

Looks good to me, but I am not the one deciding what goes to master and when. :)

Anyhow, looks like it is failing CI checks due to compile errors.

Comment thread src/Compilation.zig Outdated
Comment thread src/link/Elf.zig Outdated
@scanterog
Copy link
Copy Markdown
Contributor

yeah I think I've spotted why CI is failing cc @DhashS

@behos
Copy link
Copy Markdown
Contributor

behos commented Nov 14, 2023

👋 @kubkon it looks like there are some updates in the PR which might solve the CI issues.
Is there something else blocking this?

@DhashS
Copy link
Copy Markdown
Contributor Author

DhashS commented Nov 17, 2023

would really like to get this merged so that we can bump our rust version :)

@motiejus
Copy link
Copy Markdown
Contributor

All linux tests are failing, it is easier to get attention with a working CI.

@behos
Copy link
Copy Markdown
Contributor

behos commented Nov 29, 2023

@DhashS looks like a formatting error

diff --git a/src/main.zig b/src/main.zig
index a4d7ae93f..9ef095ef6 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2379,7 +2379,7 @@ fn buildOutputType(
                     linker_allow_undefined_version = true;
                 } else if (mem.eql(u8, arg, "--no-undefined-version")) {
                     linker_allow_undefined_version = false;
-                }  else if (mem.eql(u8, arg, "--version")) {
+                } else if (mem.eql(u8, arg, "--version")) {
                     try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
                     process.exit(0);
                 } else {

I think this is what's picked up in CI. You can run zig fmt on the changed files.

@Vexu Vexu linked an issue Nov 29, 2023 that may be closed by this pull request
@behos
Copy link
Copy Markdown
Contributor

behos commented Dec 11, 2023

@DhashS since only some formatting seems to be blocking this PR and it's been pending for a while now, if you don't have time to update it I can create another fork from your branch and reopen it after running zig fmt. Your commits will be left intact.

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.

unsupported linker arg: --no-undefined-version

6 participants