Skip to content

Commit 1977a68

Browse files
committed
Fix statically linked concurrency on Linux
Generating a statically-linked executable either with `-static-executable` or `-static-stdlib` that contains concurrency needs to link the concurrency libraries or the missing symbols will cause link failures. This patch adds dispatch and blocks runtime to the list of statically linked libraries. In the case of the static stdlib, it only adds them if the concurrency mechanisms use dispatch, otherwise it doesn't. For the static executable, it always adds them since that doesn't appear to be very configurable.
1 parent 025ee1e commit 1977a68

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

stdlib/public/runtime/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,13 @@ foreach(sdk ${SWIFT_SDKS})
209209
if(${SWIFT_SDK_${sdk}_OBJECT_FORMAT} STREQUAL ELF)
210210
string(TOLOWER "${sdk}" lowercase_sdk)
211211
set(libpthread -lpthread)
212+
set(concurrency_libs)
212213
set(android_libraries)
213214
if(${sdk} STREQUAL ANDROID)
214215
set(android_libraries -llog)
215216
set(libpthread)
217+
elseif(SWIFT_CONCURRENCY_USES_DISPATCH)
218+
set(concurrency_libs "-ldispatch -lBlocksRuntime")
216219
endif()
217220

218221
set(linkfile ${lowercase_sdk}/static-stdlib-args.lnk)
@@ -221,6 +224,7 @@ foreach(sdk ${SWIFT_SDKS})
221224
${libpthread}
222225
${android_libraries}
223226
-lswiftCore
227+
${concurrency_libs}
224228
-lstdc++
225229
-lm
226230
-Xlinker -export-dynamic

utils/static-executable-args.lnk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-undefined=pthread_once
77
-Xlinker
88
-undefined=pthread_key_create
9+
-ldispatch
10+
-lBlocksRuntime
911
-lpthread
1012
-licui18nswift
1113
-licuucswift

0 commit comments

Comments
 (0)