From: Jason Liu Date: Wed, 13 Mar 2019 21:50:25 +0000 (+0000) Subject: [AIX][CMake] Changes for building on AIX with XL and GCC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7dc7b58c4c68885238ff360085a8a92fadd93a8;p=llvm [AIX][CMake] Changes for building on AIX with XL and GCC Summary: In support of IBM's efforts to produce a viable C and C++ LLVM compiler for AIX (ref: RFC at http://lists.llvm.org/pipermail/llvm-dev/2019-February/130175.html), this patch adds customizations to the CMake files in order to properly invoke the host toolchain for the build on AIX. Additional changes to enable a successful build will follow. Patch by Xing Xue Reviewers: hubert.reinterpretcast, jasonliu, sfertile Reviewed by: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D58250 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356104 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 388f9060903..7325cacc752 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -221,7 +221,8 @@ function(add_link_opts target_name) 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 @@ function(add_link_opts target_name) 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/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 3bc806f9bf0..f94b79f819c 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -135,12 +135,32 @@ if(APPLE) 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() @@ -220,8 +240,9 @@ if( LLVM_ENABLE_PIC ) 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/include/llvm/Config/abi-breaking.h.cmake b/include/llvm/Config/abi-breaking.h.cmake index 89c66bd7d11..a1ffad66077 100644 --- a/include/llvm/Config/abi-breaking.h.cmake +++ b/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(__GNUC__) && !defined(__clang__)) +#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