Skip to content

Commit 679273a

Browse files
authored
Merge pull request #31053 from drexin/wip-backport-atomics-fix
[5.2] Remove dependency on libatomic on Linux
2 parents 517f414 + c2a0d16 commit 679273a

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ function(_add_variant_c_compile_flags)
363363
endif()
364364
endif()
365365

366+
if("${CFLAGS_SDK}" STREQUAL "LINUX")
367+
if(${CFLAGS_ARCH} STREQUAL x86_64)
368+
# this is the minimum architecture that supports 16 byte CAS, which is necessary to avoid a dependency to libatomic
369+
list(APPEND result "-march=core2")
370+
endif()
371+
endif()
372+
366373
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
367374
endfunction()
368375

@@ -460,7 +467,7 @@ function(_add_variant_link_flags)
460467
RESULT_VAR_NAME result)
461468

462469
if("${LFLAGS_SDK}" STREQUAL "LINUX")
463-
list(APPEND link_libraries "pthread" "atomic" "dl")
470+
list(APPEND link_libraries "pthread" "dl")
464471
elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD")
465472
list(APPEND link_libraries "pthread")
466473
elseif("${LFLAGS_SDK}" STREQUAL "CYGWIN")

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ function(add_swift_unittest test_dirname)
4848
"${android_system_libs}")
4949
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES "log")
5050
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
51-
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES
52-
"atomic")
51+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
52+
target_compile_options(${test_dirname} PRIVATE
53+
-march=core2)
54+
endif()
5355
endif()
5456

5557
find_program(LDLLD_PATH "ld.lld")

stdlib/public/SwiftShims/RefCount.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class RefCountBitsT {
589589

590590
typedef RefCountBitsT<RefCountIsInline> InlineRefCountBits;
591591

592-
class SideTableRefCountBits : public RefCountBitsT<RefCountNotInline>
592+
class alignas(sizeof(void*) * 2) SideTableRefCountBits : public RefCountBitsT<RefCountNotInline>
593593
{
594594
uint32_t weakBits;
595595

stdlib/public/runtime/Metadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5054,7 +5054,7 @@ void swift::checkMetadataDependencyCycle(const Metadata *startMetadata,
50545054
/***************************************************************************/
50555055

50565056
namespace {
5057-
struct PoolRange {
5057+
struct alignas(sizeof(uintptr_t) * 2) PoolRange {
50585058
static constexpr uintptr_t PageSize = 16 * 1024;
50595059
static constexpr uintptr_t MaxPoolAllocationSize = PageSize / 2;
50605060

unittests/runtime/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
5050
${FOUNDATION_LIBRARY}
5151
swiftStdlibUnittest${SWIFT_PRIMARY_VARIANT_SUFFIX}
5252
)
53-
elseif(SWIFT_HOST_VARIANT STREQUAL "linux")
54-
list(APPEND PLATFORM_TARGET_LINK_LIBRARIES "atomic")
5553
elseif(SWIFT_HOST_VARIANT STREQUAL "freebsd")
5654
find_library(EXECINFO_LIBRARY execinfo)
5755
list(APPEND PLATFORM_TARGET_LINK_LIBRARIES

unittests/runtime/LongTests/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
1919

2020
# Link the Objective-C runtime.
2121
list(APPEND PLATFORM_TARGET_LINK_LIBRARIES "objc")
22-
elseif(SWIFT_HOST_VARIANT STREQUAL "linux")
23-
list(APPEND PLATFORM_TARGET_LINK_LIBRARIES
24-
"atomic"
25-
)
2622
elseif(SWIFT_HOST_VARIANT STREQUAL "freebsd")
2723
find_library(EXECINFO_LIBRARY execinfo)
2824
list(APPEND PLATFORM_TARGET_LINK_LIBRARIES

utils/gen-static-stdlib-link-args

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ function write_linkfile {
6161
cat >$OUTPUTFILE <<EOF
6262
-ldl
6363
-lpthread
64-
-latomic
6564
-lswiftCore
66-
-latomic
6765
-lswiftImageInspectionShared
6866
$ICU_LIBS
6967
-lstdc++

utils/static-executable-args.lnk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
-Xlinker
99
--defsym=__import_pthread_key_create=pthread_key_create
1010
-lpthread
11-
-latomic
1211
-licui18n
1312
-licuuc
1413
-licudata

0 commit comments

Comments
 (0)