diff options
author | Brad King <brad.king@kitware.com> | 2019-07-16 14:30:30 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-07-16 14:30:38 (GMT) |
commit | c3d9d800157a8fe2c0478d7e054544b99694c240 (patch) | |
tree | e723f303f577f058be0b5771053dbee027e6c32e | |
parent | 76a540bab5f05e4d523ce1b0480b0ee6424c676b (diff) | |
parent | c2c3d22504728e0763c3d0e88333a34d24457fb6 (diff) | |
download | CMake-c3d9d800157a8fe2c0478d7e054544b99694c240.zip CMake-c3d9d800157a8fe2c0478d7e054544b99694c240.tar.gz CMake-c3d9d800157a8fe2c0478d7e054544b99694c240.tar.bz2 |
Merge topic 'aix-explicit-exports'
c2c3d22504 Tests: Drop RunCMake workaround for AIX ld warnings about GNU atexit
9f5c2040bf AIX: Explicitly compute executable exports for both XL and GNU
0f150b69d3 AIX: Explicitly compute shared object exports for both XL and GNU
a5bf4e7921 AIX: Drop redundant -brtl flags
9cb5f040d7 XL: De-duplicate shared object creation flags
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3556
-rw-r--r-- | Modules/Compiler/XL.cmake | 2 | ||||
-rw-r--r-- | Modules/Platform/AIX-GNU.cmake | 15 | ||||
-rw-r--r-- | Modules/Platform/AIX-XL.cmake | 31 | ||||
-rwxr-xr-x | Modules/Platform/AIX/ExportImportList | 48 | ||||
-rw-r--r-- | Modules/Platform/Apple-XL-C.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Apple-XL-CXX.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Linux-XL-C.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Linux-XL-CXX.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Linux-XL-Fortran.cmake | 1 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 7 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 11 | ||||
-rw-r--r-- | Source/cmTarget.h | 3 | ||||
-rw-r--r-- | Tests/RunCMake/CMP0065/RunCMakeTest.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/RunCMake.cmake | 2 |
16 files changed, 106 insertions, 39 deletions
diff --git a/Modules/Compiler/XL.cmake b/Modules/Compiler/XL.cmake index a9cec11..fc71ab4 100644 --- a/Modules/Compiler/XL.cmake +++ b/Modules/Compiler/XL.cmake @@ -18,6 +18,8 @@ macro(__compiler_xl lang) set(CMAKE_${lang}_RESPONSE_FILE_FLAG "-qoptfile=") set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-qoptfile=") + set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-qmkshrobj") + set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,") set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",") diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake index 0abbb61..cec71a1 100644 --- a/Modules/Platform/AIX-GNU.cmake +++ b/Modules/Platform/AIX-GNU.cmake @@ -11,8 +11,6 @@ set(__AIX_COMPILER_GNU 1) # # By default, runtime linking is enabled. All shared objects specified on the command line # will be listed, even if there are no symbols referenced, in the output file. -string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " -Wl,-brtl") -string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " -Wl,-brtl") string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,-brtl") @@ -20,11 +18,22 @@ macro(__aix_compiler_gnu lang) set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-blibpath:") set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":") string(APPEND CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS " -Wl,-G,-bnoipath") - set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") + set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") # CMP0065 old behavior set(CMAKE_${lang}_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 1) set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath") if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 7 OR CMAKE_SYSTEM_VERSION VERSION_LESS 7.1) unset(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY) endif() + + # Construct the export list ourselves to pass only the object files so + # that we export only the symbols actually provided by the sources. + set(CMAKE_${lang}_CREATE_SHARED_LIBRARY + "\"${CMAKE_ROOT}/Modules/Platform/AIX/ExportImportList\" -o <OBJECT_DIR>/objects.exp <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" + ) + + set(CMAKE_${lang}_LINK_EXECUTABLE_WITH_EXPORTS + "\"${CMAKE_ROOT}/Modules/Platform/AIX/ExportImportList\" -o <OBJECT_DIR>/objects.exp <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endmacro() diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake index 06a806b..52292bd 100644 --- a/Modules/Platform/AIX-XL.cmake +++ b/Modules/Platform/AIX-XL.cmake @@ -11,8 +11,6 @@ set(__AIX_COMPILER_XL 1) # # By default, runtime linking is enabled. All shared objects specified on the command line # will be listed, even if there are no symbols referenced, in the output file. -string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " -Wl,-brtl") -string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " -Wl,-brtl") string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,-brtl") @@ -20,31 +18,20 @@ macro(__aix_compiler_xl lang) set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-blibpath:") set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-G -Wl,-bnoipath") # -shared - set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") + set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") # CMP0065 old behavior set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS " ") set(CMAKE_SHARED_MODULE_${lang}_FLAGS " ") set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath") - # Find the CreateExportList program that comes with this toolchain. - find_program(CMAKE_XL_CreateExportList - NAMES CreateExportList - DOC "IBM XL CreateExportList tool" + # Construct the export list ourselves to pass only the object files so + # that we export only the symbols actually provided by the sources. + set(CMAKE_${lang}_CREATE_SHARED_LIBRARY + "\"${CMAKE_ROOT}/Modules/Platform/AIX/ExportImportList\" -o <OBJECT_DIR>/objects.exp <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" ) - # CMAKE_XL_CreateExportList is part of the AIX XL compilers but not the linux ones. - # If we found the tool, we'll use it to create exports, otherwise stick with the regular - # create shared library compile line. - if (CMAKE_XL_CreateExportList) - # The compiler front-end passes all object files, archive files, and shared - # library files named on the command line to CreateExportList to create a - # list of all symbols to be exported from the shared library. This causes - # all archive members to be copied into the shared library whether they are - # needed or not. Instead we run the tool ourselves to pass only the object - # files so that we export only the symbols actually provided by the sources. - set(CMAKE_${lang}_CREATE_SHARED_LIBRARY - "${CMAKE_XL_CreateExportList} <OBJECT_DIR>/objects.exp <OBJECTS>" - "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" - ) - endif() + set(CMAKE_${lang}_LINK_EXECUTABLE_WITH_EXPORTS + "\"${CMAKE_ROOT}/Modules/Platform/AIX/ExportImportList\" -o <OBJECT_DIR>/objects.exp <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endmacro() diff --git a/Modules/Platform/AIX/ExportImportList b/Modules/Platform/AIX/ExportImportList new file mode 100755 index 0000000..c17378c --- /dev/null +++ b/Modules/Platform/AIX/ExportImportList @@ -0,0 +1,48 @@ +#!/bin/sh +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# This script is internal to CMake and meant only to be +# invoked by CMake-generated build systems on AIX. + +usage='usage: ExportImportList -o <out-file> [--] <objects>...' + +die() { + echo "$@" 1>&2; exit 1 +} + +# Process command-line arguments. +out='' +while test "$#" != 0; do + case "$1" in + -o) shift; out="$1" ;; + --) shift; break ;; + -*) die "$usage" ;; + *) break ;; + esac + shift +done +test -n "$out" || die "$usage" + +# Collect symbols exported from all object files. +out_tmp="$out.tmp$$" +trap 'rm -f "$out_tmp"' EXIT INT TERM +for f in "$@"; do + dump -tov -X 32_64 "$f" | + awk ' + BEGIN { + V["EXPORTED"]=" export" + V["PROTECTED"]=" protected" + } + /^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|bss) +[^ ]+ +(extern|weak) +(EXPORTED|PROTECTED| ) / { + if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) { + print $NF V[$(NF-1)] + } + } + ' +done > "$out_tmp" + +# Generate the export/import file. +{ + sort -u "$out_tmp" +} > "$out" diff --git a/Modules/Platform/Apple-XL-C.cmake b/Modules/Platform/Apple-XL-C.cmake index 2aeb132..e4fc3dd 100644 --- a/Modules/Platform/Apple-XL-C.cmake +++ b/Modules/Platform/Apple-XL-C.cmake @@ -1,4 +1,3 @@ -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-qmkshrobj") set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle") # Enable shared library versioning. diff --git a/Modules/Platform/Apple-XL-CXX.cmake b/Modules/Platform/Apple-XL-CXX.cmake index f8e1906..ea330c8 100644 --- a/Modules/Platform/Apple-XL-CXX.cmake +++ b/Modules/Platform/Apple-XL-CXX.cmake @@ -1,4 +1,3 @@ -set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-qmkshrobj") set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS "-bundle") # Enable shared library versioning. diff --git a/Modules/Platform/Linux-XL-C.cmake b/Modules/Platform/Linux-XL-C.cmake index d595e44..ef0c52b 100644 --- a/Modules/Platform/Linux-XL-C.cmake +++ b/Modules/Platform/Linux-XL-C.cmake @@ -1,2 +1 @@ -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-qmkshrobj") set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-export-dynamic") diff --git a/Modules/Platform/Linux-XL-CXX.cmake b/Modules/Platform/Linux-XL-CXX.cmake index 5ceb255..aa57d6e 100644 --- a/Modules/Platform/Linux-XL-CXX.cmake +++ b/Modules/Platform/Linux-XL-CXX.cmake @@ -1,2 +1 @@ -set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-qmkshrobj") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,-export-dynamic") diff --git a/Modules/Platform/Linux-XL-Fortran.cmake b/Modules/Platform/Linux-XL-Fortran.cmake index a878991..d9b4c2d 100644 --- a/Modules/Platform/Linux-XL-Fortran.cmake +++ b/Modules/Platform/Linux-XL-Fortran.cmake @@ -1,2 +1 @@ -set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-qmkshrobj") set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-Wl,-export-dynamic") diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index c807f6d..a2c0503 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2754,6 +2754,13 @@ std::string cmGeneratorTarget::GetCreateRuleVariable( case cmStateEnums::MODULE_LIBRARY: return "CMAKE_" + lang + "_CREATE_SHARED_MODULE"; case cmStateEnums::EXECUTABLE: + if (this->IsExecutableWithExports()) { + std::string linkExeWithExports = + "CMAKE_" + lang + "_LINK_EXECUTABLE_WITH_EXPORTS"; + if (this->Makefile->IsDefinitionSet(linkExeWithExports)) { + return linkExeWithExports; + } + } return "CMAKE_" + lang + "_LINK_EXECUTABLE"; default: break; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 0f730c9..4ffd6e0 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1515,8 +1515,10 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065( } CM_FALLTHROUGH; case cmPolicies::OLD: - // OLD behavior is to always add the flags - add_shlib_flags = true; + // OLD behavior is to always add the flags, except on AIX where + // we compute symbol exports if ENABLE_EXPORTS is on. + add_shlib_flags = + !(tgt.Target->IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS")); break; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: @@ -1525,8 +1527,10 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065( cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065)); CM_FALLTHROUGH; case cmPolicies::NEW: - // NEW behavior is to only add the flags if ENABLE_EXPORTS is on - add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS"); + // NEW behavior is to only add the flags if ENABLE_EXPORTS is on, + // except on AIX where we compute symbol exports. + add_shlib_flags = + !tgt.Target->IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS"); break; } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 773487e..9290d27 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -171,6 +171,7 @@ public: bool IsGeneratorProvided; bool HaveInstallRule; bool IsDLLPlatform; + bool IsAIX; bool IsAndroid; bool IsImportedTarget; bool ImportedGloballyVisible; @@ -219,6 +220,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, impl->IsGeneratorProvided = false; impl->HaveInstallRule = false; impl->IsDLLPlatform = false; + impl->IsAIX = false; impl->IsAndroid = false; impl->IsImportedTarget = (vis == VisibilityImported || vis == VisibilityImportedGlobally); @@ -229,6 +231,10 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, impl->IsDLLPlatform = !impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); + // Check whether we are targeting AIX. + impl->IsAIX = + (impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "AIX"); + // Check whether we are targeting an Android platform. impl->IsAndroid = (impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"); @@ -1664,6 +1670,11 @@ bool cmTarget::IsDLLPlatform() const return impl->IsDLLPlatform; } +bool cmTarget::IsAIX() const +{ + return impl->IsAIX; +} + bool cmTarget::IsImported() const { return impl->IsImportedTarget; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index d9e87b8..a808bb4 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -180,6 +180,9 @@ public: //! Return whether or not the target is for a DLL platform. bool IsDLLPlatform() const; + //! Return whether or not we are targeting AIX. + bool IsAIX() const; + bool IsImported() const; bool IsImportedGloballyVisible() const; diff --git a/Tests/RunCMake/CMP0065/RunCMakeTest.cmake b/Tests/RunCMake/CMP0065/RunCMakeTest.cmake index 254a4ec..e86b50e 100644 --- a/Tests/RunCMake/CMP0065/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMP0065/RunCMakeTest.cmake @@ -1,8 +1,11 @@ include(RunCMake) run_cmake(OLDBad1) -run_cmake(OLDBad2) -run_cmake(NEWBad) +if(NOT CMAKE_SYSTEM_NAME STREQUAL "AIX") + # Tests with ENABLE_EXPORTS ON. For AIX we do not use the flags at all. + run_cmake(OLDBad2) + run_cmake(NEWBad) +endif() run_cmake(NEWGood) run_cmake(WARN-OFF) run_cmake(WARN-ON) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 735ad5f..c952b1a 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -120,7 +120,7 @@ add_RunCMake_test(CMP0081) # CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode # generators ignore. The policy will have no effect on those generators. if(NOT CMAKE_GENERATOR MATCHES "Visual Studio|Xcode") - add_RunCMake_test(CMP0065) + add_RunCMake_test(CMP0065 -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) endif() if(CMAKE_GENERATOR MATCHES "Make") add_RunCMake_test(Make -DMAKE_IS_GNU=${MAKE_IS_GNU}) diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index e730d6e..568bdf8 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -144,8 +144,6 @@ function(run_cmake test) "|Error kstat returned" "|Hit xcodebuild bug" "|[^\n]*xcodebuild[^\n]*warning: file type[^\n]*is based on missing file type" - "|ld: 0711-224 WARNING: Duplicate symbol: .__init_aix_libgcc_cxa_atexit" - "|ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information" "|[^\n]*is a member of multiple groups" "|[^\n]*from Time Machine by path" "|[^\n]*Bullseye Testing Technology" |