aboutsummaryrefslogtreecommitdiff
path: root/lld/test
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-05-30 10:59:22 -0700
committerFangrui Song <i@maskray.me>2024-05-30 10:59:22 -0700
commit270d95bfedc20c28f142ac63b4882dd06c869c90 (patch)
tree017687cb1efcf31825d49a89a52ab172dcc50244 /lld/test
parentded04bf5d32a4fd5e0919053a598443f9d773549 (diff)
downloadllvm-270d95bfedc20c28f142ac63b4882dd06c869c90.zip
llvm-270d95bfedc20c28f142ac63b4882dd06c869c90.tar.gz
llvm-270d95bfedc20c28f142ac63b4882dd06c869c90.tar.bz2
[ELF] Improve orphan placement tests
Merge orphan-align.test (which introduced `shouldSkip`) into orphan.s.
Diffstat (limited to 'lld/test')
-rw-r--r--lld/test/ELF/linkerscript/orphan-align.s28
-rw-r--r--lld/test/ELF/linkerscript/orphan.s110
-rw-r--r--lld/test/ELF/linkerscript/orphans.s31
3 files changed, 84 insertions, 85 deletions
diff --git a/lld/test/ELF/linkerscript/orphan-align.s b/lld/test/ELF/linkerscript/orphan-align.s
deleted file mode 100644
index b866bea..0000000
--- a/lld/test/ELF/linkerscript/orphan-align.s
+++ /dev/null
@@ -1,28 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: echo "SECTIONS { \
-# RUN: . = SIZEOF_HEADERS; \
-# RUN: .text : { *(.text) } \
-# RUN: . = ALIGN(0x1000); \
-# RUN: .data.rel.ro : { *(.data.rel.ro) } \
-# RUN: }" > %t.script
-# RUN: ld.lld -o %t -T %t.script %t.o -shared --no-rosegment
-# RUN: llvm-readobj -l %t | FileCheck %s
-
-
-# Test that the orphan section foo is placed before the ALIGN and so the second
-# PT_LOAD is aligned.
-
-
-# CHECK: Type: PT_LOAD
-# CHECK-NEXT: Offset: 0x0
-
-# CHECK: Type: PT_LOAD
-# CHECK-NEXT: Offset: 0x1000
-
-nop
-.section .data.rel.ro, "aw"
-.byte 0
-
-.section foo, "ax"
-nop
diff --git a/lld/test/ELF/linkerscript/orphan.s b/lld/test/ELF/linkerscript/orphan.s
index d141f0e..a929d52 100644
--- a/lld/test/ELF/linkerscript/orphan.s
+++ b/lld/test/ELF/linkerscript/orphan.s
@@ -1,36 +1,94 @@
# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: echo "SECTIONS { \
-# RUN: .text : { *(.text) } \
-# RUN: .rw1 : { *(.rw1) } \
-# RUN: .rw2 : { *(.rw2) } \
-# RUN: .rw3 : { *(.rw3) } \
-# RUN: }" > %t.script
-# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump --section-headers %t1 | FileCheck %s
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
## .jcr is a relro section and should be placed before other RW sections.
## .bss is SHT_NOBITS section and should be last RW section, so some space
## in ELF file could be saved.
-# CHECK: 0 00000000 0000000000000000
-# CHECK-NEXT: 1 .text 00000000 0000000000000000 TEXT
-# CHECK-NEXT: 2 .jcr 00000008 0000000000000000 DATA
-# CHECK-NEXT: 3 .rw1 00000008 0000000000000008 DATA
-# CHECK-NEXT: 4 .rw2 00000008 0000000000000010 DATA
-# CHECK-NEXT: 5 .rw3 00000008 0000000000000018 DATA
-# CHECK-NEXT: 6 .bss 00000008 0000000000000020 BSS
+# RUN: ld.lld a.o -T text-rw.lds -o text-rw
+# RUN: llvm-readelf -S text-rw | FileCheck %s --check-prefix=TEXT-RW
+# TEXT-RW: .interp PROGBITS 00000000000002{{..}} 0
+# TEXT-RW-NEXT: .note.my NOTE 00000000000002{{..}} 0
+# TEXT-RW-NEXT: .text PROGBITS 00000000000002{{..}} 0
+# TEXT-RW-NEXT: .mytext PROGBITS 00000000000002{{..}} 0
+# TEXT-RW-NEXT: .jcr PROGBITS 00000000000002{{..}} 0
+# TEXT-RW-NEXT: .rw1 PROGBITS 0000000000001{{...}} 0
+# TEXT-RW-NEXT: .rw2 PROGBITS 0000000000001{{...}} 0
+# TEXT-RW-NEXT: .rw3 PROGBITS 0000000000001{{...}} 0
+# TEXT-RW-NEXT: .bss NOBITS 0000000000001{{...}} 0
-.section .rw1, "aw"
- .quad 0
+# RUN: ld.lld a.o -T only-text.lds -o only-text
+# RUN: llvm-readelf -S only-text | FileCheck %s --check-prefix=ONLY-TEXT
+# ONLY-TEXT: .interp PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .note.my NOTE 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .text PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .mytext PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .jcr PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .rw1 PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .rw2 PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .rw3 PROGBITS 00000000000002{{..}} 0
+# ONLY-TEXT-NEXT: .bss NOBITS 00000000000002{{..}} 0
-.section .rw2, "aw"
- .quad 0
+# RUN: ld.lld a.o -T text-align.lds -o text-align
+# RUN: llvm-readelf -S text-align | FileCheck %s --check-prefix=TEXT-ALIGN
+# TEXT-ALIGN: .interp PROGBITS 00000000000002{{..}} 0
+# TEXT-ALIGN-NEXT: .note.my NOTE 00000000000002{{..}} 0
+# TEXT-ALIGN-NEXT: .text PROGBITS 00000000000002{{..}} 0
+# TEXT-ALIGN-NEXT: .mytext PROGBITS 0000000000001000 0
+# TEXT-ALIGN-NEXT: .jcr PROGBITS 0000000000001{{...}} 0
+# TEXT-ALIGN-NEXT: .rw1 PROGBITS 0000000000001{{...}} 0
+# TEXT-ALIGN-NEXT: .rw2 PROGBITS 0000000000001{{...}} 0
+# TEXT-ALIGN-NEXT: .rw3 PROGBITS 0000000000001{{...}} 0
+# TEXT-ALIGN-NEXT: .bss NOBITS 0000000000001{{...}} 0
-.section .rw3, "aw"
- .quad 0
+# RUN: ld.lld a.o -T only-rw.lds -o only-rw
+# RUN: llvm-readelf -S only-rw | FileCheck %s --check-prefix=ONLY-RW
+# ONLY-RW: .interp PROGBITS 00000000000002{{..}} 0
+# ONLY-RW-NEXT: .note.my NOTE 00000000000002{{..}} 0
+# ONLY-RW-NEXT: .text PROGBITS 00000000000002{{..}} 0
+# ONLY-RW-NEXT: .mytext PROGBITS 00000000000002{{..}} 0
+# ONLY-RW-NEXT: .jcr PROGBITS 00000000000002{{..}} 0
+# ONLY-RW-NEXT: .rw1 PROGBITS 00000000000002{{..}} 0
+# ONLY-RW-NEXT: .rw2 PROGBITS 0000000000001{{...}} 0
+# ONLY-RW-NEXT: .rw3 PROGBITS 0000000000001{{...}} 0
+# ONLY-RW-NEXT: .bss NOBITS 0000000000001{{...}} 0
-.section .jcr, "aw"
- .quad 0
+#--- a.s
+.section .rw1, "aw"; .byte 0
+.section .rw2, "aw"; .byte 0
+.section .rw3, "aw"; .byte 0
+.section .jcr, "aw"; .byte 0
+.section .bss, "aw",@nobits; .byte 0
+.section .note.my, "a", @note; .byte 0
+.section .interp, "a", @progbits; .byte 0
+.text; nop
+.section .mytext,"ax"; nop
-.section .bss, "aw",@nobits
- .quad 0
+#--- text-rw.lds
+SECTIONS {
+ . = SIZEOF_HEADERS;
+ .text : { *(.text) }
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
+ .rw1 : { *(.rw1) }
+ .rw2 : { *(.rw2) }
+}
+
+#--- only-text.lds
+SECTIONS {
+ . = SIZEOF_HEADERS;
+ .text : { *(.text) }
+}
+
+#--- text-align.lds
+SECTIONS {
+ . = SIZEOF_HEADERS;
+ .text : { *(.text) }
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
+}
+
+#--- only-rw.lds
+SECTIONS {
+ . = SIZEOF_HEADERS;
+ .rw1 : { *(.rw1) }
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
+}
diff --git a/lld/test/ELF/linkerscript/orphans.s b/lld/test/ELF/linkerscript/orphans.s
deleted file mode 100644
index 03088b5..0000000
--- a/lld/test/ELF/linkerscript/orphans.s
+++ /dev/null
@@ -1,31 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-
-# RUN: echo "SECTIONS { .writable : { *(.writable) } }" > %t.script
-# RUN: ld.lld -o %t.out --script %t.script %t
-# RUN: llvm-objdump --section-headers %t.out | \
-# RUN: FileCheck -check-prefix=TEXTORPHAN %s
-
-# RUN: echo "SECTIONS { .text : { *(.text) } }" > %t.script
-# RUN: ld.lld -o %t.out --script %t.script %t
-# RUN: llvm-objdump --section-headers %t.out | \
-# RUN: FileCheck -check-prefix=WRITABLEORPHAN %s
-
-# TEXTORPHAN: Sections:
-# TEXTORPHAN-NEXT: Idx Name
-# TEXTORPHAN-NEXT: 0
-# TEXTORPHAN-NEXT: 1 .text
-# TEXTORPHAN-NEXT: 2 .writable
-
-# WRITABLEORPHAN: Sections:
-# WRITABLEORPHAN-NEXT: Idx Name
-# WRITABLEORPHAN-NEXT: 0
-# WRITABLEORPHAN-NEXT: 1 .text
-# WRITABLEORPHAN-NEXT: 2 .writable
-
-.global _start
-_start:
- nop
-
-.section .writable,"aw"
- .zero 4