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 @@ -196,6 +196,12 @@ # 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) + # The default behaviour on AIX processes dynamic initialization of non-local variables with + # static storage duration even for archive members that are otherwise unreferenced. + # Since `--whole-archive` is not used by the LLVM build to keep such initializations for Linux, + # we can limit the processing for archive members to only those that are otherwise referenced. + append("-bcdtors:mbr" + CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) endif() endif()