-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Linking with lld stopped working on linux/Android since lld 13 and this repo enabled --gc-sections
#5698
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
Comments
I can confirm that reverting llvm/llvm-project@6d2d3bd fixes this issue. We're going to have to adapt that lld ELF commit for Swift. |
Here's a fix for this, it's not fully complete yet because the problem is the Can you test with your real world example to make sure this works there too? |
I think disabling |
For future reference for others the default change that introduced the issue here was highly controversial and I believe also broke rust, here is some further reading: |
Yikes, but since Swift 5.7 and trunk both use clang/lld 13+, maybe that's enough?
Just tried it natively on Android, can confirm your pull fixes the problem with lld 14.
It all depends if we can get your fix in quickly before the 5.7 release. If we can, no problem. If not, probably best to disable |
The problem is that if the host compiler isn't up to date you can't build swift itself. I asked and it doesn't seem like there's an official matrix of supported versions here. This issue is really the worse case scenario for this IMO because you could theoretically use a GCC to build swift and then lld to link your swift program with the compiler, in which case this fix still wouldn't work. |
Around February I tried the |
Do you happen to have any of the example failures around still? |
Your fix is in the stdlib, which already has to be built by the Swift-forked clang, so the host compiler should be irrelevant.
I don't think we can worry about all that, particularly since Swift concurrency already requires compilation by the Swift-forked clang.
@drodriguez, I haven't tried running the compiler validation suite on this fix, only tried my repro case above after recompiling the stdlib. It would be good to know what else failed for you and why, hopefully not a result of this fix. |
Is this always the case? That you use the host compiler to build the forked clang and then that to build the stdlib? If so that would definitely solve that issue! |
Yes, that is the default for how the Swift toolchain is currently built, because of changes like swiftlang/swift#39245. That change eventually made it into clang 14, llvm/llvm-project@f670c5a, so building the stdlib may work with a stock clang 14 now, or there may be other changes specific to the Swift fork too. |
Sadly no. I am recovering
I do not think it was a result of the fix. I think when I tried, the fix was very good, but not enough. Hopefully it will all be green and that's the fix. |
I submitted #5707 in case we can't fix it for real, my Swift PR is blocked on unrelated build failures so I can't run tests. Let me know if you get some useful test data here. |
The results of my testing:
Keith's tests in swiftlang/swift#60357 didn't seem to find the same problem, so it might be something in our environment, but that every failure relates to metadata does not put me at ease. I think the situation is slightly better than last time I checked, but there seems to be something still going on. If the solution works for upstream, please feel free to use it. We will need to find what's going on at our systems, and if we find something, we will see if it is something specific to us, or something that should be contributed back. |
@drodriguez, can you do a test run with |
Or maybe I misunderstood, the 10 failures are with this fix but with |
I tried with
Correct. Trying to run with |
For |
OK, so the original 10 failures were the baseline for lld without I suggest we get #5708 in for now, then we can spend more time validating the stdlib fix and get that in once we're sure of it. You may want to check a lld test run with no linker flags and no stdlib fix to get a true baseline. I will run those different flags combos with the validation suite natively on Android too, which only uses lld now, and report back my results. |
The 2 swift-reflection-dump crashes reproduce for me locally as well. Also the build failure on my swift PR is actually real, the issue appears to be that when not using lld the section that I'm forcing the be retained, and the sections that we actually want from the object files are not merged. So you end up with duplicate sections of metadata, which unsurprisingly causes issues. |
I imagine that the difference in the section flags caused by adding I agree merging the revert for 5.7 is safest. I'm not sure if I'm going to spend much more time on this. |
For reference this post also covers many pieces of this change https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order |
Opened swiftlang/swift#60406 with my Android test info, let's take discussion of this underlying lld issue there. |
Description
After dead-stripping was enabled in #4135, various people reported problems with using lld, though it wouldn't always show up. It appears to be some change with lld 13, as lld 12 works fine, perhaps the commit @drodriguez linked (I'll try reverting that commit and report back later).
Obviously, this is really a regression in how Swift interacts with lld 13 and 14, but I'm reporting it here first as we'll probably want to amend SPM 5.7 quickly before the underlying lld issue is figured out. @keith, maybe we should disable stripping on ELF if the linker is lld for now?
@3405691582, can you reproduce on OpenBSD?
Expected behavior
Linking to work fine with lld, as it does with gold.
Actual behavior
Several linker errors like this show up instead:
Steps to reproduce
rm Sources/ArgumentParserTestHelpers/TestHelpers.swift
../swift-DEVELOPMENT-SNAPSHOT-2022-07-25-a-ubuntu20.04/usr/bin/swift build -v -c release -Xswiftc -use-ld=lld
Swift Package Manager version/commit hash
latest Jul. 25 trunk snapshot and 5.7 Jul. 23 snapshot
Swift & OS version (output of
swift --version && uname -a
)Swift 5.8 and 5.7 on Ubuntu 20.04 x86_64
The text was updated successfully, but these errors were encountered: