Skip to content
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

[SR-14536] Importing FoundationNetworking with -static-stdlib is broken with missing symbols on Linux #3226

Closed
kateinoigakukun opened this issue Apr 27, 2021 · 2 comments

Comments

@kateinoigakukun
Copy link
Member

Previous ID SR-14536
Radar rdar://problem/77224218
Original Reporter @kateinoigakukun
Type Bug
Status Resolved
Resolution Done
Environment

Ubuntu 20.04.2 LTS
Swift version 5.4 (swift-5.4-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 1
Component/s Compiler, Foundation
Labels Bug
Assignee @kateinoigakukun
Priority Medium

md5: 7e7c7781d9c433972e4118e0fd2fd9dc

Issue Description:

import FoundationNetworking
_ = URLSession.shared

This code couldn't be built with -static-stdlib due to linking failure on Linux.

This issue was introduced by the use of @_implementationOnly in swift-corelibs-foundation. FoundationNetworking shipped with Swift 5.4 imports CFURLSessionInterface with @_implementationOnly, then FoundationNetworking.swiftmodule doesn't have a dependency declaration of CFURLSessionInterface. So "import FoundationNetworking" doesn't tell the driver to link CFURLSessionInterface and CFURLSessionInterface dependent libraries.

Here is my forum post about this issue several month ago.
Autolinking behavior of @_implementationOnly with static linking

Here is the command line log.

$ swiftc -static-stdlib main.swift -v
/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/bin/swift-frontend -frontend -c -primary-file main.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -module-name main -o /tmp/main-980558.o -use-static-resource-dir
/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/bin/swift-autolink-extract /tmp/main-980558.o -o /tmp/main-9e4f94.autolink
/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/bin/clang -fuse-ld=gold -pie /home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/lib/swift/linux/x86_64/swiftrt.o /tmp/main-980558.o -Xlinker --start-group @/tmp/main-9e4f94.autolink -Xlinker --end-group -L /home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/lib/swift_static/linux @/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/lib/swift_static/linux/static-stdlib-args.lnk --target=x86_64-unknown-linux-gnu -v -o main
clang version 10.0.0 (git@github.com:apple/llvm-project.git 159d0efd5633014e890836a4227fb867b491eb6b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/bin/ld.gold" -pie -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/lib/swift_static/linux -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/lib/x86_64-linux-gnu/../../lib64 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. -L/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/bin/../lib -L/lib -L/usr/lib /home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/lib/swift/linux/x86_64/swiftrt.o /tmp/main-980558.o --start-group -lFoundationNetworking -lswift_Concurrency -lswiftCore -lFoundation -lswiftGlibc -lm -lpthread -lutil -ldl -lswiftDispatch -ldispatch -lBlocksRuntime -lDispatchStubs -lCoreFoundation -luuid -lswiftSwiftOnoneSupport --end-group -ldl -lpthread -lswiftCore -licui18nswift -licuucswift -licudataswift -lstdc++ -lm -export-dynamic --exclude-libs ALL -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o
/home/katei/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2021-04-24-a/usr/lib/swift_static/linux/libFoundationNetworking.a(MultiHandle.swift.o):MultiHandle.swift.o:function $s20FoundationNetworking10URLSessionC12_MultiHandleC03rawE0Svvpfi: error: undefined reference to 'CFURLSessionMultiHandleInit'
... // and many undefined reference errors for CoreFoundation symbols

For now, we can link correctly with extra "-lCFURLSessionInterface -lcurl" options.

@typesanitizer
Copy link

@swift-ci create

@kateinoigakukun
Copy link
Member Author

Resolved by #2996

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants