diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -851,6 +851,12 @@ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") add_definitions("-D_XOPEN_SOURCE=700") add_definitions("-D_LARGE_FILE_API") + + # CMake versions less than 3.16 set linker flags to include -brtl by default, + # so clear it out. + string(REPLACE "-Wl,-brtl" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") + string(REPLACE "-Wl,-brtl" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}") + string(REPLACE "-Wl,-brtl" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") endif() # Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9. diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -90,6 +90,7 @@ set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"") elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX") + set(native_export_file "${export_file}") set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-bE:${export_file}") elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -11,6 +11,7 @@ include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckSymbolExists) +include(CMakeDependentOption) if(CMAKE_LINKER MATCHES "lld-link" OR (WIN32 AND LLVM_USE_LINKER STREQUAL "lld") OR LLVM_ENABLE_LLD) set(LINKER_IS_LLD_LINK TRUE) @@ -909,11 +910,20 @@ endif() # This option makes utils/extract_symbols.py be used to determine the list of -# symbols to export from LLVM tools. This is necessary when using MSVC if you -# want to allow plugins, though note that the plugin has to explicitly link -# against (exactly one) tool so we can't unilaterally turn on -# LLVM_ENABLE_PLUGINS when it's enabled. -option(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS "Export symbols from LLVM tools so that plugins can import them" OFF) +# symbols to export from LLVM tools. This is necessary when on AIX or using MSVC +# if you want to allow plugins. On AIX we don't show the option, and enable this +# by default except when the LLVM libraries are set up for dynamic linking, due +# to incompatibility in the initial configuration. With MSVC note though that +# the plugin has to explicitly link against (exactly one) tool so we can't +# unilaterally turn on LLVM_ENABLE_PLUGINS when it's enabled. +set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_default OFF) +if (NOT (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB)) + set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_default ON) +endif() + +CMAKE_DEPENDENT_OPTION(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS + "Export symbols from LLVM tools so that plugins can import them" OFF + "NOT ${CMAKE_SYSTEM_NAME} MATCHES AIX" ${LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_default}) if(BUILD_SHARED_LIBS AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) message(FATAL_ERROR "BUILD_SHARED_LIBS not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS") endif() diff --git a/llvm/utils/extract_symbols.py b/llvm/utils/extract_symbols.py --- a/llvm/utils/extract_symbols.py +++ b/llvm/utils/extract_symbols.py @@ -42,9 +42,14 @@ process.wait() def nm_get_symbols(lib): - process = subprocess.Popen(['nm','-P',lib], bufsize=1, - stdout=subprocess.PIPE, stdin=subprocess.PIPE, - universal_newlines=True) + if sys.platform.startswith('aix'): + process = subprocess.Popen(['nm','-P','-Xany','-C','-p',lib], bufsize=1, + stdout=subprocess.PIPE, stdin=subprocess.PIPE, + universal_newlines=True) + else: + process = subprocess.Popen(['nm','-P',lib], bufsize=1, + stdout=subprocess.PIPE, stdin=subprocess.PIPE, + universal_newlines=True) process.stdin.close() for line in process.stdout: # Look for external symbols that are defined in some section