Fine-grained autolinking control

This change adds the following options to allow for greater control over the compiler's autolinking directive use:
- '-disable-autolink-library': equivalent to an existing '-disable-autolink-framework', this option takes a library name as input and ensures the compiler does not produce an autolink directive '-l<library-name>'.
- '-disable-autolink-frameworks': a boolean disable flag which turns off insertion of autolinking directives for all imported frameworks (of the type '-framework <framework-name>')
- '-disable-all-autolinking': a boolean disable flag which turns off insertion of *any* autolinking directives.

Resolves rdar://100859983
This commit is contained in:
Artem Chikin
2023-10-05 15:12:48 -07:00
parent 90506909d3
commit 57e4f244d1
7 changed files with 116 additions and 15 deletions

View File

@@ -1466,21 +1466,30 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
if (Context.LangOpts.hasFeature(Feature::Embedded))
return;
switch (linkLib.getKind()) {
case LibraryKind::Library: {
AutolinkEntries.emplace_back(linkLib);
break;
}
case LibraryKind::Framework: {
// If we're supposed to disable autolinking of this framework, bail out.
auto &frameworks = IRGen.Opts.DisableAutolinkFrameworks;
if (std::find(frameworks.begin(), frameworks.end(), linkLib.getName())
!= frameworks.end())
return;
AutolinkEntries.emplace_back(linkLib);
break;
}
// '-disable-autolinking' means we will not auto-link
// any loaded library at all.
if (!IRGen.Opts.DisableAllAutolinking) {
switch (linkLib.getKind()) {
case LibraryKind::Library: {
auto &libraries = IRGen.Opts.DisableAutolinkLibraries;
if (llvm::find(libraries, linkLib.getName()) != libraries.end())
return;
AutolinkEntries.emplace_back(linkLib);
break;
}
case LibraryKind::Framework: {
// 'disable-autolink-frameworks' means we will not auto-link
// any loaded framework.
if (!IRGen.Opts.DisableFrameworkAutolinking) {
auto &frameworks = IRGen.Opts.DisableAutolinkFrameworks;
if (llvm::find(frameworks, linkLib.getName()) != frameworks.end())
return;
AutolinkEntries.emplace_back(linkLib);
}
break;
}
}
}
if (linkLib.shouldForceLoad()) {