Create freestanding shared library for useage on systems not supported by swift

Hi!

Say I have a small shared library called X, that should be loaded by node. Until now, this all worked under debian, where swift is available. I want to switch the node process to alpine to reduce the docker image size. Is it possible to generate a freestanding shared object using the static SDK (the shared object should not rely on any library not avaible on alpine, but the .so can, of course, be generated on any distro, even glibc ones), and if yes, how? I tried to generate a fresh Swift package (type: library), and forced it to generate a dynamic library using type: .dynamic. Then I tried to cross-compile it using the static SDK - which resulted in some strange errors (I can share those if needed).

Is this supported?

Rust supports this: rust dylib for musl without linked with so · Issue #74317 · rust-lang/rust · GitHub

Thanks!

From Swift 5.10+, SwiftPM has --static-swift-stdlib, which is supposed to handle the use -Xswiftc -static-stdlib behind the scenes.

However, I think there's a bug with how it handles dynamic library products, but you can get around this by passing -Xswiftc -static-stdlib too.

swift build --static-swift-stdlib -Xswiftc -static-stdlib

Does that work?

Thanks!
That is my output, but it seems that is not enough

docker run -it swift:6.2.3-noble
root@a786dbc79a0d:/# cd /tmp/
root@a786dbc79a0d:/tmp# swift package init --type library
Creating library package: tmp
Creating Package.swift
Creating .gitignore
Creating Sources
Creating Sources/tmp/tmp.swift
Creating Tests/
Creating Tests/tmpTests/
Creating Tests/tmpTests/tmpTests.swift
root@a786dbc79a0d:/tmp# nano Package.swift # see listing below
root@a786dbc79a0d:/tmp# swift build
Building for debugging...
[8/8] Linking libtmp.so
Build complete! (1.94s)




root@a786dbc79a0d:/tmp# ls -lsa .build/debug/
total 124
4 drwxr-xr-x 10 root root  4096 Jan 23 12:22 .
4 drwxr-xr-x  3 root root  4096 Jan 23 12:22 ..
4 drwxr-x---  4 root root  4096 Jan 23 12:22 ModuleCache
4 drwxr-xr-x  2 root root  4096 Jan 23 12:22 Modules
24 -rw-r--r--  1 root root 23796 Jan 23 12:22 description.json
4 drwxr-x---  3 root root  4096 Jan 23 12:22 index
32 -rwxr-xr-x  1 root root 32672 Jan 23 12:22 libtmp.so
24 -rw-r--r--  1 root root 23796 Jan 23 12:22 plugin-tools-description.json
4 -rw-r--r--  1 root root    75 Jan 23 12:22 swift-version-24593BA9C3E375BF.txt
4 drwxr-xr-x  3 root root  4096 Jan 23 12:22 tmp.build
4 drwxr-xr-x  2 root root  4096 Jan 23 12:22 tmp.product
4 drwxr-xr-x  3 root root  4096 Jan 23 12:22 tmpPackageDiscoveredTests.build
4 drwxr-xr-x  3 root root  4096 Jan 23 12:22 tmpPackageTests.build
4 drwxr-xr-x  2 root root  4096 Jan 23 12:22 tmpTests.build



root@a786dbc79a0d:/tmp# ldd .build/debug/libtmp.so # this still has the swift libraries, obviously
linux-vdso.so.1 (0x00007fff15946000)
libswiftSwiftOnoneSupport.so => /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so (0x00007dd1c5e73000)
libswiftCore.so => /usr/lib/swift/linux/libswiftCore.so (0x00007dd1c5784000)
libswift_Concurrency.so => /usr/lib/swift/linux/libswift_Concurrency.so (0x00007dd1c56e2000)
libswift_StringProcessing.so => /usr/lib/swift/linux/libswift_StringProcessing.so (0x00007dd1c5629000)
libswift_RegexParser.so => /usr/lib/swift/linux/libswift_RegexParser.so (0x00007dd1c5511000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007dd1c52fa000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007dd1c507c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007dd1c4f93000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007dd1c4f65000)
/lib64/ld-linux-x86-64.so.2 (0x00007dd1c5ec5000)
libdispatch.so => /usr/lib/swift/linux/libdispatch.so (0x00007dd1c4f06000)
libswift_Builtin_float.so => /usr/lib/swift/linux/libswift_Builtin_float.so (0x00007dd1c4f00000)
libswiftGlibc.so => /usr/lib/swift/linux/libswiftGlibc.so (0x00007dd1c4ef0000)
libBlocksRuntime.so => /usr/lib/swift/linux/libBlocksRuntime.so (0x00007dd1c4eec000)



root@a786dbc79a0d:/tmp# swift build --static-swift-stdlib
[1/1] Planning build
Building for debugging...
[1/1] Write swift-version-24593BA9C3E375BF.txt
Build complete! (0.13s)



root@a786dbc79a0d:/tmp# ldd .build/debug/libtmp.so
linux-vdso.so.1 (0x00007ffc4bb70000)
libswiftSwiftOnoneSupport.so => /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so (0x00007acdd5108000)
libswiftCore.so => /usr/lib/swift/linux/libswiftCore.so (0x00007acdd4a19000)
libswift_Concurrency.so => /usr/lib/swift/linux/libswift_Concurrency.so (0x00007acdd4977000)
libswift_StringProcessing.so => /usr/lib/swift/linux/libswift_StringProcessing.so (0x00007acdd48be000)
libswift_RegexParser.so => /usr/lib/swift/linux/libswift_RegexParser.so (0x00007acdd47a6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007acdd458f000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007acdd4311000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007acdd4228000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007acdd41fa000)
/lib64/ld-linux-x86-64.so.2 (0x00007acdd515a000)
libdispatch.so => /usr/lib/swift/linux/libdispatch.so (0x00007acdd419b000)
libswift_Builtin_float.so => /usr/lib/swift/linux/libswift_Builtin_float.so (0x00007acdd4195000)
libswiftGlibc.so => /usr/lib/swift/linux/libswiftGlibc.so (0x00007acdd4185000)
libBlocksRuntime.so => /usr/lib/swift/linux/libBlocksRuntime.so (0x00007acdd4181000)



root@a786dbc79a0d:/tmp# swift build --static-swift-stdlib -Xswiftc -static-stdlib
Building for debugging...
[1/1] Write swift-version-24593BA9C3E375BF.txt
Build complete! (0.07s)


root@a786dbc79a0d:/tmp# ldd .build/debug/libtmp.so
linux-vdso.so.1 (0x00007ffdb094c000)
libswiftSwiftOnoneSupport.so => /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so (0x00007210f5cd6000)
libswiftCore.so => /usr/lib/swift/linux/libswiftCore.so (0x00007210f55e7000)
libswift_Concurrency.so => /usr/lib/swift/linux/libswift_Concurrency.so (0x00007210f5545000)
libswift_StringProcessing.so => /usr/lib/swift/linux/libswift_StringProcessing.so (0x00007210f548c000)
libswift_RegexParser.so => /usr/lib/swift/linux/libswift_RegexParser.so (0x00007210f5374000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007210f515d000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007210f4edf000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007210f4df6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007210f4dc8000)
/lib64/ld-linux-x86-64.so.2 (0x00007210f5d28000)
libdispatch.so => /usr/lib/swift/linux/libdispatch.so (0x00007210f4d69000)
libswift_Builtin_float.so => /usr/lib/swift/linux/libswift_Builtin_float.so (0x00007210f4d63000)
libswiftGlibc.so => /usr/lib/swift/linux/libswiftGlibc.so (0x00007210f4d53000)
libBlocksRuntime.so => /usr/lib/swift/linux/libBlocksRuntime.so (0x00007210f4d4f000)



root@a786dbc79a0d:/tmp# swift build --static-swift-stdlib -Xswiftc -static-stdlib swift sdk install https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum f30ec724d824ef43b5546e02ca06a8682dafab4b26a99fbb0e858c347e507a2c
error: Unknown option '--checksum'
Usage: swift build 
See 'build -help' for more information.



root@a786dbc79a0d:/tmp# swift sdk install https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum f30ec724d824ef43b5546e02ca06a8682dafab4b26a99fbb0e858c347e507a2c
Downloading a Swift SDK bundle archive from https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz...
Downloading
100% [=====================================================================================================]
Downloading swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz

Swift SDK bundle archive successfully downloaded from https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz.
Verifying if checksum of the downloaded archive is valid...
Downloaded archive has a valid checksum.
Swift SDK bundle at https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz is assumed to be an archive, unpacking...
Swift SDK bundle at https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz successfully installed as swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.


root@a786dbc79a0d:/tmp# swift build --static-swift-stdlib -Xswiftc -static-stdlib
Building for debugging...
[1/1] Write swift-version-24593BA9C3E375BF.txt
Build complete! (0.07s)



root@a786dbc79a0d:/tmp# swift build --static-swift-stdlib -Xswiftc -static-stdlib --swift-sdk x86_64-swift-linux-musl
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
ld.lld: error: relocation R_X86_64_TPOFF32 against __cxxabiv1::(anonymous namespace)::__globals()::eh_globals cannot be used with -shared

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(cxa_exception_storage.cpp.o)
referenced by cxa_exception_storage.cpp:33 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/cxa_exception_storage.cpp:33)
cxa_exception_storage.cpp.o:(__cxa_get_globals) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_TPOFF32 against __cxxabiv1::(anonymous namespace)::__globals()::eh_globals cannot be used with -shared

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(cxa_exception_storage.cpp.o)
referenced by cxa_exception_storage.cpp:33 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/cxa_exception_storage.cpp:33)
cxa_exception_storage.cpp.o:(__cxa_get_globals_fast) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::bad_cast'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_typeinfo.cpp.o)
referenced by stdlib_typeinfo.cpp:23 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_typeinfo.cpp:23)
stdlib_typeinfo.cpp.o:(std::bad_cast::bad_cast()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::bad_typeid'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_typeinfo.cpp.o)
referenced by stdlib_typeinfo.cpp:39 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_typeinfo.cpp:39)
stdlib_typeinfo.cpp.o:(std::bad_typeid::bad_typeid()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::bad_alloc'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_exception.cpp.o)
referenced by stdlib_exception.cpp:41 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_exception.cpp:41)
stdlib_exception.cpp.o:(std::bad_alloc::bad_alloc()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::bad_array_new_length'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_exception.cpp.o)
referenced by stdlib_exception.cpp:57 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_exception.cpp:57)
stdlib_exception.cpp.o:(std::bad_array_new_length::bad_array_new_length()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol '__cxa_unexpected_handler'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(cxa_default_handlers.cpp.o)
referenced by atomic_support.h:70 (/home/build-user/source/swift-project/llvm-project/libcxxabi/../libcxx/src/include/atomic_support.h:70)
cxa_default_handlers.cpp.o:(std::set_unexpected(void (*)())) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol '__cxa_terminate_handler'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(cxa_default_handlers.cpp.o)
referenced by atomic_support.h:70 (/home/build-user/source/swift-project/llvm-project/libcxxabi/../libcxx/src/include/atomic_support.h:70)
cxa_default_handlers.cpp.o:(std::set_terminate(void (*)())) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::logic_error'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_stdexcept.cpp.o)
referenced by stdlib_stdexcept.cpp:22 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_stdexcept.cpp:22)
stdlib_stdexcept.cpp.o:(std::logic_error::~logic_error()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::logic_error'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_stdexcept.cpp.o)
referenced by stdlib_stdexcept.cpp:22 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_stdexcept.cpp:22)
stdlib_stdexcept.cpp.o:(std::logic_error::~logic_error()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::runtime_error'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_stdexcept.cpp.o)
referenced by stdlib_stdexcept.cpp:30 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_stdexcept.cpp:30)
stdlib_stdexcept.cpp.o:(std::runtime_error::~runtime_error()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__shim_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:481 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:481)
private_typeinfo.cpp.o:(__cxxabiv1::__class_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__class_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:481 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:481)
private_typeinfo.cpp.o:(__cxxabiv1::__class_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'vtable for std::runtime_error'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(stdlib_stdexcept.cpp.o)
referenced by stdlib_stdexcept.cpp:30 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/stdlib_stdexcept.cpp:30)
stdlib_stdexcept.cpp.o:(std::runtime_error::~runtime_error()) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__shim_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:631 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:631)
private_typeinfo.cpp.o:(__cxxabiv1::__pbase_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__pbase_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:631 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:631)
private_typeinfo.cpp.o:(__cxxabiv1::__pbase_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo name for std::nullptr_t'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by typeinfo:202 (include/c++/v1/typeinfo:202)
private_typeinfo.cpp.o:(__cxxabiv1::__pointer_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__shim_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:631 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:631)
private_typeinfo.cpp.o:(__cxxabiv1::__pointer_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__pbase_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:631 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:631)
private_typeinfo.cpp.o:(__cxxabiv1::__pointer_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'typeinfo for __cxxabiv1::__shim_type_info'; recompile with -fPIC

defined in /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a(private_typeinfo.cpp.o)
referenced by private_typeinfo.cpp:666 (/home/build-user/source/swift-project/llvm-project/libcxxabi/src/private_typeinfo.cpp:666)
private_typeinfo.cpp.o:(__cxxabiv1::__pointer_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const) in archive /root/.swiftpm/swift-sdks/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a

ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[7/8] Linking libtmp.so
root@a786dbc79a0d:/tmp#

Package.swift:

// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "tmp",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "tmp",
type: .dynamic,
targets: ["tmp"]
),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "tmp"
),
.testTarget(
name: "tmpTests",
dependencies: ["tmp"]
),
]
)

Out of curiosity: What is the difference between the new static sdk and the compiler options from swift 5.10