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-2205] Linker fails when linking to Foundation if -static-stdlib flag is present #730

Open
swift-ci opened this issue Jul 28, 2016 · 9 comments

Comments

@swift-ci
Copy link

@swift-ci swift-ci commented Jul 28, 2016

Previous ID SR-2205
Radar rdar://problem/34535228
Original Reporter mominul (JIRA User)
Type Bug

Attachment: Download

Environment

DEVELOPMENT-SNAPSHOT-2016-07-25
Ubuntu 16.04

Additional Detail from JIRA
Votes 15
Component/s libdispatch
Labels Bug, Linux
Assignee None
Priority Medium

md5: 76b3df295dd2c0f2cbc48f0a20b3a982

is duplicated by:

  • SR-6434 libdispatch.a missing on Linux

relates to:

  • SR-10625 tests for -static-*
  • SR-9289 libFoundation.a is missing from swift development snapshots

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.

/usr/bin/ld.gold: error: cannot find -lFoundation
/tmp/main-0993c4.o:/tmp/main-0993c4.o:function main: error: undefined reference to '_TMaC10Foundation8NSString'
/tmp/main-0993c4.o:/tmp/main-0993c4.o:function main: error: undefined reference to 'TFC10Foundation8NSStringCfT13stringLiteralVs12StaticString_S0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

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

import Glibc
//import Foundation

//var str: NSString = "Hello"
//print(str)

print("Hello, world!")
exit(1)

Thanks!

@swift-ci
Copy link
Author

@swift-ci swift-ci commented Jul 21, 2017

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:

/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -ldispatch
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -ldispatch
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/sourcekitten/Source/sourcekitten/FormatCommand.swift:47: error: undefined reference to 'TFVE10FoundationSS8Encodingau4utf8S0'
/sourcekitten/Source/sourcekitten/FormatCommand.swift:47: error: undefined reference to 'TIFE10FoundationSS4dataFT5usingVES_SS8Encoding20allowLossyConversionSb_GSqVS_4Data_A0'
/sourcekitten/Source/sourcekitten/FormatCommand.swift:47: error: undefined reference to 'TFE10FoundationSS4datafT5usingVES_SS8Encoding20allowLossyConversionSb_GSqVS_4Data'
/sourcekitten/Source/sourcekitten/FormatCommand.swift:48: error: undefined reference to 'TFV10Foundation3URLCfT15fileURLWithPathSS_S0'
/sourcekitten/Source/sourcekitten/FormatCommand.swift:48: error: undefined reference to '_TMaVC10Foundation6NSData14WritingOptions'
/sourcekitten/Source/sourcekitten/FormatCommand.swift:48: error: undefined reference to 'TWPVC10Foundation6NSData14WritingOptionss10SetAlgebraS'
/sourcekitten/Source/sourcekitten/FormatCommand.swift:48: error: undefined reference to 'TFV10Foundation4Data5writefzT2toVS_3URL7optionsVCS_6NSData14WritingOptions_T'
/sourcekitten/Source/sourcekitten/CompleteCommand.swift:51: error: undefined reference to '_TMaC10Foundation6NSUUID'
/sourcekitten/Source/sourcekitten/CompleteCommand.swift:51: error: undefined reference to 'TFC10Foundation6NSUUIDCfT_S0'
/sourcekitten/Source/sourcekitten/YamlRequestCommand.swift:44: error: undefined reference to '_TMaC10Foundation12NSDictionary'
/sourcekitten/Source/sourcekitten/main.swift:20: error: undefined reference to '_TMaC8Dispatch13DispatchQueue'
/sourcekitten/Source/SourceKittenFramework/Module.swift:80: error: undefined reference to '_TF10Foundation20NSTemporaryDirectoryFT_SS'
/sourcekitten/Source/SourceKittenFramework/Module.swift:80: error: undefined reference to 'TFV10Foundation3URLCfT15fileURLWithPathSS_S0'
/sourcekitten/Source/SourceKittenFramework/Module.swift:80: error: undefined reference to 'TFV10Foundation3URL22appendingPathComponentfSSS0'
/sourcekitten/Source/SourceKittenFramework/Module.swift:81: error: undefined reference to 'TIFV10Foundation4Data5writeFzT2toVS_3URL7optionsVCS_6NSData14WritingOptions_T_A0'
/sourcekitten/Source/SourceKittenFramework/Module.swift:81: error: undefined reference to 'TFV10Foundation4Data5writefzT2toVS_3URL7optionsVCS_6NSData14WritingOptions_T'
/sourcekitten/Source/SourceKittenFramework/Module.swift:82: error: undefined reference to '_TFV10Foundation3URLg4pathSS'
/sourcekitten/Source/SourceKittenFramework/Module.swift:104: error: undefined reference to 'TFV10Foundation3URLCfT15fileURLWithPathSS_S0'
/sourcekitten/Source/SourceKittenFramework/Module.swift:104: error: undefined reference to 'TFV10Foundation3URL23resolvingSymlinksInPathfT_S0'
/sourcekitten/Source/SourceKittenFramework/Module.swift:104: error: undefined reference to '_TFV10Foundation3URLg4pathSS'
/sourcekitten/Source/SourceKittenFramework/JSONOutput.swift:23: error: undefined reference to '_TMaC10Foundation17JSONSerialization'
/sourcekitten/Source/SourceKittenFramework/JSONOutput.swift:23: error: undefined reference to 'TFVC10Foundation17JSONSerialization14WritingOptionsau13prettyPrintedS1'
/sourcekitten/Source/SourceKittenFramework/JSONOutput.swift:51: error: undefined reference to '_TMaC10Foundation8NSNumber'
/sourcekitten/Source/SourceKittenFramework/JSONOutput.swift:51: error: undefined reference to 'TFC10Foundation8NSNumberCfT5valueVs5Int64_S0'
/sourcekitten/Source/SourceKittenFramework/JSONOutput.swift:53: error: undefined reference to '_TMaC10Foundation8NSNumber'
/sourcekitten/Source/SourceKittenFramework/JSONOutput.swift:53: error: undefined reference to 'TFC10Foundation8NSNumberCfT5valueSb_S0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:30: error: undefined reference to 'TZFV10Foundation12CharacterSetg22whitespacesAndNewlinesS0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:31: error: undefined reference to 'TFV10Foundation12CharacterSet6insertfT12charactersInSS_T'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:60: error: undefined reference to '_TMaC10Foundation15NSMutableString'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:66: error: undefined reference to 'TZFV10Foundation12CharacterSetg8newlinesS0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:66: error: undefined reference to 'TFE10FoundationSS10componentsfT11separatedByVS_12CharacterSet_GSaSS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:71: error: undefined reference to 'TZFV10Foundation12CharacterSetg8newlinesS0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:71: error: undefined reference to '_TFV10Foundation12CharacterSet8containsfScSb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:86: error: undefined reference to '_TFE10FoundationSS13lengthOfBytesfT5usingVES_SS8Encoding_Si'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:94: error: undefined reference to 'TFV10Foundation8_NSRangeCfT8locationSi6lengthSi_S0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:125: error: undefined reference to '_TF10Foundation10NSMaxRangeFVS_8_NSRangeSi'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:116: error: undefined reference to '_TF10Foundation17NSLocationInRangeFTSiVS_8_NSRange_Sb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:154: error: undefined reference to '_TF10Foundation10NSMaxRangeFVS_8_NSRangeSi'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:145: error: undefined reference to '_TF10Foundation17NSLocationInRangeFTSiVS_8_NSRange_Sb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:164: error: undefined reference to '_TF10Foundation17NSLocationInRangeFTSiVS_8_NSRange_Sb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:177: error: undefined reference to 'TWPC10Foundation8NSObjects8HashableS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:178: error: undefined reference to '_TMaC10Foundation6NSLock'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:178: error: undefined reference to 'TFC10Foundation6NSLockCfT_S0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:186: error: undefined reference to 'TWPC10Foundation8NSObjects8HashableS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:224: error: undefined reference to '_TFV10Foundation12CharacterSet8containsfScSb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:237: error: undefined reference to '_TMaC10Foundation11FileManager'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:238: error: undefined reference to '_TFC10Foundation8NSStringg14isAbsolutePathSb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:240: error: undefined reference to '_TMaC10Foundation5NSURL'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:240: error: undefined reference to 'TZFC10Foundation5NSURL7fileURLfT18withPathComponentsGSaSSGSqVS_3URL'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:240: error: undefined reference to '_TFV10Foundation3URLg4pathSS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:240: error: undefined reference to 'TFC10Foundation5NSURLCfT15fileURLWithPathSS_S0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:240: error: undefined reference to 'TFC10Foundation5NSURLg17standardizingPathGSqVS_3URL'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:0: error: undefined reference to '_TMV10Foundation8_NSRange'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:325: error: undefined reference to 'TFC10Foundation8NSString12getLineStartfTGSqGSpSi3endGSqGSpSi11contentsEndGSqGSpSi3forVS_8_NSRange_T'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:326: error: undefined reference to '_TFC10Foundation8NSString9substringfT4withVS_8_NSRange_SS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:333: error: undefined reference to 'TFC10Foundation8NSString12getLineStartfTGSqGSpSi3endGSqGSpSi11contentsEndGSqGSpSi3forVS_8_NSRange_T'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:334: error: undefined reference to '_TF10Foundation10NSMaxRangeFVS_8_NSRangeSi'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:334: error: undefined reference to '_TFC10Foundation8NSString9substringfT4withVS_8_NSRange_SS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:352: error: undefined reference to 'TFC10Foundation8NSString9lineRangefT3forVS_8_NSRange_S1'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:352: error: undefined reference to '_TF10Foundation10NSMaxRangeFVS_8_NSRangeSi'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:372: error: undefined reference to '_TFC10Foundation8NSStringg13pathExtensionSS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:379: error: undefined reference to '_TFC10Foundation8NSStringg13pathExtensionSS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:394: error: undefined reference to '_TMaC10Foundation11FileManager'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:398: error: undefined reference to '_TFE10FoundationSSg11capitalizedSS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:468: error: undefined reference to '_TMaC10Foundation19NSRegularExpression'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:468: error: undefined reference to '_TMaVC10Foundation19NSRegularExpression7Options'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:468: error: undefined reference to 'TWPVC10Foundation19NSRegularExpression7Optionss10SetAlgebraS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:468: error: undefined reference to 'TFC10Foundation19NSRegularExpressionCfzT7patternSS7optionsVS0_7Options_S0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:470: error: undefined reference to 'TWPV10Foundation17NSMatchingOptionss10SetAlgebraS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:470: error: undefined reference to 'TFC10Foundation19NSRegularExpression7matchesfT2inSS7optionsVS_17NSMatchingOptions5rangeVS_8_NSRange_GSaCS_18TextCheckingResult'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:0: error: undefined reference to '_TMaC10Foundation18TextCheckingResult'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:485: error: undefined reference to '_TMaVC10Foundation19NSRegularExpression7Options'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:485: error: undefined reference to 'TFVC10Foundation19NSRegularExpression7Optionsau17anchorsMatchLinesS1'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:485: error: undefined reference to 'TFVC10Foundation19NSRegularExpression7Optionsau24dotMatchesLineSeparatorsS1'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:485: error: undefined reference to 'TWPVC10Foundation19NSRegularExpression7Optionss10SetAlgebraS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:486: error: undefined reference to 'TFVC10Foundation19NSRegularExpression7Optionsau17anchorsMatchLinesS1'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:491: error: undefined reference to 'TFC10Foundation19NSRegularExpressionCfzT7patternSS7optionsVS0_7Options_S0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:492: error: undefined reference to 'TFC10Foundation19NSRegularExpression7matchesfT2inSS7optionsVS_17NSMatchingOptions5rangeVS_8_NSRange_GSaCS_18TextCheckingResult'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:520: error: undefined reference to 'TZFV10Foundation12CharacterSetg22whitespacesAndNewlinesS0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:500: error: undefined reference to '_TF10Foundationau10NSNotFoundSi'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:506: error: undefined reference to 'TFC10Foundation8NSString12getLineStartfTGSqGSpSi3endGSqGSpSi11contentsEndGSqGSpSi3forVS_8_NSRange_T'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:507: error: undefined reference to '_TFC10Foundation8NSString9substringfT4withVS_8_NSRange_SS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:508: error: undefined reference to 'TZFV10Foundation12CharacterSetg22whitespacesAndNewlinesS0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:512: error: undefined reference to '_TFE10FoundationSS8containsfSSSb'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:531: error: undefined reference to 'TFE10FoundationSS10componentsfT11separatedByVS_12CharacterSet_GSaSS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:534: error: undefined reference to 'TZFV10Foundation12CharacterSetg22whitespacesAndNewlinesS0'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:571: error: undefined reference to 'TFV10Foundation12CharacterSet6insertfT12charactersInSS_T'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:572: error: undefined reference to '_TFE10FoundationSS18trimmingCharactersfT2inVS_12CharacterSet_SS'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:577: error: undefined reference to 'TFVC10Foundation8NSString14CompareOptionsau9backwardsS1'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:577: error: undefined reference to 'TIFE10FoundationSS5rangeFT2ofSS7optionsVCS_8NSString14CompareOptions5rangeGSqGVs5RangeVVSS13CharacterView5Index6localeGSqVS_6LocaleGSqGS2_S4( [1])'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:577: error: undefined reference to 'TIFE10FoundationSS5rangeFT2ofSS7optionsVCS_8NSString14CompareOptions5rangeGSqGVs5RangeVVSS13CharacterView5Index6localeGSqVS_6LocaleGSqGS2_S4( [2])'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:577: error: undefined reference to 'TFE10FoundationSS5rangefT2ofSS7optionsVCS_8NSString14CompareOptions5rangeGSqGVs5RangeVVSS13CharacterView5Index6localeGSqVS_6LocaleGSqGS2_S4__'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:603: error: undefined reference to '_TMaC10Foundation11FileManager'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:0: error: undefined reference to '_TMV10Foundation8_NSRange'
/sourcekitten/Source/SourceKittenFramework/String+SourceKitten.swift:0: error: undefined reference to 'TWPC10Foundation8NSObjects8HashableS'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /usr/bin/swift-build-tool -f /sourcekitten/.build/debug.yaml -v

@swift-ci
Copy link
Author

@swift-ci swift-ci commented Jul 22, 2017

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.

@belkadan
Copy link

@belkadan belkadan commented Sep 26, 2017

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?

@swift-ci
Copy link
Author

@swift-ci swift-ci commented Sep 26, 2017

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).

@belkadan
Copy link

@belkadan belkadan commented Sep 26, 2017

Heh, actually the latest snapshots don't have libdispatch in them at all. Uh…oops?

@swift-ci
Copy link
Author

@swift-ci swift-ci commented Jul 16, 2018

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`

@swift-ci
Copy link
Author

@swift-ci swift-ci commented Jul 18, 2018

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

@swift-ci
Copy link
Author

@swift-ci swift-ci commented Jul 19, 2018

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.

@kevints
Copy link
Mannequin

@kevints kevints mannequin commented Nov 16, 2018

@compnerd did you fix this on master?

@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
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