-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[utils] Replace gold with lld as the default linker on Linux #80104
base: main
Are you sure you want to change the base?
Conversation
GNU Gold is deprecated[0] and will not be updated by upstream binutils. This begins with binutils 2.44, released in February 2025. [0] lists.gnu.org/archive/html/info-gnu/2025-02/msg00001.html
For visibility, I'm mostly fine with using lld. My main concern though is that lld does not use a normal link algorithm and I'm concerned about losing the ability to use POSIX linkers if we aren't verifying that they work since the link algorithm is generally more sensitive to changes in link flag repetition and ordering. |
This is something that we discussed with the changes to Swift Build as well. We should be using the default linker on the platform ( |
In the cases where the default system linker is BFD, and that version of BFD trips over the swift compiler/runtime's use of protected symbols, what to do then? It seems from my limited view of this issue that the decision a few months ago was was to use gold to cover that gap, but gold is now unmaintained and deprecated. Is a more comprehensive CMake configure-time check (aka 'does the system linker handle this known protected symbols test case properly') in order here? |
Yeah, a more comprehensive fix would be better:
|
We build and install We definitely can't just remove setting this preset to use gold or we will see failures on the Ubuntu 22.04 PR tests. I have #77635 that I should probably just finish. Then the nightlies can use that preset while other testing can validate that one of the POSIX linkers still works. Amazon Linux 2023 somewhat ironically has a new enough BFD that it would totally work for this purpose, but no gold linker. |
I believe the current plan is to generally avoid having Swift specify which linker to use and let Clang make that decision instead. Ubuntu 22.04 is supported (by Ubuntu) until April 2027, and I assume we're likely to continue to support Swift on that platform until then, so we will need some kind of workaround until at least that date. The question then is what we should do. I think we can statically detect the platforms where this is a problem at (Swift compiler) build time. At that point, we have a couple of options:
Perhaps the thing to do here is to go through our currently supported platforms and look to see which ones use the older BFD linker as the default, and then look to see what their end-of-life date(s) are. If the EOL dates aren't too far away, (1) seems reasonable, particularly if newer versions of those platforms with non-broken linkers are already available. If the EOL dates are further off, maybe (2) would be a better choice. |
@@ -926,7 +926,7 @@ reconfigure | |||
# Use the clang that we install in the path for macros | |||
llvm-cmake-options= | |||
-DCROSS_TOOLCHAIN_FLAGS_LLVM_NATIVE='-DCMAKE_C_COMPILER=clang;-DCMAKE_CXX_COMPILER=clang++' | |||
-DCLANG_DEFAULT_LINKER=gold | |||
-DCLANG_DEFAULT_LINKER=ld.lld |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one note, as Evan says, the default is lld, so the better way to make this switch is to delete these 9 lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we install it lld by default, but the clang-linker itself will still use BFD, which I believe will fail PR testing due to the relocation bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh, setting this linker is a maze of config options and overrides. 😿
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah. I can go ahead and update my lld PR to use that flag and incorporate that change there.
It is possible to set different presets on the various nightly packages. If we have separate presets for gold vs lld vs default-linker and a list of which versions of which distros have support for each, I can go in tell the package builder to select the appropriate preset with the appropriate linker default. |
GNU Gold is deprecated[0] and will not be updated by upstream binutils. This begins with binutils 2.44, released in February 2025.
[0] https://lists.gnu.org/archive/html/info-gnu/2025-02/msg00001.html
Resolves #79163
cc @etcwilde