Skip to content

Commit 871ee79

Browse files
committed
Link the concurrency runtime against libatomic on Linux.
We mostly get away without this because we're fairly disciplined about using constant memory orderings, and apparently that's usually good enough to get inline accesses and avoid needing to link atomic. However, we have a few places with the task status atomic that use a non-constant load ordering with load and compare_exchange_weak, and my recent change to make that atomic a double-word was apparently sufficient on some (but not all) Linux distributions to get the compiler to call the runtime function. Regardless, we shouldn't be playing around in the margins here: Linux requires us to link libatomic, so we should.
1 parent a5732dd commit 871ee79

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ if(SWIFT_CONCURRENCY_USES_DISPATCH)
2929
endif()
3030
endif()
3131

32+
# Linux requires us to link an atomic library to use atomics.
33+
# Frustratingly, in many cases this isn't necessary because the
34+
# sequence is inlined, but we have some code that's just subtle
35+
# enough to turn into runtime calls.
36+
if(SWIFT_HOST_VARIANT STREQUAL "Linux")
37+
if(SWIFT_HOST_VARIANT_ARCH MATCHES "armv6|armv7|i686")
38+
list(APPEND swift_concurrency_link_libraries
39+
atomic)
40+
endif()
41+
endif()
3242

3343
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
3444
../CompatibilityOverride/CompatibilityOverride.cpp

0 commit comments

Comments
 (0)