diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index a89442f485d85..dee7278559026 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -349,6 +349,13 @@ function(_add_variant_c_compile_flags) list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}") endif() + if("${CFLAGS_SDK}" STREQUAL "LINUX") + if(${CFLAGS_ARCH} STREQUAL x86_64) + # this is the minimum architecture that supports 16 byte CAS, which is necessary to avoid a dependency to libatomic + list(APPEND result "-march=core2") + endif() + endif() + set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE) endfunction() @@ -466,7 +473,7 @@ function(_add_variant_link_flags) RESULT_VAR_NAME result MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR}") if("${LFLAGS_SDK}" STREQUAL "LINUX") - list(APPEND link_libraries "pthread" "atomic" "dl") + list(APPEND link_libraries "pthread" "dl") elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD") list(APPEND link_libraries "pthread") elseif("${LFLAGS_SDK}" STREQUAL "CYGWIN") diff --git a/cmake/modules/AddSwiftUnittests.cmake b/cmake/modules/AddSwiftUnittests.cmake index 5da0ae3ac44e3..3e53e6696e444 100644 --- a/cmake/modules/AddSwiftUnittests.cmake +++ b/cmake/modules/AddSwiftUnittests.cmake @@ -48,8 +48,10 @@ function(add_swift_unittest test_dirname) "${android_system_libs}") set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES "log") elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES - "atomic") + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") + target_compile_options(${test_dirname} PRIVATE + -march=core2) + endif() endif() find_program(LDLLD_PATH "ld.lld") diff --git a/stdlib/public/SwiftShims/RefCount.h b/stdlib/public/SwiftShims/RefCount.h index 1de032c56f49b..c4fee4c22dab0 100644 --- a/stdlib/public/SwiftShims/RefCount.h +++ b/stdlib/public/SwiftShims/RefCount.h @@ -631,7 +631,7 @@ class RefCountBitsT { typedef RefCountBitsT InlineRefCountBits; -class SideTableRefCountBits : public RefCountBitsT +class alignas(sizeof(void*) * 2) SideTableRefCountBits : public RefCountBitsT { uint32_t weakBits; diff --git a/stdlib/public/runtime/Metadata.cpp b/stdlib/public/runtime/Metadata.cpp index 2546d90dec5cd..687dd83dbb7e4 100644 --- a/stdlib/public/runtime/Metadata.cpp +++ b/stdlib/public/runtime/Metadata.cpp @@ -5115,7 +5115,7 @@ void swift::checkMetadataDependencyCycle(const Metadata *startMetadata, /***************************************************************************/ namespace { - struct PoolRange { + struct alignas(sizeof(uintptr_t) * 2) PoolRange { static constexpr uintptr_t PageSize = 16 * 1024; static constexpr uintptr_t MaxPoolAllocationSize = PageSize / 2;