3 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
4 # RUN: llvm-objcopy %t1.o %t1copy.o
5 # RUN: llvm-objcopy --localize-symbol=h1 %t1.o %t1changed.o
6 # RUN: ld.lld -r %t1.o -o %t1reloc.o
7 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-safe.s -o %t2.o
8 # RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s
9 # RUN: ld.lld %t1copy.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s
10 # RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections -shared | FileCheck --check-prefix=EXPORT %s
11 # RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s
12 # RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections | FileCheck --check-prefix=ALL %s
13 # RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s
14 # RUN: ld.lld %t1changed.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s
15 # RUN: ld.lld %t1reloc.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s
18 # CHECK: selected section {{.*}}:(.rodata.h3)
19 # CHECK-NEXT: removing identical section {{.*}}:(.rodata.h4)
20 # CHECK-NEXT: selected section {{.*}}:(.text.f3)
21 # CHECK-NEXT: removing identical section {{.*}}:(.text.f4)
22 # CHECK-NEXT: selected section {{.*}}:(.rodata.g3)
23 # CHECK-NEXT: removing identical section {{.*}}:(.rodata.g4)
24 # CHECK-NEXT: selected section {{.*}}:(.rodata.l3)
25 # CHECK-NEXT: removing identical section {{.*}}:(.rodata.l4)
26 # CHECK-NEXT: selected section {{.*}}:(.text)
27 # CHECK-NEXT: removing identical section {{.*}}:(.text)
30 # With --icf=all address-significance implies keep-unique only for rodata, not
33 # ALL: selected section {{.*}}:(.rodata.h3)
34 # ALL-NEXT: removing identical section {{.*}}:(.rodata.h4)
35 # ALL-NEXT: selected section {{.*}}:(.text.f3)
36 # ALL-NEXT: removing identical section {{.*}}:(.text.f4)
37 # ALL-NEXT: selected section {{.*}}:(.text.f1)
38 # ALL-NEXT: removing identical section {{.*}}:(.text.f2)
39 # ALL-NEXT: removing identical section {{.*}}:(.text.non_addrsig1)
40 # ALL-NEXT: removing identical section {{.*}}:(.text.non_addrsig2)
41 # ALL-NEXT: selected section {{.*}}:(.rodata.g3)
42 # ALL-NEXT: removing identical section {{.*}}:(.rodata.g4)
43 # ALL-NEXT: selected section {{.*}}:(.rodata.l3)
44 # ALL-NEXT: removing identical section {{.*}}:(.rodata.l4)
45 # ALL-NEXT: selected section {{.*}}:(.text)
46 # ALL-NEXT: removing identical section {{.*}}:(.text)
49 # llvm-mc normally emits an empty .text section into every object file. Since
50 # nothing actually refers to it via a relocation, it doesn't have any associated
51 # symbols (thus nor can anything refer to it via a relocation, making it safe to
52 # merge with the empty section in the other input file). Here we check that the
53 # only two sections merged are the two empty sections and the sections with only
54 # STB_LOCAL or STV_HIDDEN symbols. The dynsym entries should have prevented
55 # anything else from being merged.
57 # EXPORT: selected section {{.*}}:(.rodata.h3)
58 # EXPORT-NEXT: removing identical section {{.*}}:(.rodata.h4)
59 # EXPORT-NEXT: selected section {{.*}}:(.rodata.l3)
60 # EXPORT-NEXT: removing identical section {{.*}}:(.rodata.l4)
63 # If --icf=all is specified when exporting we can also merge the exported text
64 # sections, but not the exported rodata.
65 # ALL-EXPORT-NOT: {{.}}
66 # ALL-EXPORT: selected section {{.*}}:(.rodata.h3)
67 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.rodata.h4)
68 # ALL-EXPORT-NEXT: selected section {{.*}}:(.text.f3)
69 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.f4)
70 # ALL-EXPORT-NEXT: selected section {{.*}}:(.text.f1)
71 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.f2)
72 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.non_addrsig1)
73 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.non_addrsig2)
74 # ALL-EXPORT-NEXT: selected section {{.*}}:(.rodata.l3)
75 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.rodata.l4)
76 # ALL-EXPORT-NEXT: selected section {{.*}}:(.text)
77 # ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text)
78 # ALL-EXPORT-NOT: {{.}}
80 # SH_LINK_0: --icf=safe conservatively ignores SHT_LLVM_ADDRSIG [index [[#]]] with sh_link=0 (likely created using objcopy or ld -r)
85 .section .text.f1,"ax",@progbits
90 .section .text.f2,"ax",@progbits
95 .section .text.f3,"ax",@progbits
100 .section .text.f4,"ax",@progbits
105 .section .rodata.g1,"a",@progbits
110 .section .rodata.g2,"a",@progbits
115 .section .rodata.g3,"a",@progbits
120 .section .rodata.g4,"a",@progbits
125 .section .rodata.l1,"a",@progbits
129 .section .rodata.l2,"a",@progbits
133 .section .rodata.l3,"a",@progbits
137 .section .rodata.l4,"a",@progbits
141 .section .rodata.h1,"a",@progbits
147 .section .rodata.h2,"a",@progbits
153 .section .rodata.h3,"a",@progbits
159 .section .rodata.h4,"a",@progbits