Link to transitive dependencies on stub libraries only on some linkers

Only linkers that enforce `--no-allow-shlib-undefined` recursively need
to link private transitive dependencies on stub libraries explicitly.
This commit is contained in:
Brad King
2023-12-11 20:06:16 -05:00
parent dd4a6dff92
commit 2c6ec6de15
3 changed files with 19 additions and 1 deletions

View File

@@ -1340,7 +1340,8 @@ void cmComputeLinkInformation::AddSharedDepItem(LinkEntry const& entry)
// If the linker also uses '--as-needed' behavior, this will not
// add an unnecessary direct dependency.
(tgt && tgt->IsImported() &&
!tgt->HasKnownRuntimeArtifactLocation(this->Config))) {
!tgt->HasKnownRuntimeArtifactLocation(this->Config) &&
this->Target->LinkerEnforcesNoAllowShLibUndefined(this->Config))) {
this->AddItem(entry);
return;
}

View File

@@ -5596,6 +5596,20 @@ std::string cmGeneratorTarget::GetLinkerTool(const std::string& lang,
return linkerTool;
}
bool cmGeneratorTarget::LinkerEnforcesNoAllowShLibUndefined(
std::string const& config) const
{
// FIXME(#25486): Account for the LINKER_TYPE target property.
// Also factor out the hard-coded list below into a platform
// information table based on the linker id.
std::string ll = this->GetLinkerLanguage(config);
std::string linkerIdVar = cmStrCat("CMAKE_", ll, "_COMPILER_LINKER_ID");
cmValue linkerId = this->Makefile->GetDefinition(linkerIdVar);
// The GNU bfd-based linker may enforce '--no-allow-shlib-undefined'
// recursively by default. The Solaris linker has similar behavior.
return linkerId && (*linkerId == "GNU" || *linkerId == "Solaris");
}
std::string cmGeneratorTarget::GetPDBOutputName(
const std::string& config) const
{

View File

@@ -805,6 +805,9 @@ public:
std::string GetLinkerTool(const std::string& lang,
const std::string& config) const;
/** Is the linker known to enforce '--no-allow-shlib-undefined'? */
bool LinkerEnforcesNoAllowShLibUndefined(std::string const& config) const;
/** Does this target have a GNU implib to convert to MS format? */
bool HasImplibGNUtoMS(std::string const& config) const;