swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-9946] sourcekit-lsp doesn't link statically with a Toolchain #52349

Open krzyzanowskim opened 5 years ago

krzyzanowskim commented 5 years ago
Previous ID SR-9946
Radar rdar://47947049
Original Reporter @krzyzanowskim
Type Bug
Environment macOS 10.14.3 (18D109)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler | |Labels | Bug | |Assignee | @mikeash | |Priority | Medium | md5: cac680cfa4b5f549f8d9dce48990b59f

Issue Description:

1. Install Toolchain: https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-osx.pkg

2. Use sourcekit-lsp for the Toolchain https://github.com/apple/sourcekit-lsp/tree/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a

3. Build using Toolchain, with static linking option enabled:

$ swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-osx/usr/bin/swift-build --package-path swift-source/sourcekit-lsp/ --static-swift-stdlib 

Undefined symbols for architecture x86_64:
  "__objc_realizeClassFromSwift", referenced from:
      __ZL30_swift_updateClassMetadataImplPN5swift19TargetClassMetadataINS_9InProcessEEENS_16ClassLayoutFlagsEmPKPKNS_10TypeLayoutEPmb in libswiftCore.a(Metadata.cpp.o)
  "_objc_setHook_getClass", referenced from:
      __ZL19installGetClassHookv in libswiftCore.a(MetadataLookup.cpp.o)
ld: symbol(s) not found for architecture x86_64
: error: link command failed with exit code 1 (use -v to see invocation)

It's worth to mention that it compiles just fine without "--static-swift-stdlib". Also it worked fine with some Toolchains (not all)
option.

benlangmuir commented 5 years ago

Reproduced with snapshot 2019-02-14-a on macOS 10.13.6. This is not specific to sourcekit-lsp. You can reproduce with a fresh executable package:

$ export TOOLCHAINS=org.swift.50201902141a
$ swift package init --type executable
$ swift build --static-swift-stdlib
belkadan commented 5 years ago

Swift on macOS isn't going to support static linking at all, so we'll need a different answer for this.