Skip to content

Commit cc78bb5

Browse files
committed
[Multi-threaded IRGen] Ensure that autolink info gets into each object file
When performing multi-threaded IRGen, all of the link libraries used for autolinking went (only) into the first object file. If the object files were then placed in a static archive, the autolinking would only kick in if clients that link the static library reference something in the first object file. This causes link failures. Make sure that we put the autolink information into each of the object files we create when doing multi-threaded IRGen. Fixes the rest of rdar://162400654.
1 parent bce3fa0 commit cc78bb5

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,9 +1740,7 @@ static void performParallelIRGeneration(IRGenDescriptor desc) {
17401740

17411741
(void)layoutStringsEnabled(*IGM, /*diagnose*/ true);
17421742

1743-
// Only need to do this once.
1744-
if (!IGMcreated)
1745-
IGM->addLinkLibraries();
1743+
IGM->addLinkLibraries();
17461744
IGMcreated = true;
17471745
}
17481746

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This test checks that we produce autolink entries into the expected places
2+
// when performing multi-threaded IR generation.
3+
4+
// RUN: %empty-directory(%t/src)
5+
// RUN: split-file %s %t/src
6+
7+
// RUN: %target-swift-frontend -emit-module -o %t -module-name empty -module-link-name empty %S/../Inputs/empty.swift
8+
9+
// RUN: %target-swift-frontend -emit-ir %t/src/A.swift %t/src/B.swift -I %t -Fsystem %S/Inputs/Frameworks -o %t/A.ll -o %t/B.ll -num-threads 2 -O -g -module-name test
10+
// RUN: %FileCheck --check-prefix=CHECK-A %s <%t/A.ll
11+
// RUN: %FileCheck --check-prefix=CHECK-B %s <%t/B.ll
12+
13+
// Linux uses a different autolinking mechanism, based on
14+
// swift-autolink-extract. This file tests the Darwin mechanism.
15+
// UNSUPPORTED: autolink-extract
16+
// REQUIRES: OS=macosx
17+
18+
19+
//--- A.swift
20+
import empty
21+
22+
public func f() -> String { "hello" }
23+
24+
// CHECK-A: !llvm.linker.options = !{
25+
// CHECK-A: !{{[0-9]+}} = !{!{{"-lempty"|"/DEFAULTLIB:empty.lib"}}}
26+
27+
//--- B.swift
28+
import LinkFramework
29+
30+
public func useLibrarySym() {
31+
let _ = LinkFramework.IComeFromLinkFramework
32+
}
33+
34+
// CHECK-B: !llvm.linker.options = !{
35+
// CHECK-B: !{{[0-9]+}} = !{!"-framework", !"LinkFramework"}

0 commit comments

Comments
 (0)