forked from OSchip/llvm-project
[AIX][compiler-rt] Build and install standalone libatomic
On AIX, we have to ship `libatomic.a` for compatibility. First, a new `clang_rt.atomic` is added. Second, use added cmake modules for AIX, we are able to build a compatible libatomic.a for AIX. The second step can't be perfectly implemented with cmake now since AIX's archive approach is kinda unique, i.e., archiving shared libraries into a static archive file. Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D102155
This commit is contained in:
parent
4b91f96a3e
commit
d56729b4a4
|
@ -0,0 +1,53 @@
|
|||
include(CMakeParseArguments)
|
||||
include(CompilerRTUtils)
|
||||
|
||||
function(get_aix_libatomic_default_link_flags link_flags export_list)
|
||||
set(${link_flags}
|
||||
"-Wl,-H512 -Wl,-D0 \
|
||||
-Wl,-T512 -Wl,-bhalt:4 -Wl,-bernotok \
|
||||
-Wl,-bnoentry -Wl,-bexport:${export_list} \
|
||||
-Wl,-bmodtype:SRE -Wl,-lc" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
macro(archive_aix_libatomic name)
|
||||
cmake_parse_arguments(LIB
|
||||
""
|
||||
""
|
||||
"ARCHS;PARENT_TARGET"
|
||||
${ARGN})
|
||||
set(shared_libraries_to_archive "")
|
||||
foreach (arch ${LIB_ARCHS})
|
||||
if(CAN_TARGET_${arch})
|
||||
set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/libatomic-${arch}.dir")
|
||||
# FIXME: Target name should be kept consistent with definition
|
||||
# in AddCompilerRT.cmake added by
|
||||
# add_compiler_rt_runtime(<name> SHARED ...)
|
||||
set(target ${name}-dynamic-${arch})
|
||||
if(TARGET ${target})
|
||||
file(MAKE_DIRECTORY ${output_dir})
|
||||
add_custom_command(OUTPUT "${output_dir}/libatomic.so.1"
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
copy "$<TARGET_FILE:${target}>"
|
||||
"${output_dir}/libatomic.so.1"
|
||||
DEPENDS ${target})
|
||||
list(APPEND shared_libraries_to_archive "${output_dir}/libatomic.so.1")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if(shared_libraries_to_archive)
|
||||
set(output_dir "")
|
||||
set(install_dir "")
|
||||
get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir)
|
||||
get_compiler_rt_install_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} install_dir)
|
||||
add_custom_command(OUTPUT "${output_dir}/libatomic.a"
|
||||
COMMAND ${CMAKE_AR} -X32_64 r "${output_dir}/libatomic.a"
|
||||
${shared_libraries_to_archive}
|
||||
DEPENDS ${shared_libraries_to_archive})
|
||||
install(FILES "${output_dir}/libatomic.a"
|
||||
DESTINATION ${install_dir})
|
||||
add_custom_target(aix-libatomic
|
||||
DEPENDS "${output_dir}/libatomic.a")
|
||||
endif()
|
||||
add_dependencies(${LIB_PARENT_TARGET} aix-libatomic)
|
||||
endmacro()
|
|
@ -48,6 +48,10 @@ endif()
|
|||
|
||||
include(builtin-config-ix)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
|
||||
include(CompilerRTAIXUtils)
|
||||
endif()
|
||||
|
||||
option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
|
||||
"Do not export any symbols from the static library." ON)
|
||||
|
||||
|
@ -747,4 +751,42 @@ else ()
|
|||
endforeach ()
|
||||
endif ()
|
||||
|
||||
option(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC
|
||||
"Build standalone shared atomic library."
|
||||
OFF)
|
||||
|
||||
if(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
|
||||
add_custom_target(builtins-standalone-atomic)
|
||||
set(BUILTIN_DEPS "")
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
|
||||
if(NOT COMPILER_RT_LIBATOMIC_LINK_FLAGS)
|
||||
get_aix_libatomic_default_link_flags(COMPILER_RT_LIBATOMIC_LINK_FLAGS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ppc/atomic.exp")
|
||||
endif()
|
||||
# The compiler needs builtins to link any other binaries, so let
|
||||
# clang_rt.atomic be built after builtins.
|
||||
set(BUILTIN_DEPS builtins)
|
||||
endif()
|
||||
foreach (arch ${BUILTIN_SUPPORTED_ARCH})
|
||||
if(CAN_TARGET_${arch})
|
||||
add_compiler_rt_runtime(clang_rt.atomic
|
||||
SHARED
|
||||
ARCHS ${arch}
|
||||
SOURCES atomic.c
|
||||
LINK_FLAGS ${COMPILER_RT_LIBATOMIC_LINK_FLAGS}
|
||||
DEPS ${BUILTIN_DEPS}
|
||||
PARENT_TARGET builtins-standalone-atomic)
|
||||
endif()
|
||||
endforeach()
|
||||
# FIXME: On AIX, we have to archive built shared libraries into a static
|
||||
# archive, i.e., libatomic.a. Once cmake adds support of such usage for AIX,
|
||||
# this ad-hoc part can be removed.
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
|
||||
archive_aix_libatomic(clang_rt.atomic
|
||||
ARCHS ${BUILTIN_SUPPORTED_ARCH}
|
||||
PARENT_TARGET builtins-standalone-atomic)
|
||||
endif()
|
||||
add_dependencies(compiler-rt builtins-standalone-atomic)
|
||||
endif()
|
||||
|
||||
add_dependencies(compiler-rt builtins)
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
__atomic_compare_exchange
|
||||
__atomic_compare_exchange_1
|
||||
__atomic_compare_exchange_2
|
||||
__atomic_compare_exchange_4
|
||||
__atomic_compare_exchange_8
|
||||
__atomic_exchange
|
||||
__atomic_exchange_1
|
||||
__atomic_exchange_2
|
||||
__atomic_exchange_4
|
||||
__atomic_exchange_8
|
||||
__atomic_fetch_add_1
|
||||
__atomic_fetch_add_2
|
||||
__atomic_fetch_add_4
|
||||
__atomic_fetch_add_8
|
||||
__atomic_fetch_and_1
|
||||
__atomic_fetch_and_2
|
||||
__atomic_fetch_and_4
|
||||
__atomic_fetch_and_8
|
||||
__atomic_fetch_or_1
|
||||
__atomic_fetch_or_2
|
||||
__atomic_fetch_or_4
|
||||
__atomic_fetch_or_8
|
||||
__atomic_fetch_sub_1
|
||||
__atomic_fetch_sub_2
|
||||
__atomic_fetch_sub_4
|
||||
__atomic_fetch_sub_8
|
||||
__atomic_fetch_xor_1
|
||||
__atomic_fetch_xor_2
|
||||
__atomic_fetch_xor_4
|
||||
__atomic_fetch_xor_8
|
||||
__atomic_is_lock_free
|
||||
__atomic_load
|
||||
__atomic_load_1
|
||||
__atomic_load_2
|
||||
__atomic_load_4
|
||||
__atomic_load_8
|
||||
__atomic_store
|
||||
__atomic_store_1
|
||||
__atomic_store_2
|
||||
__atomic_store_4
|
||||
__atomic_store_8
|
Loading…
Reference in New Issue