llvm.org GIT mirror llvm / 690ade4
Merging r310522: ------------------------------------------------------------------------ r310522 | belleyb | 2017-08-09 13:58:39 -0700 (Wed, 09 Aug 2017) | 8 lines [Linker] PR33527 - Linker::LinkOnlyNeeded should import AppendingLinkage globals Linker::LinkOnlyNeeded should always import globals with AppendingLinkage. This resolves PR33527. Differential Revision: https://reviews.llvm.org/D34448 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@318180 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 9 months ago
11 changed file(s) with 176 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
328328 bool ModuleLinker::linkIfNeeded(GlobalValue &GV) {
329329 GlobalValue *DGV = getLinkedToGlobal(&GV);
330330
331 if (shouldLinkOnlyNeeded() && !(DGV && DGV->isDeclaration()))
332 return false;
331 if (shouldLinkOnlyNeeded()) {
332 // Always import variables with appending linkage.
333 if (!GV.hasAppendingLinkage()) {
334 // Don't import globals unless they are referenced by the destination
335 // module.
336 if (!DGV)
337 return false;
338 // Don't import globals that are already defined in the destination module
339 if (!DGV->isDeclaration())
340 return false;
341 }
342 }
333343
334344 if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) {
335345 auto *DGVar = dyn_cast(DGV);
0 @used1 = global i8 4
1 @used2 = global i32 123
2
3 @llvm.compiler.used = appending global [2 x i8*] [
4 i8* @used1,
5 i8* bitcast (i32* @used2 to i8*)
6 ], section "llvm.metadata"
0 define internal void @ctor1() {
1 call void @func1()
2 ret void
3 }
4
5 define internal void @ctor2() {
6 ret void
7 }
8
9 define void @func1() {
10 ret void
11 }
12
13 define void @unused() {
14 ret void
15 }
16
17 @llvm.global_ctors = appending global[2 x{i32, void() *, i8 * }] [
18 {i32, void() *, i8 * } { i32 2, void() *@ctor1, i8 *null},
19 {i32, void() *, i8 * } { i32 7, void() *@ctor2, i8 *null}]
0 define internal void @dtor1() {
1 call void @func1()
2 ret void
3 }
4
5 define internal void @dtor2() {
6 ret void
7 }
8
9 define void @func1() {
10 ret void
11 }
12
13 define void @unused() {
14 ret void
15 }
16
17 @llvm.global_dtors = appending global[2 x{i32, void() *, i8 * }] [
18 {i32, void() *, i8 * } { i32 2, void() *@dtor1, i8 *null},
19 {i32, void() *, i8 * } { i32 7, void() *@dtor2, i8 *null}]
0 @used1 = global i8 4
1 @used2 = global i32 123
2
3 @llvm.used = appending global [2 x i8*] [
4 i8* @used1,
5 i8* bitcast (i32* @used2 to i8*)
6 ], section "llvm.metadata"
0 ; RUN: llvm-link -S %s %p/Inputs/only-needed-compiler-used.ll | FileCheck %s --check-prefix=CHECK --check-prefix=NO-INTERNALIZE
1 ; RUN: llvm-link -S -internalize %s %p/Inputs/only-needed-compiler-used.ll | FileCheck %s --check-prefix=CHECK --check-prefix=INTERNALIZE
2 ; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-compiler-used.ll | FileCheck %s --check-prefix=CHECK --check-prefix=NO-INTERNALIZE
3 ; RUN: llvm-link -S -only-needed -internalize %s %p/Inputs/only-needed-compiler-used.ll | FileCheck %s --check-prefix=CHECK --check-prefix=INTERNALIZE
4
5 ; Empty destination module!
6
7
8 ; CHECK-DAG: @llvm.compiler.used = appending global [2 x i8*] [i8* @used1, i8* bitcast (i32* @used2 to i8*)], section "llvm.metadata"
9 ; NO-INTERNALIZE-DAG: @used1 = global i8 4
10 ; INTERNALIZE-DAG: @used1 = internal global i8 4
11 ; NO-INTERNALIZE-DAG: @used2 = global i32 123
12 ; INTERNALIZE-DAG: @used2 = internal global i32 123
0 ; RUN: llvm-link -S %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK-ALL --check-prefix=NO-INTERNALIZE
1 ; RUN: llvm-link -S -internalize %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK_ALL --check-prefix=INTERNALIZE
2 ; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=NO-INTERNALIZE
3 ; RUN: llvm-link -S -only-needed -internalize %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=INTERNALIZE
4
5 ; Empty destination module!
6
7
8 ; CHECK: @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2, void ()* @ctor1, i8* null }, { i32, void ()*, i8* } { i32 7, void ()* @ctor2, i8* null }]
9 ; CHECK: define internal void @ctor1()
10 ; CHECK: define internal void @ctor2()
11 ; NO-INTERNALIZE: define void @func1()
12 ; INTERNALIZE: define internal void @func1()
13 ; LINK-ALL: define {{(internal )?}}void @unused()
14 ; ONLY-NEEDED-NOT: void @unused()
0 ; RUN: llvm-link -S %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK-ALL --check-prefix=NO-INTERNALIZE
1 ; RUN: llvm-link -S -internalize %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK_ALL --check-prefix=INTERNALIZE
2 ; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=NO-INTERNALIZE
3 ; RUN: llvm-link -S -only-needed -internalize %s %p/Inputs/only-needed-ctors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=INTERNALIZE
4
5 ; Destination module:
6
7 define void @foo() {
8 ret void
9 }
10
11 define internal void @ctor1() {
12 ret void
13 }
14
15 @llvm.global_ctors = appending global[1 x{i32, void() *, i8 * }] [
16 {i32, void() *, i8 * } { i32 4, void() *@ctor1, i8 *null}]
17
18
19 ; CHECK: @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 4, void ()* @ctor1, i8* null }, { i32, void ()*, i8* } { i32 2, void ()* @ctor1.2, i8* null }, { i32, void ()*, i8* } { i32 7, void ()* @ctor2, i8* null }]
20 ; CHECK: define internal void @ctor1()
21 ; CHECK: define void @foo()
22 ; CHECK: define internal void @ctor1.{{[0-9]+}}()
23 ; CHECK: define internal void @ctor2()
24 ; NO-INTERNALIZE: define void @func1()
25 ; INTERNALIZE: define internal void @func1()
26 ; LINK-ALL: define {{(internal )?}}void @unused()
27 ; ONLY-NEEDED-NOT: void @unused()
0 ; RUN: llvm-link -S %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK-ALL --check-prefix=NO-INTERNALIZE
1 ; RUN: llvm-link -S -internalize %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK_ALL --check-prefix=INTERNALIZE
2 ; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=NO-INTERNALIZE
3 ; RUN: llvm-link -S -only-needed -internalize %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=INTERNALIZE
4
5 ; Empty destination module!
6
7
8 ; CHECK: @llvm.global_dtors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2, void ()* @dtor1, i8* null }, { i32, void ()*, i8* } { i32 7, void ()* @dtor2, i8* null }]
9 ; CHECK: define internal void @dtor1()
10 ; CHECK: define internal void @dtor2()
11 ; NO-INTERNALIZE: define void @func1()
12 ; INTERNALIZE: define internal void @func1()
13 ; LINK-ALL: define {{(internal )?}}void @unused()
14 ; ONLY-NEEDED-NOT: void @unused()
0 ; RUN: llvm-link -S %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK-ALL --check-prefix=NO-INTERNALIZE
1 ; RUN: llvm-link -S -internalize %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=LINK_ALL --check-prefix=INTERNALIZE
2 ; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=NO-INTERNALIZE
3 ; RUN: llvm-link -S -only-needed -internalize %s %p/Inputs/only-needed-dtors.ll | FileCheck %s --check-prefix=CHECK --check-prefix=ONLY-NEEDED --check-prefix=INTERNALIZE
4
5 ; Destination module:
6
7 define void @foo() {
8 ret void
9 }
10
11 define internal void @dtor1() {
12 ret void
13 }
14
15 @llvm.global_dtors = appending global[1 x{i32, void() *, i8 * }] [
16 {i32, void() *, i8 * } { i32 4, void() *@dtor1, i8 *null}]
17
18
19 ; CHECK: @llvm.global_dtors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 4, void ()* @dtor1, i8* null }, { i32, void ()*, i8* } { i32 2, void ()* @dtor1.2, i8* null }, { i32, void ()*, i8* } { i32 7, void ()* @dtor2, i8* null }]
20 ; CHECK: define internal void @dtor1()
21 ; CHECK: define void @foo()
22 ; CHECK: define internal void @dtor1.{{[0-9]+}}()
23 ; CHECK: define internal void @dtor2()
24 ; NO-INTERNALIZE: define void @func1()
25 ; INTERNALIZE: define internal void @func1()
26 ; LINK-ALL: define {{(internal )?}}void @unused()
27 ; ONLY-NEEDED-NOT: void @unused()
0 ; RUN: llvm-link -S %s %p/Inputs/only-needed-used.ll | FileCheck %s
1 ; RUN: llvm-link -S -internalize %s %p/Inputs/only-needed-used.ll | FileCheck %s
2 ; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-used.ll | FileCheck %s
3 ; RUN: llvm-link -S -only-needed -internalize %s %p/Inputs/only-needed-used.ll | FileCheck %s
4
5 ; Empty destination module!
6
7
8 ; CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* @used1, i8* bitcast (i32* @used2 to i8*)], section "llvm.metadata"
9 ; CHECK-DAG: @used1 = global i8 4
10 ; CHECK-DAG: @used2 = global i32 123