-
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
Static stdlib linking is broken on main and 5.9 #65097
Comments
Could this be related to #64312, I wonder? |
Footnotes |
|
Update: This issue can't have been caused by #64312; it also exists in the Swift 5.7.3 and 5.8 release toolchains!
root@4fcf0d17c25a:/foo# swift build -Xlinker -v -Xswiftc -v -c release --static-swift-stdlib
Building for production...
Swift version 5.7.3 (swift-5.7.3-RELEASE)
Target: aarch64-unknown-linux-gnu
<SNIP>
"/usr/bin/ld.gold" -pie -EL -z relro --hash-style=gnu --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o /foo/.build/aarch64-unknown-linux-gnu/release/foo /lib/aarch64-linux-gnu/Scrt1.o /lib/aarch64-linux-gnu/crti.o /usr/bin/../lib/gcc/aarch64-linux-gnu/9/crtbeginS.o -L/usr/lib/swift_static/linux -L/foo/.build/aarch64-unknown-linux-gnu/release -L/usr/lib -L/usr/bin/../lib/gcc/aarch64-linux-gnu/9 -L/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu -L/usr/bin/../lib -L/lib -L/usr/lib /usr/lib/swift_static/linux/aarch64/swiftrt.o --start-group /foo/.build/aarch64-unknown-linux-gnu/release/foo.build/foo.swift.o -lswift_StringProcessing -lswift_Concurrency -lswiftCore --end-group -ldl -lpthread -lswiftCore -lstdc++ -lm -export-dynamic --exclude-libs ALL --gc-sections --defsym main=foo_main "-rpath=\$ORIGIN" -v -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/aarch64-linux-gnu/9/crtendS.o /lib/aarch64-linux-gnu/crtn.o
/usr/lib/swift_static/linux/libswift_Concurrency.a(GlobalExecutor.cpp.o):GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
/usr/lib/swift_static/linux/libswift_Concurrency.a(GlobalExecutor.cpp.o):GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
<SNIP>
/usr/lib/swift_static/linux/libswift_Concurrency.a(Task.cpp.o):Task.cpp:function swift_task_asyncMainDrainQueueImpl(): error: undefined reference to 'dispatch_main'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
root@ed014baf2277:/foo# swift build -Xlinker -v -Xswiftc -v -c release --static-swift-stdlib
Building for production...
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
Swift version 5.8 (swift-5.8-RELEASE)
Target: aarch64-unknown-linux-gnu
<SNIP>
"/usr/bin/ld.gold" -pie -EL -z relro --hash-style=gnu --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o /foo/.build/aarch64-unknown-linux-gnu/release/foo /lib/aarch64-linux-gnu/Scrt1.o /lib/aarch64-linux-gnu/crti.o /usr/bin/../lib/gcc/aarch64-linux-gnu/9/crtbeginS.o -L/usr/lib/swift_static/linux -L/foo/.build/aarch64-unknown-linux-gnu/release -L/usr/lib -L/usr/bin/../lib/gcc/aarch64-linux-gnu/9 -L/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu -L/lib -L/usr/lib /usr/lib/swift_static/linux/aarch64/swiftrt.o --start-group /foo/.build/aarch64-unknown-linux-gnu/release/foo.build/Foo.swift.o -lswift_RegexParser -lswift_StringProcessing -lswift_Concurrency -lswiftCore --end-group -ldl -lpthread -lswiftCore -lstdc++ -lm -export-dynamic --exclude-libs ALL --gc-sections --defsym main=foo_main "-rpath=\$ORIGIN" -v -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/aarch64-linux-gnu/9/crtendS.o /lib/aarch64-linux-gnu/crtn.o
/usr/lib/swift_static/linux/libswift_Concurrency.a(GlobalExecutor.cpp.o):GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
/usr/lib/swift_static/linux/libswift_Concurrency.a(GlobalExecutor.cpp.o):GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
<SNIP>
/usr/lib/swift_static/linux/libswift_Concurrency.a(Task.cpp.o):Task.cpp:function swift_task_asyncMainDrainQueueImpl(): error: undefined reference to 'dispatch_main'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
root@667e5d417d3a:/foo# swift build -Xlinker -v -Xswiftc -v -c release --static-swift-stdlib
Building for production...
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
Swift version 5.9-dev (LLVM 6676f64aea2989b, Swift 563750fbe935a01)
Target: aarch64-unknown-linux-gnu
<SNIP>
"/usr/bin/ld.gold" -pie -EL -z relro --hash-style=gnu --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o /foo/.build/aarch64-unknown-linux-gnu/release/foo /lib/aarch64-linux-gnu/Scrt1.o /lib/aarch64-linux-gnu/crti.o /usr/bin/../lib/gcc/aarch64-linux-gnu/9/crtbeginS.o -L/usr/lib/swift_static/linux -L/foo/.build/aarch64-unknown-linux-gnu/release -L/usr/lib -L/usr/bin/../lib/gcc/aarch64-linux-gnu/9 -L/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu -L/lib -L/usr/lib /usr/lib/swift_static/linux/aarch64/swiftrt.o --start-group /foo/.build/aarch64-unknown-linux-gnu/release/foo.build/Foo.swift.o -lswiftCore -lswift_Concurrency -lswift_StringProcessing -lswift_RegexParser --end-group -ldl -lpthread -lswiftCore -lstdc++ -lm -export-dynamic --exclude-libs ALL --gc-sections --defsym main=foo_main "-rpath=\$ORIGIN" -v -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/aarch64-linux-gnu/9/crtendS.o /lib/aarch64-linux-gnu/crtn.o
/usr/lib/swift_static/linux/libswift_Concurrency.a(GlobalExecutor.cpp.o):GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
/usr/lib/swift_static/linux/libswift_Concurrency.a(GlobalExecutor.cpp.o):GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
<SNIP>
/usr/lib/swift_static/linux/libswift_Concurrency.a(Task.cpp.o):Task.cpp:function swift_task_asyncMainDrainQueueImpl(): error: undefined reference to 'dispatch_main'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation) Also verified with Adding The error is the result of failing to include Edit: |
You two have different missing symbols. The missing Edit: Just checked the package bot and we're definitely passing |
@etcwilde You literally dug up the same GCC and Firefox references to that issue that I found (#65097 (comment)) 🙂. But I haven't been able to reproduce the missing C++ symbols that Franz originally reported - nor were those same the missing symbols we were originally investigating when he filed this bug. It's my (revised) opinion that the oddity has/had to do with the additional absence of |
CMake: fix missing `SWIFT_CONCURRENCY_GLOBAL_EXECUTOR` value `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 are trivial tests previously didn't link Dispatch statically, the 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. Resolves some of the errors reported in #65097.
[5.9] 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 PR: #65795. Reviewed by: @al45tair @drexin @etcwilde Resolves: some of the issues reported in #65097 Tests: Added in swiftlang/swift-integration-tests#115 `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 are trivial tests previously didn't link Dispatch statically, the 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. Resolves some of the errors reported in #65097.
[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.
Okay, so I think I've fully tracked down the issue. The Clang package on UBI9 installs the gcc-12-aligned devtoolset and libstdc++, which defines the Why does the dynamic library work then? Because devtoolset-12 has a I seem to be having success with As for the question why So we may need something like
to force that through on ubi9. It might not be a terrible idea to force that on all Linux distros to ensure that the runtime will actually work on the distro we're building for, out-of-the-box. I'll try a PR and see if we take down the Linux nightlies off of main. |
@FranzBusch, is this still reproducing? I just tried building with the 5.9.2 and 5.10.1 docker images and am unable to reproduce this behavior anymore (both with SwiftPM and just a raw |
I think this has been fixed by some change. Let's close it for now. |
Description
Trying to compile a simple Swift program on either
main
or the5.9
release branch is currently failing to link when using--static-swift-stdlib
. It produces the following linker errorSteps to reproduce
Try to compile a simple swift package that contains an executable target that contains just this
Environment
The text was updated successfully, but these errors were encountered: