-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add the remaining toolchain-distributed runtime libs to autolink-extract #64312
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
Conversation
…act deduplication
From the associated discussion:
I am indeed a little concerned about the " The problem is that while 99% of users don't care about link order, the 1% that do are going to be tripped up by this. How is performance without those two sections? Does that bring us down to acceptable levels? |
@al45tair I challenge the idea that link order is meaningful with respect to this issue in the first place. It's not possible to control the link order produced by As for the effect of removing those two sections on the performance improvement, it's severe - the effect of duplicated libraries scales a bit worse than linearly (but not quite as bad as quadratically) as the number of duplicates increases; the system libs group makes up over 25% of the duplications (being consistently the ones with more duplicates than any other), and the Foundation support libs another almost 10%, which means you're losing as much as 50% of the improvement (maybe a bit less if the package doesn't import Meanwhile, when I tried this PR with one of the larger non-OSS projects I work with, we saw both time and RAM usage drop by over 98% - the memory usage went from almost 17GB to under 750MB, and wall time from 2 full minutes to under 10s (and if that's not scary enough, |
Ah, I see what you're saying; because this is about autolinking specifically, anyone who was worried about link order is already going to have a bad day because there's no control over that. They'd have to turn autolinking off and then manually list the things to link with. In which case I withdraw any objection.
You're right, that's too big a hit. |
@swift-ci Please smoke test |
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.
Ugh, this is really not the ideal solution. Generally speaking, I think that we should explore disabling autolink-extract on Linux and have SPM drive the link dependencies and possibly offer some control over the link order.
@swift-ci please test |
Linux is the only target that uses autolink-extract in the first place, to my knowledge, and at least in the short term I much prefer the relatively non-invasive band-aid that makes a problem that's actively affecting users effectively vanish. (Besides, if I have to explain this issue to one more poor confused dev trying to build on DigitalOcean or Fly.Io and getting bizarre errors that randomly go away when they make some unrelated ill-advised change that has nothing to do with anything... 😒.) I certainly agree the larger issues around linkage should be dealt with in the longer term. |
🤨 The Windows CI passes but the Linux doesn't? Also, I can't find any hints as to what went wrong in the Linux tests, it just says the SwiftPM tests suddenly exited with failure, no error messages, and those tests ran without issue when I did a buildbox_linux build locally. |
Looks like this:
which isn't helpful. I don't think this is anything you could have done. I'll re-trigger the tests. |
@swift-ci Please test Linux platform |
I think that @gwynne already ran into this problem. |
Yes, I had to apply this diff to diff --git a/CMakeLists.txt b/CMakeLists.txt
index a259764..712f65f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
endif()
endif()
set_target_properties(XCTest PROPERTIES
+ INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swift
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/swift)
The built build-user@b98bdb9ebc35:~$ ldd /home/build-user/build/buildbot_linux/unified-swiftpm-build-linux-aarch64/aarch64-unknown-linux-gnu/release/IndexStoreDBPackageTests.xctest
linux-vdso.so.1 (0x0000ffff8b460000)
libXCTest.so => lib/swift/linux/libXCTest.so (0x0000ffff8b1e0000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff8b140000)
libFoundation.so => lib/swift/linux/libFoundation.so (0x0000ffff8a8c0000)
libBlocksRuntime.so => lib/swift/linux/libBlocksRuntime.so (0x0000ffff8a8a0000)
libswift_Concurrency.so => lib/swift/linux/libswift_Concurrency.so (0x0000ffff8a820000)
libswift_StringProcessing.so => lib/swift/linux/libswift_StringProcessing.so (0x0000ffff8a730000)
libswiftDispatch.so => lib/swift/linux/libswiftDispatch.so (0x0000ffff8a6e0000)
libswiftCore.so => lib/swift/linux/libswiftCore.so (0x0000ffff8a0e0000)
libswiftGlibc.so => lib/swift/linux/libswiftGlibc.so (0x0000ffff8a0b0000)
libdispatch.so => lib/swift/linux/libdispatch.so (0x0000ffff8a030000)
libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000ffff89e00000)
libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffff89dd0000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff89c20000)
/lib/ld-linux-aarch64.so.1 (0x0000ffff8b427000)
** libswift_RegexParser.so => not found **
libicuucswift.so.65 => lib/swift/linux/libicuucswift.so.65 (0x0000ffff89a20000)
libicui18nswift.so.65 => lib/swift/linux/libicui18nswift.so.65 (0x0000ffff89710000)
libicudataswift.so.65 => lib/swift/linux/libicudataswift.so.65 (0x0000ffff87c50000)
** libswift_RegexParser.so => lib/swift/linux/libswift_RegexParser.so (0x0000ffff87b30000) ** I have no idea if my fix is the right one (I know @compnerd is doubtful, and he's probably right). |
Update: I think I know why this PR broke it - if I'm correct, it's a particularly weird and thoroughly ironic case of link order mattering after all. Or more precisely, the link order mattering in a way that exposed a bug in the I still stand by my assertion that the deduplication doesn't need to concern itself with link order; a bug in the build system is all that made it significant in this case, and it absolutely should not be. This should be fixed in |
That work around is terrible and you should feel bad 😆 |
@swift-ci please test |
Opened swiftlang/swift-corelibs-xctest#432 to track fixing the XCTest build issue. |
@swift-ci please test |
…goes after fixing ordering
@swift-ci please test |
@swift-ci please test macOS platform |
This really is a self-inflicted wound. The issue isn't gold, its Swift's behaviour of injecting a custom section and then extracting it to recreate a linker response file rather than creating a build graph and generating the proper command for linking. |
@gwynne I think this is worth having. It'll need cherry-picking to the release/5.9 branch. |
Add the remaining toolchain-distributed runtime libs to autolink-extract
Cherry pick to 5.9 is here: #64633 |
(Note that it'll need approval from one of the branch managers to get it merged; I can't do that myself). |
[Linux] (Cherry Pick) Merge pull request #64312 from gwynne/patch-2
[5.8] CMake: fix missing `SWIFT_CONCURRENCY_GLOBAL_EXECUTOR` Explanation: Resolves issues with static linking on Linux Risk: Medium, affects Linux builds and top-level CMake declarations. Original PRs: #65795 and #64312 for `main`, #65824 and #64633 for `release/5.9` Reviewed by: @al45tair @drexin @etcwilde Resolves: some of the issues reported in #65097, also resolves #58380 Tests: Added in swiftlang/swift-integration-tests#118 `SWIFT_CONCURRENCY_GLOBAL_EXECUTOR` is defined in `stdlib/cmake/modules/StdlibOptions.cmake`, which is not included during the first pass of evaluation of the root `CMakeLists.txt`. It is available on subsequent evaluations after the value is stored in CMake cache. This led to subtle bugs, where `usr/lib/swift_static/linux/static-stdlib-args.lnk` didn't contain certain flags on clean toolchain builds, but did contain them in incremental builds. Not having these autolinking flags in toolchain builds leads to errors when statically linking executables on Linux. Additionally, since our trivial lit tests previously didn't link Dispatch statically, they didn't expose a bug where `%import-static-libdispatch` substitution had a missing value. To fix that I had to update `lit.cfg` and clean up some of the related path computations to infer a correct substitution value.
This is a potential workaround for the issues reported in #58380. In testing, this change resulted in a 90% reduction in both link time and linker RAM usage with no measurable impact on the output of the build.
(I call it a workaround rather than a fix because the underlying behavior is arguably
ld.gold
's fault, not Swift's.)Fixes #58380.