Skip to content

Commit 97df90f

Browse files
authored
Merge pull request #29581 from drexin/wip-fix-atomics
Remove dependency on libatomic on Linux
2 parents 486de42 + 29749e6 commit 97df90f

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ function(_add_variant_c_compile_flags)
349349
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
350350
endif()
351351

352+
if("${CFLAGS_SDK}" STREQUAL "LINUX")
353+
if(${CFLAGS_ARCH} STREQUAL x86_64)
354+
# this is the minimum architecture that supports 16 byte CAS, which is necessary to avoid a dependency to libatomic
355+
list(APPEND result "-march=core2")
356+
endif()
357+
endif()
358+
352359
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
353360
endfunction()
354361

@@ -466,7 +473,7 @@ function(_add_variant_link_flags)
466473
RESULT_VAR_NAME result
467474
MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR}")
468475
if("${LFLAGS_SDK}" STREQUAL "LINUX")
469-
list(APPEND link_libraries "pthread" "atomic" "dl")
476+
list(APPEND link_libraries "pthread" "dl")
470477
elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD")
471478
list(APPEND link_libraries "pthread")
472479
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
@@ -631,7 +631,7 @@ class RefCountBitsT {
631631

632632
typedef RefCountBitsT<RefCountIsInline> InlineRefCountBits;
633633

634-
class SideTableRefCountBits : public RefCountBitsT<RefCountNotInline>
634+
class alignas(sizeof(void*) * 2) SideTableRefCountBits : public RefCountBitsT<RefCountNotInline>
635635
{
636636
uint32_t weakBits;
637637

stdlib/public/runtime/Metadata.cpp

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

51175117
namespace {
5118-
struct PoolRange {
5118+
struct alignas(sizeof(uintptr_t) * 2) PoolRange {
51195119
static constexpr uintptr_t PageSize = 16 * 1024;
51205120
static constexpr uintptr_t MaxPoolAllocationSize = PageSize / 2;
51215121

0 commit comments

Comments
 (0)