Skip to content

Remove dependency on libatomic on Linux #29581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions cmake/modules/AddSwiftUnittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SwiftShims/RefCount.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class RefCountBitsT {

typedef RefCountBitsT<RefCountIsInline> InlineRefCountBits;

class SideTableRefCountBits : public RefCountBitsT<RefCountNotInline>
class alignas(sizeof(void*) * 2) SideTableRefCountBits : public RefCountBitsT<RefCountNotInline>
{
uint32_t weakBits;

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down