[compiler-rt] 6393164 - [AIX][compiler-rt] Fix cmake build of libatomic for cmake-3.16+
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 11 17:12:36 PDT 2021
Author: Kai Luo
Date: 2021-06-12T00:12:29Z
New Revision: 6393164cf249a2d4ef5cb55107cda5d9476787a3
URL: https://github.com/llvm/llvm-project/commit/6393164cf249a2d4ef5cb55107cda5d9476787a3
DIFF: https://github.com/llvm/llvm-project/commit/6393164cf249a2d4ef5cb55107cda5d9476787a3.diff
LOG: [AIX][compiler-rt] Fix cmake build of libatomic for cmake-3.16+
cmake-3.16+ for AIX changes the default behavior of building a `SHARED` library which breaks AIX's build of libatomic, i.e., cmake-3.16+ builds `SHARED` as an archive of dynamic libraries. To fix it, we have to build `libatomic.so.1` as `MODULE` which keeps `libatomic.so.1` as an normal dynamic library.
Reviewed By: jsji
Differential Revision: https://reviews.llvm.org/D103786
Added:
Modified:
compiler-rt/cmake/Modules/AddCompilerRT.cmake
compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
compiler-rt/lib/builtins/CMakeLists.txt
Removed:
################################################################################
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index ca2f34e618ab..1e9e7c58664b 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -148,7 +148,7 @@ endmacro()
# Adds static or shared runtime for a list of architectures and operating
# systems and puts it in the proper directory in the build and install trees.
# add_compiler_rt_runtime(<name>
-# {OBJECT|STATIC|SHARED}
+# {OBJECT|STATIC|SHARED|MODULE}
# ARCHS <architectures>
# OS <os list>
# SOURCES <source files>
@@ -161,8 +161,9 @@ endmacro()
# PARENT_TARGET <convenience parent target>
# ADDITIONAL_HEADERS <header files>)
function(add_compiler_rt_runtime name type)
- if(NOT type MATCHES "^(OBJECT|STATIC|SHARED)$")
- message(FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED")
+ if(NOT type MATCHES "^(OBJECT|STATIC|SHARED|MODULE)$")
+ message(FATAL_ERROR
+ "type argument must be OBJECT, STATIC, SHARED or MODULE")
return()
endif()
cmake_parse_arguments(LIB
diff --git a/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
index 3f89682cc110..983d97df2d29 100644
--- a/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
@@ -2,11 +2,26 @@ include(CMakeParseArguments)
include(CompilerRTUtils)
function(get_aix_libatomic_default_link_flags link_flags export_list)
- set(${link_flags}
+ set(linkopts
"-Wl,-H512 -Wl,-D0 \
-Wl,-T512 -Wl,-bhalt:4 -Wl,-bernotok \
-Wl,-bnoentry -Wl,-bexport:${export_list} \
- -Wl,-bmodtype:SRE -Wl,-lc" PARENT_SCOPE)
+ -Wl,-bmodtype:SRE -Wl,-lc")
+ # Add `-Wl,-G`. Quoted from release notes of cmake-3.16.0
+ # > On AIX, runtime linking is no longer enabled by default.
+ # See https://cmake.org/cmake/help/latest/release/3.16.html
+ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
+ set(linkopts "-Wl,-G" "${linkopts}")
+ endif()
+ set(${link_flags} ${linkopts} PARENT_SCOPE)
+endfunction()
+
+function(get_aix_libatomic_type type)
+ if(${CMAKE_VERSION} VERSION_LESS "3.16.0")
+ set(${type} SHARED PARENT_SCOPE)
+ else()
+ set(${type} MODULE PARENT_SCOPE)
+ endif()
endfunction()
macro(archive_aix_libatomic name)
@@ -30,6 +45,10 @@ macro(archive_aix_libatomic name)
COMMAND ${CMAKE_COMMAND} -E
copy "$<TARGET_FILE:${target}>"
"${output_dir}/libatomic.so.1"
+ # If built with MODULE, F_LOADONLY is set.
+ # We have to remove this flag at POST_BUILD.
+ COMMAND ${CMAKE_STRIP} -X32_64 -E
+ "${output_dir}/libatomic.so.1"
DEPENDS ${target})
list(APPEND shared_libraries_to_archive "${output_dir}/libatomic.so.1")
endif()
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index bbb322595225..628fe0558fdc 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -759,6 +759,7 @@ option(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC
if(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
add_custom_target(builtins-standalone-atomic)
set(BUILTIN_DEPS "")
+ set(BUILTIN_TYPE SHARED)
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
if(NOT COMPILER_RT_LIBATOMIC_LINK_FLAGS)
get_aix_libatomic_default_link_flags(COMPILER_RT_LIBATOMIC_LINK_FLAGS
@@ -767,11 +768,14 @@ if(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
# The compiler needs builtins to link any other binaries, so let
# clang_rt.atomic be built after builtins.
set(BUILTIN_DEPS builtins)
+ # For
diff erent versions of cmake, SHARED behaves
diff erently. For some
+ # versions, we might need MODULE rather than SHARED.
+ get_aix_libatomic_type(BUILTIN_TYPE)
endif()
foreach (arch ${BUILTIN_SUPPORTED_ARCH})
if(CAN_TARGET_${arch})
add_compiler_rt_runtime(clang_rt.atomic
- SHARED
+ ${BUILTIN_TYPE}
ARCHS ${arch}
SOURCES atomic.c
LINK_FLAGS ${COMPILER_RT_LIBATOMIC_LINK_FLAGS}
More information about the llvm-commits
mailing list