-
Notifications
You must be signed in to change notification settings - Fork 468
[SR-2205] Linker fails when linking to Foundation if -static-stdlib flag is present #730
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
Comment by Alexndra Paredes (JIRA) I'm having the same issue, where compiling without the `-static-stdlib` don't fail. But when using the flag we get the same error. To reproduce it, our Dockerfile looks like: FROM norionomura/sourcekit:311 as swift-builder
RUN apt-get update && \
apt-get install -y \
libicu-dev
RUN curl --location --output sourcekitten.tar.gz "https://github.com/jpsim/SourceKitten/archive/0.18.0.tar.gz"
RUN tar -xvf sourcekitten.tar.gz
RUN mv SourceKitten-0.18.0 sourcekitten
RUN cd sourcekitten && swift build -v -Xswiftc -static-stdlib and the error output is:
|
Comment by Muhammad Mominul Huque (JIRA) Using DEVELOPMENT-SNAPSHOT-2017-07-20 and compiling test.swift file with this command gave many errors: swiftc test.swift -o test -static-stdlib Errors are many so I have added those to a file errors.txt But now linker is able to find Foundation but have problems with resolving symbols. |
Looks like we now put libFoundation.a in lib/swift_static/linux/, but libdispatch.la is still in lib/swift/linux/. dgrove-oss (JIRA User), interested? |
Comment by David Grove (JIRA) could have been fixed by the CMake conversion. @compnerd, have you tried building with static libs with CMake (I haven't not something I normally do). |
Heh, actually the latest snapshots don't have libdispatch in them at all. Uh…oops? |
Comment by Sergio Campama (JIRA) Are there any update on this? I'm getting an error with `-ldispatch` not being found when compiling statically on linux (with a bunch of undefined references under the Dispatch module). I'm also getting errors on missing `_Block_copy` and `_NSConcreteStackBlock` references, and also a reference to `objc_retainAutoreleasedReturnValue` |
Comment by Sergio Campama (JIRA) Ok, I was able to modify the CMake targets to add a libdispatch.a into swift_static. Had to solve some issues with importing the BlocksRuntime sources, but it let me to compile statically a Swift binary in Linux using a toolchain created with my modified targets. The problem I'm having right now with this is that I'm getting a crash because free is being called with a wrong address. While adding the libdispatch.a target, one of the errors I got was that I needed to add -fPIC to the compilation flags of certain files, so I added that. Could that be related? I'm not very familiar with PIC. The full output, and the input swift source is in https://gist.github.com/sergiocampama/079ee2f6267a72e287f3b3c931a9d873 |
Comment by Sergio Campama (JIRA) Ok, progress. This swift program links and runs correctly: import Foundation
print("Hello, world!") And this also links and runs correctly: import Glibc
print("Hello, world!") This next one links, but fails at runtime with the errors I posted in the gist import Foundation
import Glibc
print("Hello and crash :(") So somehow, importing both Foundation and Glibc makes statically linked binaries fail to run. |
@compnerd did you fix this on master? |
No longer reproducible with Swift 5.8 (verified with |
Attachment: Download
Environment
DEVELOPMENT-SNAPSHOT-2016-07-25
Ubuntu 16.04
Additional Detail from JIRA
md5: 76b3df295dd2c0f2cbc48f0a20b3a982
is duplicated by:
relates to:
Issue Description:
I come across of this situation when I was trying to compile my code as statically linked with stdlib.
If I compile my code without importing Foundation with -static-stdlib flag, the compilation succeeds.
But the actual error occurs when I try to import Foundation. As the linker fails when linking with Foundation.
As I tried to inspect the error with my little knowledge, here is the fact that took my attention:
Without the `-static-stdlib` flag the library search path is set as
/path/to/swift/usr/lib/swift/linux
where the shared libraries are stored including Foundation.But with the `-static-stdlib` flag the library search path is set as
/path/to/swift/usr/lib/swift_static/linux
where the static libraries are stored excluding Foundation.So linker is innocent!
Can it be solved by adding statically linked copy of Foundation?
So is there any solutions? Can I compile my code statically linked with stdlib and Foundation?
To reproduce it, is very easy
Thanks!
The text was updated successfully, but these errors were encountered: