mirror of
https://github.com/reactos/CMake.git
synced 2024-11-23 19:49:51 +00:00
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
This commit is contained in:
parent
c3d9d80015
commit
2fa920c0cd
@ -126,6 +126,8 @@ project. There are several kinds of target files that may be installed:
|
||||
marked with the ``FRAMEWORK`` property on macOS (see ``FRAMEWORK``
|
||||
below.) For DLL platforms (all Windows-based systems including
|
||||
Cygwin), the DLL import library is treated as an ``ARCHIVE`` target.
|
||||
On AIX, the linker import file created for executables with
|
||||
:prop_tgt:`ENABLE_EXPORTS` is treated as an ``ARCHIVE`` target.
|
||||
|
||||
``LIBRARY``
|
||||
Module libraries are always treated as ``LIBRARY`` targets. For non-
|
||||
|
@ -811,6 +811,10 @@ An *archive* output artifact of a buildsystem target may be:
|
||||
executable target created by the :command:`add_executable` command
|
||||
when its :prop_tgt:`ENABLE_EXPORTS` target property is set.
|
||||
|
||||
* On AIX: the linker import file (e.g. ``.imp``) of an executable target
|
||||
created by the :command:`add_executable` command when its
|
||||
:prop_tgt:`ENABLE_EXPORTS` target property is set.
|
||||
|
||||
The :prop_tgt:`ARCHIVE_OUTPUT_DIRECTORY` and :prop_tgt:`ARCHIVE_OUTPUT_NAME`
|
||||
target properties may be used to control archive output artifact locations
|
||||
and names in the build tree.
|
||||
|
@ -19,6 +19,10 @@ varies by platform:
|
||||
* On macOS, loadable modules link to the executable itself using the
|
||||
``-bundle_loader`` flag.
|
||||
|
||||
* On AIX, a linker "import file" is created along with the executable
|
||||
to list the exported symbols for import when linking other targets.
|
||||
Loadable modules link to the import file to get the symbols.
|
||||
|
||||
* On other platforms, loadable modules are simply linked without
|
||||
referencing the executable since the dynamic loader will
|
||||
automatically bind symbols when the module is loaded.
|
||||
|
@ -3,5 +3,7 @@ IMPORTED_IMPLIB
|
||||
|
||||
Full path to the import library for an ``IMPORTED`` target.
|
||||
|
||||
Set this to the location of the ``.lib`` part of a Windows DLL. Ignored
|
||||
for non-imported targets.
|
||||
Set this to the location of the ``.lib`` part of a Windows DLL, or on
|
||||
AIX set it to an import file created for executables that export symbols
|
||||
(see the :prop_tgt:`ENABLE_EXPORTS` target property).
|
||||
Ignored for non-imported targets.
|
||||
|
10
Help/release/dev/aix.rst
Normal file
10
Help/release/dev/aix.rst
Normal file
@ -0,0 +1,10 @@
|
||||
aix
|
||||
---
|
||||
|
||||
* On AIX, executables using the :prop_tgt:`ENABLE_EXPORTS` target property
|
||||
now produce a linker import file with a ``.imp`` extension in addition
|
||||
to the executable file. Plugins (created via :command:`add_library` with
|
||||
the ``MODULE`` option) that use :command:`target_link_libraries` to link
|
||||
to the executable for its symbols are now linked using the import file.
|
||||
The :command:`install(TARGETS)` command now installs the import file as
|
||||
an ``ARCHIVE`` artifact.
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -616,6 +616,15 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
|
||||
|
||||
// Pass the full path to the target file.
|
||||
std::string lib = tgt->GetFullPath(config, artifact, true);
|
||||
if (tgt->Target->IsAIX() && cmHasLiteralSuffix(lib, "-NOTFOUND") &&
|
||||
artifact == cmStateEnums::ImportLibraryArtifact) {
|
||||
// This is an imported executable on AIX that has ENABLE_EXPORTS
|
||||
// but not IMPORTED_IMPLIB. CMake used to produce and accept such
|
||||
// imported executables on AIX before we taught it to use linker
|
||||
// import files. For compatibility, simply skip linking to this
|
||||
// executable as we did before. It works with runtime linking.
|
||||
return;
|
||||
}
|
||||
if (!this->LinkDependsNoShared ||
|
||||
tgt->GetType() != cmStateEnums::SHARED_LIBRARY) {
|
||||
this->Depends.push_back(lib);
|
||||
|
@ -6363,7 +6363,8 @@ bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
|
||||
this->IsExecutableWithExports()) &&
|
||||
// Assemblies which have only managed code do not have
|
||||
// import libraries.
|
||||
this->GetManagedType(config) != ManagedType::Managed);
|
||||
this->GetManagedType(config) != ManagedType::Managed) ||
|
||||
(this->Target->IsAIX() && this->IsExecutableWithExports());
|
||||
}
|
||||
|
||||
bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const
|
||||
|
@ -637,7 +637,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||
// On DLL platforms an executable may also have an import
|
||||
// library. Install it to the archive destination if it
|
||||
// exists.
|
||||
if (target.IsDLLPlatform() && !archiveArgs.GetDestination().empty() &&
|
||||
if ((target.IsDLLPlatform() || target.IsAIX()) &&
|
||||
!archiveArgs.GetDestination().empty() &&
|
||||
target.IsExecutableWithExports()) {
|
||||
// The import library uses the ARCHIVE properties.
|
||||
archiveGenerator = CreateInstallTargetGenerator(
|
||||
|
@ -1716,7 +1716,8 @@ const char* cmTarget::GetSuffixVariableInternal(
|
||||
? "CMAKE_SHARED_LIBRARY_SUFFIX"
|
||||
: "CMAKE_EXECUTABLE_SUFFIX");
|
||||
case cmStateEnums::ImportLibraryArtifact:
|
||||
return "CMAKE_IMPORT_LIBRARY_SUFFIX";
|
||||
return (impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX"
|
||||
: "CMAKE_IMPORT_LIBRARY_SUFFIX");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1756,7 +1757,8 @@ const char* cmTarget::GetPrefixVariableInternal(
|
||||
? "CMAKE_SHARED_LIBRARY_PREFIX"
|
||||
: "");
|
||||
case cmStateEnums::ImportLibraryArtifact:
|
||||
return "CMAKE_IMPORT_LIBRARY_PREFIX";
|
||||
return (impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX"
|
||||
: "CMAKE_IMPORT_LIBRARY_PREFIX");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1892,7 +1894,8 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
|
||||
// library or an executable with exports.
|
||||
bool allowImp = (this->IsDLLPlatform() &&
|
||||
(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
|
||||
this->IsExecutableWithExports()));
|
||||
this->IsExecutableWithExports())) ||
|
||||
(this->IsAIX() && this->IsExecutableWithExports());
|
||||
|
||||
// If a mapping was found, check its configurations.
|
||||
for (std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
|
||||
|
@ -978,6 +978,11 @@ def gen_check_targets(c, g, inSource):
|
||||
"path": "^bin/((Debug|Release|RelWithDebInfo|MinSizeRel)/)?my_interface_exe\\.myexe$",
|
||||
"_dllExtra": False,
|
||||
},
|
||||
{
|
||||
"path": "^lib/my_interface_exe\\.imp$",
|
||||
"_aixExtra": True,
|
||||
"_dllExtra": False,
|
||||
},
|
||||
{
|
||||
"path": "^lib/((Debug|Release|RelWithDebInfo|MinSizeRel)/)?(lib)?my_interface_exe\\.(dll\\.a|lib)$",
|
||||
"_dllExtra": True,
|
||||
@ -4895,6 +4900,10 @@ def gen_check_targets(c, g, inSource):
|
||||
for e in expected:
|
||||
e["artifacts"] = filter_list(lambda a: not a["_dllExtra"], e["artifacts"])
|
||||
|
||||
if "aix" not in sys.platform:
|
||||
for e in expected:
|
||||
e["artifacts"] = filter_list(lambda a: not a.get("_aixExtra", False), e["artifacts"])
|
||||
|
||||
return expected
|
||||
|
||||
def check_targets(c, g, inSource):
|
||||
|
@ -38,7 +38,7 @@ set_property (TARGET static2 PROPERTY IMPORT_PREFIX static2_import_prefix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_PREFIX executable custom\" \"$<TARGET_FILE_PREFIX:exec2>\" \"exec2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_prefix,exec2_prefix>\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms};AIX>,exec2_import_prefix,exec2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX shared custom\" \"$<TARGET_FILE_PREFIX:shared2>\" \"shared2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_prefix,shared2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX static custom\" \"$<TARGET_FILE_PREFIX:static2>\" \"static2_prefix\")
|
||||
|
@ -38,7 +38,7 @@ set_property (TARGET static2 PROPERTY IMPORT_PREFIX static2_import_prefix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_PREFIX executable custom\" \"$<TARGET_FILE_PREFIX:exec2>\" \"exec2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_prefix,exec2_prefix>\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms};AIX>,exec2_import_prefix,exec2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX shared custom\" \"$<TARGET_FILE_PREFIX:shared2>\" \"shared2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_prefix,shared2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX static custom\" \"$<TARGET_FILE_PREFIX:static2>\" \"static2_prefix\")
|
||||
|
@ -38,7 +38,7 @@ set_property (TARGET static2 PROPERTY IMPORT_SUFFIX static2_import_suffix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_SUFFIX executable custom\" \"$<TARGET_FILE_SUFFIX:exec2>\" \"exec2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX executable linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_suffix,exec2_suffix>\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX executable linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms};AIX>,exec2_import_suffix,exec2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX shared custom\" \"$<TARGET_FILE_SUFFIX:shared2>\" \"shared2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX shared linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_suffix,shared2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX static custom\" \"$<TARGET_FILE_SUFFIX:static2>\" \"static2_suffix\")
|
||||
|
@ -38,7 +38,7 @@ set_property (TARGET static2 PROPERTY IMPORT_SUFFIX static2_import_suffix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_SUFFIX executable custom\" \"$<TARGET_FILE_SUFFIX:exec2>\" \"exec2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX executable linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_suffix,exec2_suffix>\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX executable linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms};AIX>,exec2_import_suffix,exec2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX shared custom\" \"$<TARGET_FILE_SUFFIX:shared2>\" \"shared2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX shared linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_suffix,shared2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX static custom\" \"$<TARGET_FILE_SUFFIX:static2>\" \"static2_suffix\")
|
||||
|
Loading…
Reference in New Issue
Block a user