Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / linkerscript / icf-output-sections.s
blobae9203abaea49f1835cf06f142d294b538133a36
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3 # RUN: echo 'SECTIONS { .text : { *(.text*) } }' > %t1.script
5 ## Sections within the same output section can be freely folded.
6 # RUN: ld.lld %t.o --script %t1.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF1 %s
7 # RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC1 %s --implicit-check-not=.text
9 # ICF1: selected section {{.*}}.o:(.text.foo0)
10 # ICF1-NEXT: removing identical section {{.*}}.o:(.text.foo1)
11 # ICF1-NEXT: removing identical section {{.*}}.o:(.text.bar0)
12 # ICF1-NEXT: removing identical section {{.*}}.o:(.text.bar1)
14 # SEC1: .text PROGBITS 0000000000000000 001000 000001
16 ## Sections with different output sections cannot be folded. Without the
17 ## linker script, .text.foo* and .text.bar* go to the same output section
18 ## .text and they will be folded.
19 # RUN: echo 'SECTIONS { .text.foo : {*(.text.foo*)} .text.bar : {*(.text.bar*)} }' > %t2.script
20 # RUN: ld.lld %t.o --script %t2.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF2 %s
21 # RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC2 %s
23 # ICF2: selected section {{.*}}.o:(.text.foo0)
24 # ICF2-NEXT: removing identical section {{.*}}.o:(.text.foo1)
25 # ICF2-NEXT: selected section {{.*}}.o:(.text.bar0)
26 # ICF2-NEXT: removing identical section {{.*}}.o:(.text.bar1)
28 # SEC2: .text.foo PROGBITS 0000000000000000 001000 000001
29 # SEC2-NEXT: .text.bar PROGBITS 0000000000000001 001001 000001
31 ## .text.bar* are orphan sections.
32 # RUN: echo 'SECTIONS { .text.foo : {*(.text.foo*)} }' > %t3.script
33 # RUN: ld.lld %t.o -T %t3.script --icf=all --print-icf-sections -o %t3 | FileCheck --check-prefix=ICF3 %s
34 # RUN: llvm-readelf -S %t3 | FileCheck --check-prefix=SEC3 %s
36 # ICF3: selected section {{.*}}.o:(.text.foo0)
37 # ICF3-NEXT: removing identical section {{.*}}.o:(.text.foo1)
39 # SEC3: Name Type Address Off Size
40 # SEC3: .text.foo PROGBITS 0000000000000000 001000 000001
41 # SEC3-NEXT: .text PROGBITS 0000000000000004 001004 000000
42 # SEC3-NEXT: .text.bar0 PROGBITS 0000000000000004 001004 000001
43 # SEC3-NEXT: .text.bar1 PROGBITS 0000000000000005 001005 000001
45 .section .text.foo0,"ax"
46 ret
47 .section .text.foo1,"ax"
48 ret
49 .section .text.bar0,"ax"
50 ret
51 .section .text.bar1,"ax"
52 ret