Skip to content

[swift][AutoLinkExtract] Don't add autolink hint for frameworks (take 2) #65235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,14 @@ llvm::SmallString<32> getTargetDependentLibraryOption(const llvm::Triple &T,
return buffer;
}

static llvm::Optional<StringRef>
getTargetDependentFrameworkOption(const llvm::Triple &T) {
if (T.isOSDarwin())
return StringRef("-framework");

return std::nullopt;
}

void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
// The debugger gets the autolink information directly from
// the LinkLibraries of the module, so there's no reason to
Expand Down Expand Up @@ -1575,7 +1583,8 @@ void AutolinkKind::collectEntriesFromLibraries(
llvm::LLVMContext &ctx = IGM.getLLVMContext();

switch (Value) {
case AutolinkKind::LLVMLinkerOptions: {
case AutolinkKind::LLVMLinkerOptions:
case AutolinkKind::SwiftAutoLinkExtract: {
// On platforms that support autolinking, continue to use the metadata.
for (LinkLibrary linkLib : AutolinkEntries) {
switch (linkLib.getKind()) {
Expand All @@ -1586,7 +1595,13 @@ void AutolinkKind::collectEntriesFromLibraries(
continue;
}
case LibraryKind::Framework: {
llvm::Metadata *args[] = {llvm::MDString::get(ctx, "-framework"),
// Skip the framework if the platform's linker doesn't support linking
// frameworks.
llvm::Optional<StringRef> opt =
getTargetDependentFrameworkOption(IGM.Triple);
if (!opt)
continue;
llvm::Metadata *args[] = {llvm::MDString::get(ctx, *opt),
llvm::MDString::get(ctx, linkLib.getName())};
Entries.insert(llvm::MDNode::get(ctx, args));
continue;
Expand All @@ -1596,24 +1611,6 @@ void AutolinkKind::collectEntriesFromLibraries(
}
return;
}
case AutolinkKind::SwiftAutoLinkExtract: {
// On platforms that support autolinking, continue to use the metadata.
for (LinkLibrary linkLib : AutolinkEntries) {
switch (linkLib.getKind()) {
case LibraryKind::Library: {
llvm::SmallString<32> opt =
getTargetDependentLibraryOption(IGM.Triple, linkLib.getName());
Entries.insert(llvm::MDNode::get(ctx, llvm::MDString::get(ctx, opt)));
continue;
}
case LibraryKind::Framework:
// Frameworks are not supported with Swift Autolink Extract.
continue;
}
llvm_unreachable("Unhandled LibraryKind in switch.");
}
return;
}
case AutolinkKind::LLVMDependentLibraries: {
for (LinkLibrary linkLib : AutolinkEntries) {
switch (linkLib.getKind()) {
Expand Down