llvm.org GIT mirror llvm / b7dc7b5
[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 Jason Liu 7 months ago
3 changed file(s) with 47 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
220220 elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
221221 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
222222 LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")
223 elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
223 elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND
224 NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD|AIX")
224225 # Object files are compiled with -ffunction-data-sections.
225226 # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
226227 # tools that use plugins. Always pass --gc-sections once we require
227228 # a newer linker.
228229 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
229230 LINK_FLAGS " -Wl,--gc-sections")
231 endif()
232 else() #LLVM_NO_DEAD_STRIP
233 if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
234 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
235 LINK_FLAGS " -Wl,-bnogc")
230236 endif()
231237 endif()
232238 endif()
134134 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
135135 endif()
136136
137 if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
138 if(NOT LLVM_BUILD_32_BITS)
139 if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
140 append("-q64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
141 else()
142 append("-maix64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
143 endif()
144 set(CMAKE_CXX_ARCHIVE_CREATE " -X64 qc ")
145 set(CMAKE_CXX_ARCHIVE_APPEND " -X64 q ")
146 set(CMAKE_C_ARCHIVE_FINISH " -X64 ")
147 set(CMAKE_CXX_ARCHIVE_FINISH " -X64 ")
148 endif()
149 # -fPIC does not enable the large code model for GCC on AIX but does for XL.
150 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
151 append("-mcmodel=large" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
152 elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL")
153 # XL generates a small number of relocations not of the large model, -bbigtoc is needed.
154 append("-Wl,-bbigtoc"
155 CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
156 endif()
157 endif()
158
137159 # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
138160 # build might work on ELF but fail on MachO/COFF.
139 if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR
140 ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR
141 ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR
142 ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") AND
161 if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX" OR
162 WIN32 OR CYGWIN) AND
143163 NOT LLVM_USE_SANITIZER)
144164 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
145165 endif()
219239 endif()
220240 endif()
221241
222 if(NOT WIN32 AND NOT CYGWIN)
242 if(NOT WIN32 AND NOT CYGWIN AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
223243 # MinGW warns if -fvisibility-inlines-hidden is used.
244 # GCC on AIX warns if -fvisibility-inlines-hidden is used.
224245 check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
225246 append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS)
226247 endif()
3333 #elif defined(_WIN32) || defined(__CYGWIN__) // Win32 w/o #pragma detect_mismatch
3434 // FIXME: Implement checks without weak.
3535 #elif defined(__cplusplus)
36 #if !(defined(_AIX) && defined(__GNUC__) && !defined(__clang__))
37 #define LLVM_HIDDEN_VISIBILITY __attribute__ ((visibility("hidden")))
38 #else
39 // GCC on AIX does not support visibility attributes. Symbols are not
40 // exported by default on AIX.
41 #define LLVM_HIDDEN_VISIBILITY
42 #endif
3643 namespace llvm {
3744 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
3845 extern int EnableABIBreakingChecks;
39 __attribute__((weak, visibility ("hidden"))) int *VerifyEnableABIBreakingChecks = &EnableABIBreakingChecks;
46 LLVM_HIDDEN_VISIBILITY
47 __attribute__((weak)) int *VerifyEnableABIBreakingChecks =
48 &EnableABIBreakingChecks;
4049 #else
4150 extern int DisableABIBreakingChecks;
42 __attribute__((weak, visibility ("hidden"))) int *VerifyDisableABIBreakingChecks = &DisableABIBreakingChecks;
51 LLVM_HIDDEN_VISIBILITY
52 __attribute__((weak)) int *VerifyDisableABIBreakingChecks =
53 &DisableABIBreakingChecks;
4354 #endif
4455 }
56 #undef LLVM_HIDDEN_VISIBILITY
4557 #endif // _MSC_VER
4658
4759 #endif // LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING