[lld] 7b8341b - [ELF][test] Improve MEMORY tests
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 14:01:29 PST 2020
Author: Fangrui Song
Date: 2020-03-06T14:01:20-08:00
New Revision: 7b8341b25771053840b719b72df547b5bf259fb6
URL: https://github.com/llvm/llvm-project/commit/7b8341b25771053840b719b72df547b5bf259fb6
DIFF: https://github.com/llvm/llvm-project/commit/7b8341b25771053840b719b72df547b5bf259fb6.diff
LOG: [ELF][test] Improve MEMORY tests
Added:
lld/test/ELF/linkerscript/memory-ignored-dot-assign.test
lld/test/ELF/linkerscript/memory-ignored-output-address.test
Modified:
lld/test/ELF/linkerscript/memory-err.s
lld/test/ELF/linkerscript/memory.s
Removed:
lld/test/ELF/linkerscript/memory4.test
lld/test/ELF/linkerscript/memory5.test
################################################################################
diff --git a/lld/test/ELF/linkerscript/memory-err.s b/lld/test/ELF/linkerscript/memory-err.s
index 3c0f689fde8d..ac8d77ead7a4 100644
--- a/lld/test/ELF/linkerscript/memory-err.s
+++ b/lld/test/ELF/linkerscript/memory-err.s
@@ -1,16 +1,71 @@
# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+
+## Check bad `ORIGIN`.
+
+# RUN: echo 'MEMORY { ram (rwx) : XYZ = 0x8000 } }' > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR1 %s
+# ERR1: {{.*}}.script:1: expected one of: ORIGIN, org, or o
+
+## Check bad `LENGTH`.
+
+# RUN: echo 'MEMORY { ram (rwx) : ORIGIN = 0x8000, XYZ = 256K } }' > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR2 %s
+# ERR2: {{.*}}.script:1: expected one of: LENGTH, len, or l
+
+## Check duplicate regions.
+
+# RUN: echo 'MEMORY { ram (rwx) : o = 8, l = 256K ram (rx) : o = 0, l = 256K }' > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR3 %s
+# ERR3: {{.*}}.script:1: region 'ram' already defined
+
+## Check no region available.
+
+# RUN: echo 'MEMORY { ram (!rx) : ORIGIN = 0x8000, LENGTH = 256K } \
+# RUN: SECTIONS { \
+# RUN: .text : { *(.text) } \
+# RUN: .data : { *(.data) } > ram \
+# RUN: }' > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR4 %s
+# ERR4: error: no memory region specified for section '.text'
+
+## Check undeclared region.
+
+# RUN: echo 'SECTIONS { .text : { *(.text) } > ram }' > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR5 %s
+# ERR5: error: memory region 'ram' not declared
+
+## Check region overflow.
+
+# RUN: echo 'MEMORY { ram (rwx) : ORIGIN = 0, LENGTH = 2K } \
+# RUN: SECTIONS { \
+# RUN: .text : { *(.text) } > ram \
+# RUN: .data : { *(.data) } > ram \
+# RUN: }' > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR6 %s
+# ERR6: error: section '.data' will not fit in region 'ram': overflowed by 2049 bytes
+
+## Check invalid region attributes.
+
+# RUN: echo "MEMORY { ram (abc) : ORIGIN = 8000, LENGTH = 256K } }" > %t.script
+# RUN: not ld.lld -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR7 %s
+# ERR7: {{.*}}.script:1: invalid memory region attribute
+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo "MEMORY { name : ORIGIN = DATA_SEGMENT_RELRO_END; }" > %t.script
-# RUN: not ld.lld -shared -o /dev/null --script %t.script %t 2>&1 | FileCheck %s
+# RUN: not ld.lld -shared -o /dev/null -T %t.script %t.o 2>&1 | FileCheck %s
# CHECK: error: {{.*}}.script:1: unable to calculate page size
-# RUN: echo "MEMORY { name : ORIGIN = CONSTANT(COMMONPAGESIZE); }" > %t.script
-# RUN: not ld.lld -shared -o /dev/null --script %t.script %t 2>&1 |\
-# RUN: FileCheck %s --check-prefix=ERR2
-# ERR2: error: {{.*}}.script:1: unable to calculate page size
+# RUN: echo 'MEMORY { name : ORIGIN = CONSTANT(COMMONPAGESIZE); }' > %t.script
+# RUN: not ld.lld -shared -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR_PAGESIZE %s
+# ERR_PAGESIZE: error: {{.*}}.script:1: unable to calculate page size
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: echo "MEMORY { name : ORIGIN = .; }" > %t.script
-# RUN: not ld.lld -shared -o /dev/null --script %t.script %t 2>&1 |\
-# RUN: FileCheck %s --check-prefix=ERR3
-# ERR3: error: {{.*}}.script:1: unable to get location counter value
+# RUN: echo 'MEMORY { name : ORIGIN = .; }' > %t.script
+# RUN: not ld.lld -shared -o /dev/null -T %t.script %t.o 2>&1 | FileCheck --check-prefix=ERR_DOT %s
+# ERR_DOT: error: {{.*}}.script:1: unable to get location counter value
+
+nop
+
+.data
+.zero 4096
diff --git a/lld/test/ELF/linkerscript/memory-ignored-dot-assign.test b/lld/test/ELF/linkerscript/memory-ignored-dot-assign.test
new file mode 100644
index 000000000000..0e7c908816df
--- /dev/null
+++ b/lld/test/ELF/linkerscript/memory-ignored-dot-assign.test
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: echo 'nop; .data; nop' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
+# RUN: ld.lld -o %t.so --script %s %t.o
+# RUN: llvm-readelf -S %t.so | FileCheck %s
+
+# CHECK: [ 1] .text PROGBITS 0000000000042000 001000 000001
+# CHECK-NEXT: [ 2] .data PROGBITS 0000000000042001 001001 000001
+
+## Test that assigning to Dot does not change the position in a memory region.
+
+MEMORY {
+ ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
+}
+SECTIONS {
+ .text : { *(.text*) }
+ . += 0x2000;
+ .data : { *(.data*) }
+}
diff --git a/lld/test/ELF/linkerscript/memory-ignored-output-address.test b/lld/test/ELF/linkerscript/memory-ignored-output-address.test
new file mode 100644
index 000000000000..7a119c372a53
--- /dev/null
+++ b/lld/test/ELF/linkerscript/memory-ignored-output-address.test
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: echo 'nop; .data; nop' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
+# RUN: ld.lld -o %t.so --script %s %t.o
+# RUN: llvm-readelf -S %t.so | FileCheck %s
+
+# CHECK: [ 1] .text PROGBITS 0000000000042000 001000 000001
+# CHECK-NEXT: [ 2] .data PROGBITS 0000000000042400 001400 000001
+
+## Test that address expressions changes the position in a memory region.
+
+MEMORY {
+ ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
+}
+SECTIONS {
+ .text : { *(.text*) }
+ data_addr = ALIGN(1024);
+ .data data_addr : { *(.data*) }
+}
diff --git a/lld/test/ELF/linkerscript/memory.s b/lld/test/ELF/linkerscript/memory.s
index 043483257cb3..3111ef60dde9 100644
--- a/lld/test/ELF/linkerscript/memory.s
+++ b/lld/test/ELF/linkerscript/memory.s
@@ -9,10 +9,10 @@
# RUN: .data : { *(.data) } > ram \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=RAM %s
+# RUN: llvm-readelf -S %t1 | FileCheck --check-prefix=RAM %s
-# RAM: 1 .text 00000001 0000000000008000 TEXT
-# RAM-NEXT: 2 .data 00001000 0000000000008001 DATA
+# RAM: [ 1] .text PROGBITS 0000000000008000 001000 000001
+# RAM-NEXT: [ 2] .data PROGBITS 0000000000008001 001001 001000
## Check RAM and ROM memory regions.
@@ -25,10 +25,10 @@
# RUN: .data : { *(.data) } >ram \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=RAMROM %s
+# RUN: llvm-readelf -S %t1 | FileCheck --check-prefix=RAMROM %s
-# RAMROM: 1 .text 00000001 0000000080000000 TEXT
-# RAMROM-NEXT: 2 .data 00001000 0000000000000000 DATA
+# RAMROM: [ 1] .text PROGBITS 0000000080000000 001000 000001
+# RAMROM-NEXT: [ 2] .data PROGBITS 0000000000000000 002000 001000
## Check memory region placement by attributes.
@@ -41,67 +41,10 @@
# RUN: .data : { *(.data) } > ram \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=ATTRS %s
+# RUN: llvm-readelf -S %t1 | FileCheck --check-prefix=ATTRS %s
-# ATTRS: 1 .text 00000001 0000000080000000 TEXT
-# ATTRS: 2 .data 00001000 0000000000000000 DATA
-
-## Check bad `ORIGIN`.
-
-# RUN: echo "MEMORY { ram (rwx) : XYZ = 0x8000 } }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR1 %s
-# ERR1: {{.*}}.script:1: expected one of: ORIGIN, org, or o
-
-## Check bad `LENGTH`.
-
-# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0x8000, XYZ = 256K } }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR2 %s
-# ERR2: {{.*}}.script:1: expected one of: LENGTH, len, or l
-
-## Check duplicate regions.
-
-# RUN: echo "MEMORY { ram (rwx) : o = 8, l = 256K ram (rx) : o = 0, l = 256K }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR3 %s
-# ERR3: {{.*}}.script:1: region 'ram' already defined
-
-## Check no region available.
-
-# RUN: echo "MEMORY { ram (!rx) : ORIGIN = 0x8000, LENGTH = 256K } \
-# RUN: SECTIONS { \
-# RUN: .text : { *(.text) } \
-# RUN: .data : { *(.data) } > ram \
-# RUN: }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR4 %s
-# ERR4: {{.*}}: no memory region specified for section '.text'
-
-## Check undeclared region.
-
-# RUN: echo "SECTIONS { .text : { *(.text) } > ram }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR5 %s
-# ERR5: {{.*}}: memory region 'ram' not declared
-
-## Check region overflow.
-
-# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0, LENGTH = 2K } \
-# RUN: SECTIONS { \
-# RUN: .text : { *(.text) } > ram \
-# RUN: .data : { *(.data) } > ram \
-# RUN: }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR6 %s
-# ERR6: {{.*}}: section '.data' will not fit in region 'ram': overflowed by 2049 bytes
-
-## Check invalid region attributes.
-
-# RUN: echo "MEMORY { ram (abc) : ORIGIN = 8000, LENGTH = 256K } }" > %t.script
-# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
-# RUN: | FileCheck -check-prefix=ERR7 %s
-# ERR7: {{.*}}.script:1: invalid memory region attribute
+# ATTRS: [ 1] .text PROGBITS 0000000080000000 001000 000001
+# ATTRS-NEXT: [ 2] .data PROGBITS 0000000000000000 002000 001000
.text
.global _start
diff --git a/lld/test/ELF/linkerscript/memory4.test b/lld/test/ELF/linkerscript/memory4.test
deleted file mode 100644
index e73d36085562..000000000000
--- a/lld/test/ELF/linkerscript/memory4.test
+++ /dev/null
@@ -1,19 +0,0 @@
-# REQUIRES: x86
-# RUN: echo ".section .text,\"ax\"; nop; .section .data,\"aw\"; nop;" \
-# RUN: | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o
-# RUN: ld.lld -o %t.so --script %s %t.o
-# RUN: llvm-objdump -section-headers %t.so | FileCheck %s
-
-# CHECK: 1 .text 00000001 0000000000042000
-# CHECK-NEXT: 2 .data 00000001 0000000000042400
-
-## Test that address expressions changes the position in a memory region.
-
-MEMORY {
- ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
-}
-SECTIONS {
- .text : { *(.text*) }
- data_addr = ALIGN(1024);
- .data data_addr : { *(.data*) }
-}
diff --git a/lld/test/ELF/linkerscript/memory5.test b/lld/test/ELF/linkerscript/memory5.test
deleted file mode 100644
index fa921a72a065..000000000000
--- a/lld/test/ELF/linkerscript/memory5.test
+++ /dev/null
@@ -1,19 +0,0 @@
-# REQUIRES: x86
-# RUN: echo ".section .text,\"ax\"; nop; .section .data,\"aw\"; nop;" \
-# RUN: | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o
-# RUN: ld.lld -o %t.so --script %s %t.o
-# RUN: llvm-objdump -section-headers %t.so | FileCheck %s
-
-# CHECK: 1 .text 00000001 0000000000042000
-# CHECK-NEXT: 2 .data 00000001 0000000000042001
-
-## Test that assigning to Dot does not change the position in a memory region.
-
-MEMORY {
- ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
-}
-SECTIONS {
- .text : { *(.text*) }
- . += 0x2000;
- .data : { *(.data*) }
-}
More information about the llvm-commits
mailing list