[PATCH] D103786: [AIX][compiler-rt] Fix cmake build of libatomic for cmake-3.16+

Kai Luo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 17:12:39 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6393164cf249: [AIX][compiler-rt] Fix cmake build of libatomic for cmake-3.16+ (authored by lkail).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103786/new/

https://reviews.llvm.org/D103786

Files:
  compiler-rt/cmake/Modules/AddCompilerRT.cmake
  compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
  compiler-rt/lib/builtins/CMakeLists.txt


Index: compiler-rt/lib/builtins/CMakeLists.txt
===================================================================
--- compiler-rt/lib/builtins/CMakeLists.txt
+++ compiler-rt/lib/builtins/CMakeLists.txt
@@ -759,6 +759,7 @@
 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 @@
     # The compiler needs builtins to link any other binaries, so let
     # clang_rt.atomic be built after builtins.
     set(BUILTIN_DEPS builtins)
+    # For different versions of cmake, SHARED behaves differently. 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}
Index: compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
===================================================================
--- compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
@@ -2,11 +2,26 @@
 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 @@
                            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()
Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake
===================================================================
--- compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -148,7 +148,7 @@
 # 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 @@
 #                         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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103786.351597.patch
Type: text/x-patch
Size: 4271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210612/a90fa129/attachment.bin>


More information about the llvm-commits mailing list