llvm.org GIT mirror llvm / d7bb2de
Fix logic for which symbols to keep with comdats. If a comdat is dropped, all symbols in it are dropped. If a comdat is kept, the symbols survive to pass regular symbol resolution. With this patch we do that for all global symbols. The added test is a copy of test/tools/gold/X86/comdat.ll that we now pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264192 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
4 changed file(s) with 97 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
421421 bool LinkFromSrc;
422422 Comdat::SelectionKind SK;
423423 std::tie(SK, LinkFromSrc) = ComdatsChosen[SC];
424 if (LinkFromSrc)
425 ValuesToLink.insert(&GV);
426 return false;
424 if (!LinkFromSrc)
425 return false;
427426 }
428427
429428 bool LinkFromSrc = true;
564563 if (!SC)
565564 continue;
566565 for (GlobalValue *GV2 : ComdatMembers[SC])
567 ValuesToLink.insert(GV2);
566 if (GV2->hasInternalLinkage())
567 ValuesToLink.insert(GV2);
568568 }
569569
570570 if (shouldInternalizeLinkedSymbols()) {
0 $c2 = comdat any
1 $c1 = comdat any
2
3 ; This is only present in this file. The linker will keep $c1 from the first
4 ; file and this will be undefined.
5 @will_be_undefined = global i32 1, comdat($c1)
6 @use = global i32* @will_be_undefined
7
8 @v1 = weak_odr global i32 41, comdat($c2)
9 define weak_odr protected i32 @f1(i8* %this) comdat($c2) {
10 bb20:
11 store i8* %this, i8** null
12 br label %bb21
13 bb21:
14 ret i32 41
15 }
16
17 @r21 = global i32* @v1
18 @r22 = global i32(i8*)* @f1
19
20 @a21 = alias i32, i32* @v1
21 @a22 = alias i16, bitcast (i32* @v1 to i16*)
22
23 @a23 = alias i32(i8*), i32(i8*)* @f1
24 @a24 = alias i16, bitcast (i32(i8*)* @f1 to i16*)
25 @a25 = alias i16, i16* @a24
0 ; RUN: llvm-link -S -o - %s %p/Inputs/comdat16.ll | FileCheck %s
1
2 $c1 = comdat any
3
4 @v1 = weak_odr global i32 42, comdat($c1)
5 define weak_odr i32 @f1(i8*) comdat($c1) {
6 bb10:
7 br label %bb11
8 bb11:
9 ret i32 42
10 }
11
12 @r11 = global i32* @v1
13 @r12 = global i32 (i8*)* @f1
14
15 @a11 = alias i32, i32* @v1
16 @a12 = alias i16, bitcast (i32* @v1 to i16*)
17
18 @a13 = alias i32 (i8*), i32 (i8*)* @f1
19 @a14 = alias i16, bitcast (i32 (i8*)* @f1 to i16*)
20 @a15 = alias i16, i16* @a14
21
22 ; CHECK: $c1 = comdat any
23 ; CHECK: $c2 = comdat any
24
25 ; CHECK-DAG: @will_be_undefined = external global i32
26
27 ; CHECK-DAG: @v1 = weak_odr global i32 42, comdat($c1)
28
29 ; CHECK-DAG: @r11 = global i32* @v1{{$}}
30 ; CHECK-DAG: @r12 = global i32 (i8*)* @f1{{$}}
31
32 ; CHECK-DAG: @r21 = global i32* @v1{{$}}
33 ; CHECK-DAG: @r22 = global i32 (i8*)* @f1{{$}}
34
35 ; CHECK-DAG: @v1.1 = internal global i32 41, comdat($c2)
36
37 ; CHECK-DAG: @a11 = alias i32, i32* @v1{{$}}
38 ; CHECK-DAG: @a12 = alias i16, bitcast (i32* @v1 to i16*)
39
40 ; CHECK-DAG: @a13 = alias i32 (i8*), i32 (i8*)* @f1{{$}}
41 ; CHECK-DAG: @a14 = alias i16, bitcast (i32 (i8*)* @f1 to i16*)
42
43 ; CHECK-DAG: @a21 = alias i32, i32* @v1.1{{$}}
44 ; CHECK-DAG: @a22 = alias i16, bitcast (i32* @v1.1 to i16*)
45
46 ; CHECK-DAG: @a23 = alias i32 (i8*), i32 (i8*)* @f1.2{{$}}
47 ; CHECK-DAG: @a24 = alias i16, bitcast (i32 (i8*)* @f1.2 to i16*)
48
49 ; CHECK: define weak_odr protected i32 @f1(i8*) comdat($c1) {
50 ; CHECK-NEXT: bb10:
51 ; CHECK-NEXT: br label %bb11{{$}}
52 ; CHECK: bb11:
53 ; CHECK-NEXT: ret i32 42
54 ; CHECK-NEXT: }
55
56 ; CHECK: define internal i32 @f1.2(i8* %this) comdat($c2) {
57 ; CHECK-NEXT: bb20:
58 ; CHECK-NEXT: store i8* %this, i8** null
59 ; CHECK-NEXT: br label %bb21
60 ; CHECK: bb21:
61 ; CHECK-NEXT: ret i32 41
62 ; CHECK-NEXT: }
0 ; RUN: llvm-link %s %p/Inputs/constructor-comdat.ll -S -o - 2>&1 | FileCheck %s
1 ; RUN: llvm-link %p/Inputs/constructor-comdat.ll %s -S -o - 2>&1 | FileCheck %s
1 ; RUN: llvm-link %p/Inputs/constructor-comdat.ll %s -S -o - 2>&1 | FileCheck --check-prefix=NOCOMDAT %s
22
33 $_ZN3fooIiEC5Ev = comdat any
44 ; CHECK: $_ZN3fooIiEC5Ev = comdat any
5 ; NOCOMDAT-NOT: comdat
56
67 @_ZN3fooIiEC1Ev = weak_odr alias void (), void ()* @_ZN3fooIiEC2Ev
78 ; CHECK: @_ZN3fooIiEC1Ev = weak_odr alias void (), void ()* @_ZN3fooIiEC2Ev
9 ; NOCOMDAT-DAG: define weak_odr void @_ZN3fooIiEC1Ev() {
810
911 ; CHECK: define weak_odr void @_ZN3fooIiEC2Ev() comdat($_ZN3fooIiEC5Ev) {
12 ; NOCOMDAT-DAG: define weak_odr void @_ZN3fooIiEC2Ev() {
1013 define weak_odr void @_ZN3fooIiEC2Ev() comdat($_ZN3fooIiEC5Ev) {
1114 ret void
1215 }