-
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
lld 13+ stopped working with the linker flag --gc-sections
and Swift on ELF platforms
#60406
lld 13+ stopped working with the linker flag --gc-sections
and Swift on ELF platforms
#60406
Comments
I looked into those 19 Ideally, we'd pass So we may be stuck adding that linker flag here in the compiler itself after searching the passed in linker flags for |
Yes, I'm seemingly bit by this too. Ran in to this building Swift proper at HEAD, so it might not just be limited to SPM. |
Hm, you're seeing |
Yes. I need to look into it a little more closely later -- the mention of the "R" flag on the other bug was a reasonable workaround. |
Alright, thanks for reporting that this ELF issue is hitting more platforms, would be good to know more about that issue when building this repo, which I haven't seen. |
If you use lld to build the swift compiler in general you hit this today when linking swiftrt.o, I found the same when I was debugging this issue and needed to use lld to avoid linking OOMs. I also found that |
Huh, I switched over to using lld for Android ever since NDK 23 last year threw out binutils, #39045, and haven't seen that. I only see problems when turning on
Since only lld supports this flag, I want to add it only if lld is passed in to Of course, that will break using lld 12 and earlier, since they don't know the |
Another minor update/jotting some notes down: in base Swift, it's the |
Oh yeah, I've hit that before and had to remove that flag for |
…ng -z nostart-stop-gc Fixes swiftlang#60406
…ng -z nostart-stop-gc (#60544) Fixes #60406 Ran the linux x86_64 compiler validation suite on this pull with `-use-ld=lld -Xlinker --gc-sections`, then without stripping as in the linked issue, and only saw the 20 unrelated failures just like @drodriguez had.
reopening to track the core issue |
…ng -z nostart-stop-gc (swiftlang#60544) Fixes swiftlang#60406 Ran the linux x86_64 compiler validation suite on this pull with `-use-ld=lld -Xlinker --gc-sections`, then without stripping as in the linked issue, and only saw the 20 unrelated failures just like @drodriguez had.
…ng -z nostart-stop-gc (swiftlang#60544) Fixes swiftlang#60406 Ran the linux x86_64 compiler validation suite on this pull with `-use-ld=lld -Xlinker --gc-sections`, then without stripping as in the linked issue, and only saw the 20 unrelated failures just like @drodriguez had.
Relevant testing info for this issue here: swiftlang/swift-package-manager#5698 (comment) |
I can no longer repro issue with the Reflection tests that we were previously discussing. |
For reference: https://lld.llvm.org/ELF/start-stop-gc |
This was fixed by #72061 and associated changes, which will ship in the upcoming Swift 6. |
Describe the bug
SPM turned on
--gc-sections
in trunk six months ago, swiftlang/swift-package-manager#4135- just before that, a linux user reported this bug with lld 13 but didn't respond when I asked for more info- and others soon reported similar problems with SPM and lld. The issue appears to be a change to how--gc-sections
works in lld that was added last year, which was then flipped on by default and produces linker errors like these when the repro command below is run:Steps To Reproduce
Steps to reproduce the behavior:
./swift-5.6.2-RELEASE-ubuntu20.04/usr/bin/swiftc swift/test/Interpreter/hello_toplevel.swift -use-ld=lld -Xlinker --gc-sections -v
Removing the lld flag makes it default to the system gold linker on linux, which works fine. Make sure you're running lld 13+ as in the output above, as I think it may pick up an earlier lld installed in the system if one is there.
Expected behavior
Linking with lld 13+ and
--gc-sections
to workEnvironment (please fill out the following information)
Additional context
Since linux uses gold by default and the Android LTS NDK used lld 12 till a couple weeks ago, it looks like this wasn't affecting too many people, but will if SPM 5.7 turns on dead-stripping by default, so that change is being backed out of SPM temporarily, swiftlang/swift-package-manager#5698, till we can fix it here.
@keith has proposed #60357 to fix this, but it may not be enough. @drodriguez ran that fix and the new lld flag
-z nostart-stop-gc
through the compiler validation suite on linux x86_64 and got a couple dozen more test failures.I tried replicating what he did natively on Android with the July 25 source snapshot, which uses lld 14 from the Termux environment, and got the following compiler validation suite test results:
No changes, ie just the stock test run with lld - 36 test failures
lld with
SWIFT_DRIVER_TEST_OPTIONS=" -Xlinker --gc-sections"
- 1113 test failureslld with
SWIFT_DRIVER_TEST_OPTIONS=" -Xlinker --gc-sections"
and the stdlib fix from #60357 - 159 test failureslld with
SWIFT_DRIVER_TEST_OPTIONS=" -Xlinker --gc-sections -Xlinker -z -Xlinker nostart-stop-gc"
- 54 test failuresI also tried applying both the stdlib fix and
-z nostart-stop-gc
, but that made no difference in the test results compared to-z nostart-stop-gc
alone.Comparing that last run to the first stock run, I see 19 additional test failures- 18 TypeDecoder tests and DebugInfo.ASTSection- that all invoke
lldb-moduleimport-test
and fail withFileCheck error: '<stdin>' is empty.
, similar to @drodriguez's results (LinkerSections.function_sections-lld that failed in the stock run now passes with-z nostart-stop-gc
applied, as that test was already using--gc-sections
). I will look into those further.I'm looking for feedback from the Swift compiler devs on what we should do about this: apply one of these fixes or try something different?
@3405691582, let me know if you can reproduce on OpenBSD.
The text was updated successfully, but these errors were encountered: