[lld] 270d95b - [ELF] Improve orphan placement tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 10:59:26 PDT 2024


Author: Fangrui Song
Date: 2024-05-30T10:59:22-07:00
New Revision: 270d95bfedc20c28f142ac63b4882dd06c869c90

URL: https://github.com/llvm/llvm-project/commit/270d95bfedc20c28f142ac63b4882dd06c869c90
DIFF: https://github.com/llvm/llvm-project/commit/270d95bfedc20c28f142ac63b4882dd06c869c90.diff

LOG: [ELF] Improve orphan placement tests

Merge orphan-align.test (which introduced `shouldSkip`) into orphan.s.

Added: 
    

Modified: 
    lld/test/ELF/linkerscript/orphan.s

Removed: 
    lld/test/ELF/linkerscript/orphan-align.s
    lld/test/ELF/linkerscript/orphans.s


################################################################################
diff  --git a/lld/test/ELF/linkerscript/orphan-align.s b/lld/test/ELF/linkerscript/orphan-align.s
deleted file mode 100644
index b866beaa898bb..0000000000000
--- 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 d141f0e45587f..a929d529a83d8 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", at 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", at 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 03088b5bc92c9..0000000000000
--- 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


        


More information about the llvm-commits mailing list