Skip to content

Commit 17c5010

Browse files
authored
[swift][AutoLinkExtract] Don't add autolink hint for frameworks. (#65051)
Default system linkers on non-Darwin platforms do not support the `-framework` argument for framework linking. This change updates autolinking to not emit `-framework` into the .o _swift1_autolink_entries metadata when there is no native linker support. This is related to rdar://106578342.
1 parent 539fc69 commit 17c5010

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,7 @@ void AutolinkKind::collectEntriesFromLibraries(
15751575
llvm::LLVMContext &ctx = IGM.getLLVMContext();
15761576

15771577
switch (Value) {
1578-
case AutolinkKind::LLVMLinkerOptions:
1579-
case AutolinkKind::SwiftAutoLinkExtract: {
1578+
case AutolinkKind::LLVMLinkerOptions: {
15801579
// On platforms that support autolinking, continue to use the metadata.
15811580
for (LinkLibrary linkLib : AutolinkEntries) {
15821581
switch (linkLib.getKind()) {
@@ -1597,6 +1596,24 @@ void AutolinkKind::collectEntriesFromLibraries(
15971596
}
15981597
return;
15991598
}
1599+
case AutolinkKind::SwiftAutoLinkExtract: {
1600+
// On platforms that support autolinking, continue to use the metadata.
1601+
for (LinkLibrary linkLib : AutolinkEntries) {
1602+
switch (linkLib.getKind()) {
1603+
case LibraryKind::Library: {
1604+
llvm::SmallString<32> opt =
1605+
getTargetDependentLibraryOption(IGM.Triple, linkLib.getName());
1606+
Entries.insert(llvm::MDNode::get(ctx, llvm::MDString::get(ctx, opt)));
1607+
continue;
1608+
}
1609+
case LibraryKind::Framework:
1610+
// Frameworks are not supported with Swift Autolink Extract.
1611+
continue;
1612+
}
1613+
llvm_unreachable("Unhandled LibraryKind in switch.");
1614+
}
1615+
return;
1616+
}
16001617
case AutolinkKind::LLVMDependentLibraries: {
16011618
for (LinkLibrary linkLib : AutolinkEntries) {
16021619
switch (linkLib.getKind()) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern int APIFromLinkFramework;

test/AutolinkExtract/Inputs/Frameworks/Link.framework/Link

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module Link {
2+
umbrella header "Link.h"
3+
export *
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swiftc_driver -c %s -F %S/Inputs/Frameworks -o %t/import_framework.o
3+
// RUN: %target-swift-autolink-extract %t/import_framework.o -o - | %FileCheck --check-prefix CHECK-%target-object-format %s
4+
5+
// REQUIRES: autolink-extract
6+
7+
// CHECK-elf-NOT: Link
8+
// CHECK-coff-NOT: Link
9+
10+
import Link
11+
_ = Link.APIFromLinkFramework

0 commit comments

Comments
 (0)