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-7038] in 4.1, -static-stdlib doesn't seem to work anymore #49586

Closed
weissi opened this issue Feb 20, 2018 · 32 comments
Closed

[SR-7038] in 4.1, -static-stdlib doesn't seem to work anymore #49586

weissi opened this issue Feb 20, 2018 · 32 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.1

Comments

@weissi
Copy link
Member

weissi commented Feb 20, 2018

Previous ID SR-7038
Radar rdar://problem/37710244
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.1Regression
Assignee @compnerd
Priority Medium

md5: 3fe03957d3ec077a1ac3669583413927

Issue Description:

repro:

  • create a new SwiftPM package (cd /tmp && mkdir test && cd test && swift package init --type=executable

  • try to build (rm -rf .build && swift build -Xswiftc -static-stdlib)

alternatively

echo 'print("hello")' > /tmp/test.swift
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/bin/swiftc -o /tmp/test -static-executable /tmp/test.swift

expected:

with 4.0.2 release it works fine:

$ rm -rf .build && /usr/local/swift/swift-4.0.2-RELEASE-ubuntu16.04/usr/bin/swift build -Xswiftc -static-stdlib && .build/x86_64-unknown-linux/debug/test
Compile Swift Module 'test' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/test
Hello, world!

actual

with today's 4.1 dev snapshot ({{swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a }}) however:

$ rm -rf .build && /usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/bin/swift build -Xswiftc -static-stdlib && .build/x86_64-unknown-linux/debug/test
Compile Swift Module 'test' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/test
/usr/bin/ld.gold: error: cannot find -lswiftImageInspectionShared
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(Errors.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/Errors.cpp:function swift::dumpStackTraceEntry(unsigned int, void*, bool): error: undefined reference to 'swift::lookupSymbol(void const*, swift::SymbolInfo*)'
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<TypeMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeMetadataRecordLookup()'
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(ProtocolConformance.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ProtocolConformance.cpp:function swift::Lazy<ConformanceState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolConformanceLookup()'
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)
error: terminated(1): /usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/bin/swift-build-tool -f /tmp/test/.build/debug.yaml main output:

things that are odd:

lswiftImageInspectionShared/Static seems gone:

in the .lnk file, it still lists -lswiftImageInspectionStatic:

$ grep -H . *.lnk | grep swift
static-executable-args.lnk:-lswiftCore
static-executable-args.lnk:-lswiftImageInspectionStatic
static-stdlib-args.lnk:-lswiftCore
static-stdlib-args.lnk:-lswiftImageInspectionShared

but

$ find /usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/ -iname '*imageinspec*' | wc -l
0

However, removing those -lswiftImageInspection* entries from the .lnk files also doesn't seem to fix it:

$ rm -rf .build && /usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/bin/swift build -Xswiftc -static-stdlib && .build/x86_64-unknown-linux/debug/test
Compile Swift Module 'test' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/test
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(Errors.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/Errors.cpp:function swift::dumpStackTraceEntry(unsigned int, void*, bool): error: undefined reference to 'swift::lookupSymbol(void const*, swift::SymbolInfo*)'
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<TypeMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeMetadataRecordLookup()'
/usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(ProtocolConformance.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ProtocolConformance.cpp:function swift::Lazy<ConformanceState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolConformanceLookup()'
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)
error: terminated(1): /usr/local/swift/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-19-a-ubuntu16.04/usr/bin/swift-build-tool -f /tmp/test/.build/debug.yaml main output:

so maybe libswiftImageIntrospection* is still needed but no longer part of the distribution?

@belkadan
Copy link
Contributor

@jckarter, what's ImageInspectionShared?

@belkadan
Copy link
Contributor

@swift-ci create

@jckarter
Copy link
Member

A while back I factored out the runtime code that looks at the images in the process in order to find the conformance/type/etc. tables for dynamic lookup. There was a specialized version for static linking since in a statically-linked executable there's only ever one image and we can directly link to its start/end symbols. @compnerd recently overhauled how this stuff works for ELF and COFF systems, and the static executable case may have fallen by the wayside.

@belkadan
Copy link
Contributor

This seems to work with a 4.1 built from source, but I didn't actually try it with a toolchain (just using the build directory). I'll check that next.

@belkadan
Copy link
Contributor

Oops, I had old build products lying around. libswiftImageInspectionStatic.a is indeed missing now.

@belkadan
Copy link
Contributor

…but that still didn't keep me from linking with the newer compiler.

@jckarter
Copy link
Member

Maybe that indicates a version mismatch between compiler and libraries. It could be that Saleem's changes made the extra .a file for static builds unnecessary.

@belkadan
Copy link
Contributor

Oops again. I was on master, not 4.1. But both the master and 4.1 downloadable toolchains seem to fail in this way, even though my local build does not.

@bob-wilson
Copy link

Looks to me like this is from:

commit 0c42b57
Author: Saleem Abdulrasool <compnerd@compnerd.org>
Date: Fri Nov 3 17:47:34 2017 -0700

ELF: restructure image metadata registration

That included this change to stdlib/public/runtime/CMakeLists.txt:

@@ -92,14 +87,6 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
   string(TOLOWER "${sdk}" lowercase_sdk)
 
   # These two libraries are only used with the static swiftcore
-  add_swift_library(swiftImageInspectionStatic STATIC
-    ImageInspectionStatic.cpp
-    StaticBinaryELF.cpp
-    C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
-    LINK_FLAGS ${swift_runtime_linker_flags})
-  set_target_properties(swiftImageInspectionStatic PROPERTIES
-    ARCHIVE_OUTPUT_DIRECTORY "${SWIFTSTATICLIB_DIR}/${lowercase_sdk}")
-
   add_swift_library(swiftImageInspectionShared STATIC
     ImageInspectionELF.cpp
     C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}

However, that library is still referenced in utils/static-executable-args.lnk. Saleem, can we just remove it from there?

@compnerd
Copy link
Collaborator

Yeah, I think that we can just remove it since that no longer does anything. The registration is done via the `swiftrt.o` file. I'll upload a change for that.

@bob-wilson
Copy link

@compnerd fixed this in #14772

@weissi
Copy link
Member Author

weissi commented Feb 22, 2018

@compnerd thanks for your patch. However I did try that locally (see last comment in the problem description) and that did not fix the problem me. Did you try creating a static stdlib/executable?

@bob-wilson
Copy link

Oops. I missed that, Johannes. Reopening this.

@compnerd
Copy link
Collaborator

Hmm, interesting, I am not able to reproduce the issue.

$ bin/swiftc -v -static-stdlib /tmp/hello.swift -o /tmp/hello
Swift version 4.1-dev (LLVM , Clang , Swift cbef5a9ded)
Target: x86_64-unknown-linux-gnu
/Users/compnerd/Source/apple-swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-linux-x86_64/bin/swift -frontend -c -primary-file /tmp/hello.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name hello -o /tmp/hello-10f854.o
/Users/compnerd/Source/apple-swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-linux-x86_64/bin/swift-autolink-extract /tmp/hello-10f854.o -o /tmp/hello-64b03c.autolink
/usr/x86_64-unknown-linux-gnu/bin/clang++ -fuse-ld=gold -pie -target x86_64-unknown-linux-gnu /Users/compnerd/Source/apple-swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-linux-x86_64/lib/swift/linux/x86_64/swiftrt.o /tmp/hello-10f854.o @/tmp/hello-64b03c.autolink -L /Users/compnerd/Source/apple-swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-linux-x86_64/lib/swift_static/linux @/Users/compnerd/Source/apple-swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-linux-x86_64/lib/swift_static/linux/static-stdlib-args.lnk --target=x86_64-unknown-linux-gnu -o /tmp/hello

$ /usr/x86_64-unknown-linux-gnu/bin/llvm-nm -U /Users/compnerd/Source/apple-swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-linux-x86_64/lib/swift_static/linux/libswiftImageInspectionShared.a | /usr/x86_64-unknown-linux-gnu/bin/c++filt``ImageInspectionELF.cpp.o:
00000000000002d0 t (anonymous namespace)::record(swift::MetadataSections const*)
0000000000000000 b (anonymous namespace)::registered
0000000000000350 T swift::lookupSymbol(void const*, swift::SymbolInfo*)
0000000000000000 T swift::initializeProtocolLookup()
0000000000000180 T swift::initializeTypeFieldLookup()
0000000000000100 T swift::initializeTypeMetadataRecordLookup()
0000000000000080 T swift::initializeProtocolConformanceLookup()
0000000000000200 T swift_addNewDSOImage

I did however have to manually extract the target from ninja and build it (ninja libswiftImageInspectionShared.a swiftSwiftOnoneSupport-linux-static), so it is very likely that the library has not been rebuilt. This sounds like a build issue that is annoying, but not a ship blocker IMO. It has likely existed for quite some time, and should be fixed, but I think that can be done later.

@weissi
Copy link
Member Author

weissi commented Feb 26, 2018

@compnerd it might well be a packaging issue but it's a major regression. Swift 4.0.x doesn't suffer from this, here's the repo:

curl -o swift.tar.gz https://swift.org/builds/swift-4.1-branch/ubuntu1604/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04.tar.gz && tar xf swift.tar.gz && echo 'print("hello")' > hello.swift && swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/bin/swiftc -static-stdlib hello.swift

which prints the above error. The next thing I did is to edit both .lnk files and remove the ImageInspection libraries from there but then you'll get this error

$ swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/bin/swiftc -static-stdlib hello.swift
/tmp/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
/tmp/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(Errors.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/Errors.cpp:function swift::dumpStackTraceEntry(unsigned int, void*, bool): error: undefined reference to 'swift::lookupSymbol(void const*, swift::SymbolInfo*)'
/tmp/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<TypeMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeMetadataRecordLookup()'
/tmp/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(ProtocolConformance.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ProtocolConformance.cpp:function swift::Lazy<ConformanceState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolConformanceLookup()'
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)

@swift-ci
Copy link
Collaborator

Comment by Cyril Lashkevich (JIRA)

Also static version of libdispatch is missing in swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04

For test program like this:

import Dispatch
dispatchMain()

I got:

~/test$ swift build -c release -Xswiftc -static-stdlib
Compile Swift Module 'test' (1 sources)
Linking ./.build/x86_64-unknown-linux/release/test
/usr/bin/ld.gold: error: cannot find -ldispatch
/usr/bin/ld.gold: error: cannot find -lswiftImageInspectionShared
/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/pu
blic/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
/home/notorca/test/.build/x86_64-unknown-linux/release/test.build/main.swift.o:/home/notorca/test/.build/x86_64-unknown-linux/release/test.build/main.swift.o:function main: error: unde
fined reference to '_T08Dispatch12dispatchMains5NeverOyF'
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)
error: terminated(1): /swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-25-a-ubuntu16.04/usr/bin/swift-build-tool -f /home/notorca/test/.build/release.yaml main output:

@belkadan
Copy link
Contributor

Saleem, don't forget to do a clean build. I also couldn't reproduce the issue and it turns out there was an old version of the library in my build directory.

Cyril: that's a separate issue, I think. Can you file a different bug for that?

@swift-ci
Copy link
Collaborator

Comment by Cyril Lashkevich (JIRA)

@belkadan sure, https://bugs.swift.org/browse/SR-7085

@compnerd
Copy link
Collaborator

The next thing I did is to edit both .lnk files and remove the ImageInspection libraries from there but then you'll get this error

Yeah, that won't work. You cannot just edit the linker response file. The libraries were changed as well (earlier). Can you ensure that you are building with the right set of libraries? The verbose link should show you the actual libraries in use.

@belkadan - from a clean build, ninja swiftCore-linux-static lib-swift_static-linux-static-stdlib-args.lnk swiftSwiftOnoneSupport-linux-static libswiftImageInspectionShared.a followed with the build does not reproduce the issue.

@weissi
Copy link
Member Author

weissi commented Feb 27, 2018

@compnerd

I tried the latest 4.1 snapshot:

$ curl -o swift.tar.gz https://swift.org/builds/swift-4.1-branch/ubuntu1604/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04.tar.gz && tar xf swift.tar.gz && echo 'print("hello")' > hello.swift && swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/bin/swiftc -static-stdlib hello.swift
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  171M  100  171M    0     0  8562k      0  0:00:20  0:00:20 --:--:-- 9530k
/usr/bin/ld.gold: error: cannot find -lswiftImageInspectionShared
/home/jweiss/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
/home/jweiss/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(Errors.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/Errors.cpp:function swift::dumpStackTraceEntry(unsigned int, void*, bool): error: undefined reference to 'swift::lookupSymbol(void const*, swift::SymbolInfo*)'
/home/jweiss/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<TypeMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeMetadataRecordLookup()'
/home/jweiss/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(ProtocolConformance.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ProtocolConformance.cpp:function swift::Lazy<ConformanceState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolConformanceLookup()'
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)

@weissi
Copy link
Member Author

weissi commented Feb 27, 2018

same for the latest dev snapshot:

$ curl -o swift.tar.gz https://swift.org/builds/development/ubuntu1604/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04.tar.gz && tar xf swift.tar.gz && echo 'print("hello")' > hello.swift && swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/bin/swiftc -static-stdlib hello.swift
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  175M  100  175M    0     0  8555k      0  0:00:21  0:00:21 --:--:-- 9637k
/usr/bin/ld.gold: error: cannot find -lswiftImageInspectionShared
/home/jweiss/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
/home/jweiss/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(Errors.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/Errors.cpp:function swift::dumpStackTraceEntry(unsigned int, void*, bool): error: undefined reference to 'swift::lookupSymbol(void const*, swift::SymbolInfo*)'
/home/jweiss/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<TypeMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeMetadataRecordLookup()'
/home/jweiss/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<(anonymous namespace)::ProtocolMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolLookup()'
/home/jweiss/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<(anonymous namespace)::FieldCacheState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeFieldLookup()'
/home/jweiss/swift-DEVELOPMENT-SNAPSHOT-2018-02-26-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(ProtocolConformance.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ProtocolConformance.cpp:function swift::Lazy<ConformanceState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolConformanceLookup()'
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)

@bob-wilson
Copy link

I see there is still a reference to that library in utils/gen-static-stdlib-link-args. Is that what we're missing?

@bob-wilson
Copy link

Yeah, that's almost certainly the problem. Saleem's change in PR 14772 only changed the static-executable-args.lnk linker file, but that's not what gets used for the static-stdlib option. This should fix it: #14860

@bob-wilson
Copy link

Nope that PR wasn't right. It turns out that the "Shared" library is actually static and that we simply weren't building it. #14880

@weissi
Copy link
Member Author

weissi commented Mar 1, 2018

thanks @bob-wilson

@bob-wilson
Copy link

I'm hoping this is fix but I haven't actually verified that yet. Let's wait until someone can verify the fix before pulling it over to the 4.1 branch.

@bob-wilson
Copy link

With today's dev snapshot, the static-stdlib option is working but the static-executable option gets a link failure:

$ swiftc -o test test.swift -static-executable

clang: warning: argument unused during compilation: '-pie'

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift/linux/x86_64/swiftrt.o:/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(Errors.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/Errors.cpp:function swift::dumpStackTraceEntry(unsigned int, void*, bool): error: undefined reference to 'swift::lookupSymbol(void const*, swift::SymbolInfo*)'

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<TypeMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeMetadataRecordLookup()'

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<(anonymous namespace)::ProtocolMetadataState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolLookup()'

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(MetadataLookup.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/MetadataLookup.cpp:function swift::Lazy<(anonymous namespace)::FieldCacheState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeTypeFieldLookup()'

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftCore.a(ProtocolConformance.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ProtocolConformance.cpp:function swift::Lazy<ConformanceState>::defaultInitCallback(void*): error: undefined reference to 'swift::initializeProtocolConformanceLookup()'

/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/libicuuc.a(putil.ao):function uprv_dl_open_55: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

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)

@bob-wilson
Copy link

If I manually add "-lswiftImageInspectionShared" to the link, then I get this:

/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/libicuuc.a(putil.ao):function uprv_dl_open_55: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

/home/bwilson/swift-DEVELOPMENT-SNAPSHOT-2018-03-01-a-ubuntu16.04/usr/lib/swift_static/linux/libswiftImageInspectionShared.a(ImageInspectionELF.cpp.o):/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-16_04/swift/stdlib/public/runtime/ImageInspectionELF.cpp:function swift::lookupSymbol(void const*, swift::SymbolInfo*): error: undefined reference to 'dladdr'

@bob-wilson
Copy link

If I edit static-executable-args.lnk to add "-lswiftImageInspectionShared" where we used to have "-lswiftImageInspectionStatic", that avoids the undefined reference to dladdr. The other linker complaint about dlopen is just a warning, so that sort of works.

@bob-wilson
Copy link

Here's a PR for that change: #14929

Someone who really understands this needs to review that.

@bob-wilson
Copy link

This should be fully resolved now on master.

I've created a PR for the 4.1 branch: #14937

@weissi
Copy link
Member Author

weissi commented Mar 27, 2018

thanks @compnerd and @bob-wilson I can confirm this is fixed now. But as soon as Dispatch is involved it still fails (SR-7039)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.1
Projects
None yet
Development

No branches or pull requests

7 participants