summaryrefslogtreecommitdiffstats
path: root/lld/test/ELF/linkerscript/icf-output-sections.s
diff options
context:
space:
mode:
Diffstat (limited to 'lld/test/ELF/linkerscript/icf-output-sections.s')
-rw-r--r--lld/test/ELF/linkerscript/icf-output-sections.s46
1 files changed, 46 insertions, 0 deletions
diff --git a/lld/test/ELF/linkerscript/icf-output-sections.s b/lld/test/ELF/linkerscript/icf-output-sections.s
new file mode 100644
index 00000000000..f23d7fff06b
--- /dev/null
+++ b/lld/test/ELF/linkerscript/icf-output-sections.s
@@ -0,0 +1,46 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: echo 'SECTIONS { .text : { *(.text*) } }' > %t1.script
+
+## Sections within the same output section can be freely folded.
+# RUN: ld.lld %t.o --script %t1.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF1 %s
+# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC1 %s --implicit-check-not=.text
+
+# ICF1: selected section {{.*}}.o:(.text.foo0)
+# ICF1-NEXT: removing identical section {{.*}}.o:(.text.foo1)
+# ICF1-NEXT: removing identical section {{.*}}.o:(.text.bar0)
+# ICF1-NEXT: removing identical section {{.*}}.o:(.text.bar1)
+
+# SEC1: .text PROGBITS 0000000000000000 001000 000001
+
+## Sections with different output sections cannot be folded. Without the
+## linker script, .text.foo* and .text.bar* go to the same output section
+## .text and they will be folded.
+# RUN: echo 'SECTIONS { .text.foo : {*(.text.foo*)} .text.bar : {*(.text.bar*)} }' > %t2.script
+# RUN: ld.lld %t.o --script %t2.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF2 %s
+# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC2 %s
+
+# ICF2: selected section {{.*}}.o:(.text.foo0)
+# ICF2-NEXT: removing identical section {{.*}}.o:(.text.foo1)
+# ICF2-NEXT: selected section {{.*}}.o:(.text.bar0)
+# ICF2-NEXT: removing identical section {{.*}}.o:(.text.bar1)
+
+# SEC2: .text.foo PROGBITS 0000000000000000 001000 000001
+# SEC2-NEXT: .text.bar PROGBITS 0000000000000001 001001 000001
+
+## .text.bar* are orphans that get assigned to .text.
+# RUN: echo 'SECTIONS { .text.foo : {*(.text.foo*)} }' > %t3.script
+# RUN: ld.lld %t.o --script %t3.script --icf=all --print-icf-sections -o %t | FileCheck --check-prefix=ICF2 %s
+# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC3 %s
+
+# SEC3: .text.foo PROGBITS 0000000000000000 001000 000001
+# SEC3-NEXT: .text PROGBITS 0000000000000004 001004 000001
+
+.section .text.foo0,"ax"
+ret
+.section .text.foo1,"ax"
+ret
+.section .text.bar0,"ax"
+ret
+.section .text.bar1,"ax"
+ret
OpenPOWER on IntegriCloud