2
2
# RUN: rm -rf %t && split-file %s %t && cd %t
3
3
4
4
#--- trivial-relocation.s
5
- # For trivial relocations, merging two equivalent sections is allowed but we must not
6
- # merge their symbols if addends are different.
5
+ # Tests following for trivial relocations:
6
+ # 1. Merging two equivalent sections is allowed but we must not merge their symbols if addends are different.
7
+ # 2. Local symbols should not be merged together even though their sections can be merged together.
7
8
8
9
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux trivial-relocation.s -o trivial.o
9
- # RUN: ld.lld trivial.o -o /dev/null --icf=all --print-icf-sections | FileCheck %s
10
+ # RUN: ld.lld trivial.o -o /dev/null --icf=all --print-icf-sections | FileCheck %s --check-prefix=TRIVIAL
10
11
11
- # CHECK: selected section {{.*}}:(.text.f1)
12
- # CHECK: removing identical section {{.*}}:(.text.f2)
13
- # CHECK-NOT: redirecting 'y' in symtab to x
14
- # CHECK-NOT: redirecting 'y' to 'x'
12
+ # TRIVIAL: selected section {{.*}}:(.rodata.sec1)
13
+ # TRIVIAL-NEXT: removing identical section {{.*}}:(.rodata.sec2)
14
+ # TRIVIAL-NEXT: selected section {{.*}}:(.text.f1)
15
+ # TRIVIAL-NEXT: removing identical section {{.*}}:(.text.f2)
16
+ # TRIVIAL-NEXT: removing identical section {{.*}}:(.text.f1_local)
17
+ # TRIVIAL-NEXT: removing identical section {{.*}}:(.text.f2_local)
15
18
16
- .globl x, y
19
+ .addrsig
17
20
18
- .section .rodata,"a" ,@progbits
21
+ .globl x_glob, y_glob
22
+
23
+ .section .rodata.sec1,"a" ,@progbits
24
+ x_glob:
25
+ .long 11
26
+ y_glob:
27
+ .long 12
28
+
29
+ .section .rodata.sec2,"a" ,@progbits
19
30
x:
20
31
.long 11
21
32
y:
22
33
.long 12
23
34
24
35
.section .text .f1,"ax" ,@progbits
25
36
f1:
26
- movq x +4 (%rip ), %rax
37
+ movq x_glob +4 (%rip ), %rax
27
38
28
39
.section .text .f2,"ax" ,@progbits
29
40
f2:
41
+ movq y_glob(%rip ), %rax
42
+
43
+ .section .text .f1_local,"ax" ,@progbits
44
+ f1_local:
45
+ movq x+4 (%rip ), %rax
46
+
47
+ .section .text .f2_local,"ax" ,@progbits
48
+ f2_local:
30
49
movq y(%rip ), %rax
31
50
32
51
.section .text ._start,"ax" ,@progbits
@@ -36,34 +55,52 @@ call f1
36
55
call f2
37
56
38
57
#--- non-trivial-relocation.s
39
- # For non-trivial relocations, we must not merge sections if addends are different.
40
- # Not merging sections would automatically disable symbol merging.
58
+ # Tests following for non-trivial relocations:
59
+ # 1. We must not merge sections if addends are different.
60
+ # 2. We must not merge sections pointing to local and global symbols.
41
61
42
- # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux trivial-relocation.s -o trivial.o
43
- # RUN: ld.lld trivial.o -o /dev/null --icf=all --print-icf-sections | FileCheck %s
62
+ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux non-trivial-relocation.s -o non-trivial.o
63
+ # RUN: ld.lld non-trivial.o -o /dev/null --icf=all --print-icf-sections | FileCheck %s --check-prefix=NONTRIVIAL
64
+
65
+ # NONTRIVIAL: selected section {{.*}}:(.rodata.sec1)
66
+ # NONTRIVIAL-NEXT: removing identical section {{.*}}:(.rodata.sec2)
67
+ # NONTRIVIAL-NEXT: selected section {{.*}}:(.text.f1_local)
68
+ # NONTRIVIAL-NEXT: removing identical section {{.*}}:(.text.f2_local)
44
69
45
- # CHECK-NOT: selected section {{.*}}:(.text.f1)
46
- # CHECK-NOT: removing identical section {{.*}}:(.text.f2)
70
+ .addrsig
47
71
48
- .globl x, y
72
+ .globl x_glob, y_glob
49
73
50
- .section .rodata,"a" ,@progbits
74
+ .section .rodata.sec1,"a" ,@progbits
75
+ x_glob:
76
+ .long 11
77
+ y_glob:
78
+ .long 12
79
+
80
+ .section .rodata.sec2,"a" ,@progbits
51
81
x:
52
82
.long 11
53
83
y:
54
84
.long 12
55
85
56
86
.section .text .f1,"ax" ,@progbits
57
87
f1:
58
- movq x +4@GOTPCREL(%rip ), %rax
88
+ movq x_glob +4@GOTPCREL(%rip ), %rax
59
89
60
90
.section .text .f2,"ax" ,@progbits
61
91
f2:
62
- movq y@GOTPCREL(%rip ), %rax
92
+ movq y_glob@GOTPCREL(%rip ), %rax
93
+
94
+ .section .text .f1_local,"ax" ,@progbits
95
+ f1_local:
96
+ movq x+4 (%rip ), %rax
97
+
98
+ .section .text .f2_local,"ax" ,@progbits
99
+ f2_local:
100
+ movq y(%rip ), %rax
63
101
64
102
.section .text ._start,"ax" ,@progbits
65
103
.globl _start
66
104
_start:
67
105
call f1
68
106
call f2
69
-
0 commit comments