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 @@ -221,7 +221,8 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections") - elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND + NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD|AIX") # Object files are compiled with -ffunction-data-sections. # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks # tools that use plugins. Always pass --gc-sections once we require @@ -229,6 +230,11 @@ set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections") endif() + else() #LLVM_NO_DEAD_STRIP + if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-bnogc") + endif() endif() endif() endfunction(add_link_opts) 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 @@ -134,12 +134,32 @@ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress") endif() +if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if(NOT LLVM_BUILD_32_BITS) + if (CMAKE_CXX_COMPILER_ID MATCHES "XL") + append("-q64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) + else() + append("-maix64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) + endif() + set(CMAKE_CXX_ARCHIVE_CREATE " -X64 qc ") + set(CMAKE_CXX_ARCHIVE_APPEND " -X64 q ") + set(CMAKE_C_ARCHIVE_FINISH " -X64 ") + set(CMAKE_CXX_ARCHIVE_FINISH " -X64 ") + endif() + # -fPIC does not enable the large code model for GCC on AIX but does for XL. + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + append("-mcmodel=large" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL") + # XL generates a small number of relocations not of the large model, -bbigtoc is needed. + append("-Wl,-bbigtoc" + CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) + endif() +endif() + # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO # build might work on ELF but fail on MachO/COFF. -if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR - ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR - ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR - ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") AND +if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX" OR + WIN32 OR CYGWIN) AND NOT LLVM_USE_SANITIZER) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") endif() @@ -219,8 +239,9 @@ endif() endif() -if(NOT WIN32 AND NOT CYGWIN) +if(NOT WIN32 AND NOT CYGWIN AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) # MinGW warns if -fvisibility-inlines-hidden is used. + # GCC on AIX warns if -fvisibility-inlines-hidden is used. check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG) append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS) endif() diff --git a/llvm/include/llvm/Config/abi-breaking.h.cmake b/llvm/include/llvm/Config/abi-breaking.h.cmake --- a/llvm/include/llvm/Config/abi-breaking.h.cmake +++ b/llvm/include/llvm/Config/abi-breaking.h.cmake @@ -34,15 +34,27 @@ #elif defined(_WIN32) || defined(__CYGWIN__) // Win32 w/o #pragma detect_mismatch // FIXME: Implement checks without weak. #elif defined(__cplusplus) +#if !(defined(_AIX) && defined(__GNU__)) +#define LLVM_HIDDEN_VISIBILITY __attribute__ ((visibility("hidden"))) +#else +// GCC on AIX does not support visibility attributes. Symbols are not +// exported by default on AIX. +#define LLVM_HIDDEN_VISIBILITY +#endif namespace llvm { #if LLVM_ENABLE_ABI_BREAKING_CHECKS extern int EnableABIBreakingChecks; -__attribute__((weak, visibility ("hidden"))) int *VerifyEnableABIBreakingChecks = &EnableABIBreakingChecks; +LLVM_HIDDEN_VISIBILITY +__attribute__((weak)) int *VerifyEnableABIBreakingChecks = + &EnableABIBreakingChecks; #else extern int DisableABIBreakingChecks; -__attribute__((weak, visibility ("hidden"))) int *VerifyDisableABIBreakingChecks = &DisableABIBreakingChecks; +LLVM_HIDDEN_VISIBILITY +__attribute__((weak)) int *VerifyDisableABIBreakingChecks = + &DisableABIBreakingChecks; #endif } +#undef LLVM_HIDDEN_VISIBILITY #endif // _MSC_VER #endif // LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING