22# RUN: rm -rf %t && split-file %s %t && cd %t
33
44#--- 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.
78
89# 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
1011
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)
1518
16- .globl x, y
19+ .addrsig
1720
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
1930x:
2031.long 11
2132y:
2233.long 12
2334
2435.section .text .f1,"ax" ,@progbits
2536f1:
26- movq x +4 (%rip ), %rax
37+ movq x_glob +4 (%rip ), %rax
2738
2839.section .text .f2,"ax" ,@progbits
2940f2:
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:
3049movq y(%rip ), %rax
3150
3251.section .text ._start,"ax" ,@progbits
@@ -36,34 +55,52 @@ call f1
3655call f2
3756
3857#--- 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.
4161
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)
4469
45- # CHECK-NOT: selected section {{.*}}:(.text.f1)
46- # CHECK-NOT: removing identical section {{.*}}:(.text.f2)
70+ .addrsig
4771
48- .globl x, y
72+ .globl x_glob, y_glob
4973
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
5181x:
5282.long 11
5383y:
5484.long 12
5585
5686.section .text .f1,"ax" ,@progbits
5787f1:
58- movq x +4@GOTPCREL(%rip ), %rax
88+ movq x_glob +4@GOTPCREL(%rip ), %rax
5989
6090.section .text .f2,"ax" ,@progbits
6191f2:
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
63101
64102.section .text ._start,"ax" ,@progbits
65103.globl _start
66104_start:
67105call f1
68106call f2
69-
0 commit comments