Skip to content

Commit 1d666d1

Browse files
committed
Merge pull request #2897 from compnerd/autolink-coff
Native autolinking on COFF
2 parents a30c4cd + 7837db4 commit 1d666d1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ void IRGenModule::emitAutolinkInfo() {
874874
AutolinkEntries.end());
875875

876876
switch (TargetInfo.OutputObjectFormat) {
877+
case llvm::Triple::UnknownObjectFormat:
878+
llvm_unreachable("unknown object format");
879+
case llvm::Triple::COFF:
877880
case llvm::Triple::MachO: {
878881
llvm::LLVMContext &ctx = Module.getContext();
879882

@@ -892,7 +895,6 @@ void IRGenModule::emitAutolinkInfo() {
892895
}
893896
break;
894897
}
895-
case llvm::Triple::COFF:
896898
case llvm::Triple::ELF: {
897899
// Merge the entries into null-separated string.
898900
llvm::SmallString<64> EntriesString;
@@ -918,9 +920,6 @@ void IRGenModule::emitAutolinkInfo() {
918920
addUsedGlobal(var);
919921
break;
920922
}
921-
default:
922-
llvm_unreachable("Don't know how to emit autolink entries for "
923-
"the selected object format.");
924923
}
925924

926925
if (!IRGen.Opts.ForceLoadSymbolName.empty()) {

test/IRGen/autolink-coff.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: %swift -target thumbv7--windows-gnu -parse-as-library -parse-stdlib -emit-module-path %t/module.swiftmodule -module-name module -module-link-name module %s
4+
// RUN: %swift -target thumbv7--windows-gnu -parse-as-library -parse-stdlib -module-name autolink -I %t -D MAIN_MODULE -emit-ir -o - %s | FileCheck %s -check-prefix CHECK-GNU-IR
5+
// RUN: %swift -target thumbv7--windows-gnu -parse-as-library -parse-stdlib -module-name autolink -I %t -D MAIN_MODULE -S -o - %s | FileCheck %s -check-prefix CHECK-GNU-ASM
6+
7+
#if MAIN_MODULE
8+
import module
9+
#endif
10+
11+
// CHECK-GNU-IR: !{{[0-9]+}} = !{i32 {{[0-9]+}}, !"Linker Options", [[NODE:![0-9]+]]}
12+
// CHECK-GNU-IR: [[NODE]] = !{[[LIST:![0-9]+]]}
13+
// CHECK-GNU-IR: [[LIST]] = !{!"-lmodule"}
14+
15+
// CHECK-GNU-ASM: .section .drectve
16+
// CHECK-GNU-ASM: .ascii " -lmodule"
17+

0 commit comments

Comments
 (0)