[lld] 81c4bf9 - [ELF] Improve _etext/_edata tests
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 12:01:54 PST 2024
Author: Fangrui Song
Date: 2024-02-09T12:01:49-08:00
New Revision: 81c4bf946a377b1dc90c02ff3ff8240e78db0edb
URL: https://github.com/llvm/llvm-project/commit/81c4bf946a377b1dc90c02ff3ff8240e78db0edb
DIFF: https://github.com/llvm/llvm-project/commit/81c4bf946a377b1dc90c02ff3ff8240e78db0edb.diff
LOG: [ELF] Improve _etext/_edata tests
Added:
Modified:
lld/test/ELF/riscv-section-layout.s
lld/test/ELF/x86-64-section-layout.s
Removed:
################################################################################
diff --git a/lld/test/ELF/riscv-section-layout.s b/lld/test/ELF/riscv-section-layout.s
index 56ac95d01fdfd6..10e0febf7c4260 100644
--- a/lld/test/ELF/riscv-section-layout.s
+++ b/lld/test/ELF/riscv-section-layout.s
@@ -3,20 +3,20 @@
# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o
# RUN: ld.lld -pie %t.32.o -o %t.32
-# RUN: llvm-readelf -S -s %t.32 | FileCheck %s --check-prefix=NOSDATA
+# RUN: llvm-readelf -S -sX %t.32 | FileCheck %s --check-prefix=NOSDATA
# RUN: llvm-mc -filetype=obj -triple=riscv32 --defsym=SDATA=1 %s -o %t.32s.o
# RUN: ld.lld -pie %t.32s.o -o %t.32s
-# RUN: llvm-readelf -S -s %t.32s | FileCheck %s
+# RUN: llvm-readelf -S -sX %t.32s | FileCheck %s
# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o
# RUN: ld.lld -pie %t.64.o -o %t.64
-# RUN: llvm-readelf -S -s %t.64 | FileCheck %s --check-prefix=NOSDATA
+# RUN: llvm-readelf -S -sX %t.64 | FileCheck %s --check-prefix=NOSDATA
# RUN: llvm-mc -filetype=obj -triple=riscv64 --defsym=SDATA=1 %s -o %t.64s.o
# RUN: ld.lld -pie %t.64s.o -o %t.64s
-# RUN: llvm-readelf -S -s %t.64s | FileCheck %s
+# RUN: llvm-readelf -S -sX %t.64s | FileCheck %s
# NOSDATA: .text
-# NOSDATA-NEXT: .tdata
+# NOSDATA-NEXT: .tdata PROGBITS [[#%x,TDATA:]]
# NOSDATA-NEXT: .tbss
# NOSDATA-NEXT: .dynamic
# NOSDATA-NEXT: .got
@@ -28,9 +28,10 @@
## exist, define __global_pointer$ and set its st_shndx arbitrarily to 1.
## The symbol value should not be used by the program.
-# NOSDATA-DAG: [[#]]: {{0*}}[[#BSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] _edata
-# NOSDATA-DAG: [[#]]: {{0*}}[[#BSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] __bss_start
-# NOSDATA-DAG: [[#]]: {{0*}}800 0 NOTYPE GLOBAL DEFAULT 1 __global_pointer$
+# NOSDATA-DAG: [[#]]: {{.*}} 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
+# NOSDATA-DAG: [[#]]: {{0*}}[[#BSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
+# NOSDATA-DAG: [[#]]: {{0*}}[[#BSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] (.bss) __bss_start
+# NOSDATA-DAG: [[#]]: {{0*}}800 0 NOTYPE GLOBAL DEFAULT 1 (.dynsym) __global_pointer$
# CHECK: .text
# CHECK-NEXT: .tdata
@@ -43,11 +44,11 @@
# CHECK-NEXT: .sbss NOBITS [[#%x,SBSS:]]
# CHECK-NEXT: .bss
-# CHECK-DAG: [[#]]: {{0*}}[[#SBSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] _edata
-# CHECK-DAG: [[#]]: {{0*}}[[#SBSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] __bss_start
-# CHECK-DAG: [[#]]: {{0*}}[[#SDATA+0x800]] 0 NOTYPE GLOBAL DEFAULT [[#]] __global_pointer$
+# CHECK-DAG: [[#]]: {{0*}}[[#SBSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] (.sdata) _edata
+# CHECK-DAG: [[#]]: {{0*}}[[#SBSS]] 0 NOTYPE GLOBAL DEFAULT [[#]] (.sbss) __bss_start
+# CHECK-DAG: [[#]]: {{0*}}[[#SDATA+0x800]] 0 NOTYPE GLOBAL DEFAULT [[#]] (.sdata) __global_pointer$
-.globl _edata, __bss_start
+.globl _etext, _edata, __bss_start
lla gp, __global_pointer$
.section .data,"aw", at progbits; .long _GLOBAL_OFFSET_TABLE_ - .
diff --git a/lld/test/ELF/x86-64-section-layout.s b/lld/test/ELF/x86-64-section-layout.s
index 37201279fa0a5d..f2928777e8214b 100644
--- a/lld/test/ELF/x86-64-section-layout.s
+++ b/lld/test/ELF/x86-64-section-layout.s
@@ -6,31 +6,31 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 --defsym=BSS=1 a.s -o a.o
# RUN: ld.lld --section-start=.note=0x200300 a.o -o a
-# RUN: llvm-readelf -S -l a | FileCheck %s
+# RUN: llvm-readelf -S -l -sX a | FileCheck %s
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a1.o
# RUN: ld.lld --section-start=.note=0x200300 a1.o -o a1
-# RUN: llvm-readelf -S a1 | FileCheck %s --check-prefix=CHECK1
+# RUN: llvm-readelf -S -sX a1 | FileCheck %s --check-prefix=CHECK1
# RUN: ld.lld -T b.lds -z norelro a.o -o b
# RUN: llvm-readelf -S -l b | FileCheck %s --check-prefix=CHECK2
-# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
-# CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
-# CHECK-NEXT: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
-# CHECK-NEXT: .lrodata PROGBITS 0000000000200301 000301 000002 00 Al 0 0 1
-# CHECK-NEXT: .rodata PROGBITS 0000000000200303 000303 000001 00 A 0 0 1
-# CHECK-NEXT: .text PROGBITS 0000000000201304 000304 000001 00 AX 0 0 4
-# CHECK-NEXT: .tdata PROGBITS 0000000000202305 000305 000001 00 WAT 0 0 1
-# CHECK-NEXT: .tbss NOBITS 0000000000202306 000306 000002 00 WAT 0 0 1
-# CHECK-NEXT: .relro_padding NOBITS 0000000000202306 000306 000cfa 00 WA 0 0 1
-# CHECK-NEXT: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
-# CHECK-NEXT: .bss NOBITS 0000000000203307 000307 001800 00 WA 0 0 1
+# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
+# CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
+# CHECK-NEXT: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
+# CHECK-NEXT: .lrodata PROGBITS 0000000000200301 000301 000002 00 Al 0 0 1
+# CHECK-NEXT: .rodata PROGBITS 0000000000200303 000303 000001 00 A 0 0 1
+# CHECK-NEXT: .text PROGBITS 0000000000201304 000304 000001 00 AX 0 0 4
+# CHECK-NEXT: .tdata PROGBITS 0000000000202305 000305 000001 00 WAT 0 0 1
+# CHECK-NEXT: .tbss NOBITS 0000000000202306 000306 000002 00 WAT 0 0 1
+# CHECK-NEXT: .relro_padding NOBITS 0000000000202306 000306 000cfa 00 WA 0 0 1
+# CHECK-NEXT: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
+# CHECK-NEXT: .bss NOBITS 0000000000203307 000307 001800 00 WA 0 0 1
## We spend size(.bss) % MAXPAGESIZE bytes for .bss.
-# CHECK-NEXT: .ldata PROGBITS 0000000000205b07 000b07 000002 00 WAl 0 0 1
-# CHECK-NEXT: .ldata2 PROGBITS 0000000000205b09 000b09 000001 00 WAl 0 0 1
-# CHECK-NEXT: .lbss NOBITS 0000000000205b0a 000b0a 000002 00 WAl 0 0 1
-# CHECK-NEXT: .comment PROGBITS 0000000000000000 000b0a {{.*}} 01 MS 0 0 1
+# CHECK-NEXT: .ldata PROGBITS 0000000000205b07 000b07 000002 00 WAl 0 0 1
+# CHECK-NEXT: .ldata2 PROGBITS 0000000000205b09 000b09 000001 00 WAl 0 0 1
+# CHECK-NEXT: .lbss NOBITS 0000000000205b0a 000b0a 001201 00 WAl 0 0 1
+# CHECK-NEXT: .comment PROGBITS 0000000000000000 000b0a {{.*}} 01 MS 0 0 1
# CHECK: Program Headers:
# CHECK-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
@@ -39,13 +39,23 @@
# CHECK-NEXT: LOAD 0x000304 0x0000000000201304 0x0000000000201304 0x000001 0x000001 R E 0x1000
# CHECK-NEXT: LOAD 0x000305 0x0000000000202305 0x0000000000202305 0x000001 0x000cfb RW 0x1000
# CHECK-NEXT: LOAD 0x000306 0x0000000000203306 0x0000000000203306 0x000001 0x001801 RW 0x1000
-# CHECK-NEXT: LOAD 0x000b07 0x0000000000205b07 0x0000000000205b07 0x000003 0x000005 RW 0x1000
+# CHECK-NEXT: LOAD 0x000b07 0x0000000000205b07 0x0000000000205b07 0x000003 0x001204 RW 0x1000
+
+# CHECK: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
+# CHECK-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
+# CHECK-NEXT: 0000000000205b0a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _edata
+# CHECK-NEXT: 0000000000206d0b 0 NOTYPE GLOBAL DEFAULT [[#]] (.lbss) _end
# CHECK1: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
# CHECK1-NEXT: .ldata PROGBITS 0000000000203307 000307 000002 00 WAl 0 0 1
# CHECK1-NEXT: .ldata2 PROGBITS 0000000000203309 000309 000001 00 WAl 0 0 1
# CHECK1-NEXT: .comment PROGBITS 0000000000000000 00030a {{.*}} 01 MS 0 0 1
+# CHECK1: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
+# CHECK1-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
+# CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _edata
+# CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _end
+
# CHECK2: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
# CHECK2-NEXT: .lrodata PROGBITS 0000000000200301 000301 000001 00 Al 0 0 1
## With a SECTIONS command, we suppress the default rule placing .lrodata.* into .lrodata.
@@ -59,7 +69,7 @@
# CHECK2-NEXT: .bss NOBITS 0000000000200307 000307 001800 00 WA 0 0 1
# CHECK2-NEXT: .ldata PROGBITS 0000000000201b07 001b07 000002 00 WAl 0 0 1
# CHECK2-NEXT: .ldata2 PROGBITS 0000000000201b09 001b09 000001 00 WAl 0 0 1
-# CHECK2-NEXT: .lbss NOBITS 0000000000201b0a 001b0a 000002 00 WAl 0 0 1
+# CHECK2-NEXT: .lbss NOBITS 0000000000201b0a 001b0a 001201 00 WAl 0 0 1
# CHECK2-NEXT: .comment PROGBITS 0000000000000000 001b0a {{.*}} 01 MS 0 0 1
# CHECK2: Program Headers:
@@ -67,11 +77,11 @@
# CHECK2-NEXT: PHDR 0x000040 0x0000000000200040 0x0000000000200040 {{.*}} {{.*}} R 0x8
# CHECK2-NEXT: LOAD 0x000000 0x0000000000200000 0x0000000000200000 0x000304 0x000304 R 0x1000
# CHECK2-NEXT: LOAD 0x000304 0x0000000000200304 0x0000000000200304 0x000001 0x000001 R E 0x1000
-# CHECK2-NEXT: LOAD 0x000305 0x0000000000200305 0x0000000000200305 0x001805 0x001807 RW 0x1000
+# CHECK2-NEXT: LOAD 0x000305 0x0000000000200305 0x0000000000200305 0x001805 0x002a06 RW 0x1000
# CHECK2-NEXT: TLS 0x000305 0x0000000000200305 0x0000000000200305 0x000001 0x000003 R 0x1
#--- a.s
-.globl _start
+.globl _start, _etext, _edata, _end
_start:
ret
@@ -92,7 +102,7 @@ _start:
## Input .ldata.rel.ro sections are placed in the output .ldata section.
.section .ldata.rel.ro,"awl"; .space 1
.ifdef BSS
-.section .lbss,"awl", at nobits; .space 1
+.section .lbss,"awl", at nobits; .space 0x1200
## Input .lbss.rel.ro sections are placed in the output .lbss section.
.section .lbss.rel.ro,"awl", at nobits; .space 1
.endif
More information about the llvm-commits
mailing list