Skip to content

Commit 1602c6f

Browse files
[AIX][cmake] Adjust management of -G for linking
The change in 0ba9843 changed the behaviour of the build when using an XL build compiler because `-G` is not a pure linker option: it also implies `-shared`. This was accounted for in the base CMake configuration, so an analysis of the change from 0ba9843 in relation to a build using Clang (where `-shared` is introduced by CMake) would not identify the issue. This patch resolves this particular issue by adding `-shared` alongside `-Wl,-G`. At the same time, the investigation reveals that several aspects of the various build configurations are not operating in the manner originally intended. The other issue related to the `-G` linker option in the build is that the removal of it (to avoid unnecessary use of run-time linking) is not effective for the build using the Clang compiler. This patch addresses this by adjusting the regular expressions used to remove the broadly- applied `-G`. Finally, the issue of specifying the export list with `-Wl,` instead of a compiler option is flagged with a FIXME comment. Reviewed By: daltenty, amyk Differential Revision: https://reviews.llvm.org/D90041
1 parent b67a2ae commit 1602c6f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

llvm/CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -917,20 +917,26 @@ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
917917
# configuration, it is still possible the user may force it as part of a
918918
# compound option.
919919
if(CMAKE_VERSION VERSION_LESS 3.16)
920-
string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
921-
string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
922-
string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
923-
string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" "" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
920+
string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
921+
string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
922+
string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
923+
string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
924924
"${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
925-
string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" "" CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS
925+
string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS
926926
"${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
927-
string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" "" CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS
927+
string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS
928+
"${CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS}")
929+
string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
930+
"${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
931+
string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS
932+
"${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
933+
string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS
928934
"${CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS}")
929935
endif()
930936

931-
# Modules should be built with -G, so we can use runtime linking with
932-
# plugins.
933-
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -Wl,-G")
937+
# Modules should be built with -shared -Wl,-G, so we can use runtime linking
938+
# with plugins.
939+
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G")
934940

935941
# Also set the correct flags for building shared libraries.
936942
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared")

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function(add_llvm_symbol_exports target_name export_file)
9090
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
9191
LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
9292
elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
93+
# FIXME: `-Wl,-bE:` bypasses whatever handling there is in the build
94+
# compiler driver to defer to the specified export list.
9395
set(native_export_file "${export_file}")
9496
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
9597
LINK_FLAGS " -Wl,-bE:${export_file}")

0 commit comments

Comments
 (0)