diff options
author | Brad King <brad.king@kitware.com> | 2019-07-16 14:32:25 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-07-16 18:15:13 (GMT) |
commit | 2fa920c0cd5c186d0991c9636c9af6691ead8dce (patch) | |
tree | 5faa5a673b51c4dfd20dbf29accb53b259f30d25 /Modules/Platform | |
parent | c3d9d800157a8fe2c0478d7e054544b99694c240 (diff) | |
download | CMake-2fa920c0cd5c186d0991c9636c9af6691ead8dce.zip CMake-2fa920c0cd5c186d0991c9636c9af6691ead8dce.tar.gz CMake-2fa920c0cd5c186d0991c9636c9af6691ead8dce.tar.bz2 |
AIX: Create import library for executables with exports
On AIX, plugins meant to be loaded into executables via `dlopen` must be
linked with access to a list of symbols exported from the executable in
order to use them (when not using runtime linking). The AIX linker
supports specifying this list as an "import file" passed on the command
line either via the `-bI:...` option or (with a leading `#! .` line) as
a normal input file like any other library file.
The linker import file plays the same role on AIX as import libraries do
on Windows. Teach CMake to enable its import library abstraction on AIX
for executables with the `ENABLE_EXPORTS` target property set. Teach
our internal `ExportImportList` script to optionally generate a leading
`#! .` line at the top of the generated export/import list. Update our
rule for linking an executable with exports to generate a public-facing
"import library" implemented as an AIX linker import file.
With this approach, our existing infrastructure for handling import
libraries on Windows will now work for AIX linker import files too:
* Plugins that link to their executable's symbols will be automatically
linked using the import file on the command line.
* The executable's import file will be (optionally) installed and
exported for use in linking externally-built plugins.
This will allow executables and their plugins to build even if we later
turn off runtime linking.
Issue: #19163
Diffstat (limited to 'Modules/Platform')
-rw-r--r-- | Modules/Platform/AIX-GNU.cmake | 4 | ||||
-rw-r--r-- | Modules/Platform/AIX-XL.cmake | 4 | ||||
-rw-r--r-- | Modules/Platform/AIX.cmake | 2 | ||||
-rwxr-xr-x | Modules/Platform/AIX/ExportImportList | 7 |
4 files changed, 12 insertions, 5 deletions
diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake index cec71a1..9e981c6 100644 --- a/Modules/Platform/AIX-GNU.cmake +++ b/Modules/Platform/AIX-GNU.cmake @@ -34,6 +34,6 @@ macro(__aix_compiler_gnu lang) ) 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>") + "\"${CMAKE_ROOT}/Modules/Platform/AIX/ExportImportList\" -o <TARGET_IMPLIB> -l . <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> -Wl,-bE:<TARGET_IMPLIB> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endmacro() diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake index 52292bd..3424e2c 100644 --- a/Modules/Platform/AIX-XL.cmake +++ b/Modules/Platform/AIX-XL.cmake @@ -32,6 +32,6 @@ macro(__aix_compiler_xl lang) ) 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>") + "\"${CMAKE_ROOT}/Modules/Platform/AIX/ExportImportList\" -o <TARGET_IMPLIB> -l . <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> -Wl,-bE:<TARGET_IMPLIB> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endmacro() diff --git a/Modules/Platform/AIX.cmake b/Modules/Platform/AIX.cmake index 551a995..03cef51 100644 --- a/Modules/Platform/AIX.cmake +++ b/Modules/Platform/AIX.cmake @@ -1,5 +1,7 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so +set(CMAKE_AIX_IMPORT_FILE_PREFIX "") +set(CMAKE_AIX_IMPORT_FILE_SUFFIX ".imp") set(CMAKE_DL_LIBS "-lld") # RPATH support on AIX is called libpath. By default the runtime diff --git a/Modules/Platform/AIX/ExportImportList b/Modules/Platform/AIX/ExportImportList index c17378c..4f67ef5 100755 --- a/Modules/Platform/AIX/ExportImportList +++ b/Modules/Platform/AIX/ExportImportList @@ -5,7 +5,7 @@ # 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>...' +usage='usage: ExportImportList -o <out-file> [-l <lib>] [--] <objects>...' die() { echo "$@" 1>&2; exit 1 @@ -13,8 +13,10 @@ die() { # Process command-line arguments. out='' +lib='' while test "$#" != 0; do case "$1" in + -l) shift; lib="$1" ;; -o) shift; out="$1" ;; --) shift; break ;; -*) die "$usage" ;; @@ -44,5 +46,8 @@ done > "$out_tmp" # Generate the export/import file. { + if test -n "$lib"; then + echo "#! $lib" + fi sort -u "$out_tmp" } > "$out" |