diff options
author | Fangrui Song <i@maskray.me> | 2024-01-07 21:36:33 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2024-01-07 21:36:33 -0800 |
commit | 1dfb9498333a6c7c6ac012eb70dc593f5165a025 (patch) | |
tree | 2160eb37881843ff88a0ff6427d3724c4500bfb5 | |
parent | ce944597e43ae4f77260d4683f8d6535947fb0a2 (diff) |
[ELF] Improve OVERLAY tests
Also test two issues:
* When the start address is `.`, subsequent sections don't share the
address of the first overlay section.
* When the first overlay section is empty and discardable, `p_paddr` is
incorrectly zero. This is because a discarded section has a zero
address, causing `prev->getLMA() + prev->size` where `prev` refers to
the first section to evaluate to zero.
-rw-r--r-- | lld/test/ELF/linkerscript/overlay-reject.test | 13 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/overlay-reject2.test | 17 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/overlay.test | 100 |
3 files changed, 80 insertions, 50 deletions
diff --git a/lld/test/ELF/linkerscript/overlay-reject.test b/lld/test/ELF/linkerscript/overlay-reject.test deleted file mode 100644 index fa8a2be37aed..000000000000 --- a/lld/test/ELF/linkerscript/overlay-reject.test +++ /dev/null @@ -1,13 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o -# RUN: not ld.lld %t.o --script %s -o /dev/null 2>&1 | FileCheck %s - -# CHECK: {{.*}}.test:{{.*}}: { expected, but got 0x3000 -# CHECK-NEXT: >>> .out.aaa 0x3000 : { *(.aaa) } -# CHECK-NEXT: >>> ^ - -SECTIONS { - OVERLAY 0x1000 : AT ( 0x2000 ) { - .out.aaa 0x3000 : { *(.aaa) } - } -} diff --git a/lld/test/ELF/linkerscript/overlay-reject2.test b/lld/test/ELF/linkerscript/overlay-reject2.test deleted file mode 100644 index be886d7c1dac..000000000000 --- a/lld/test/ELF/linkerscript/overlay-reject2.test +++ /dev/null @@ -1,17 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o -# RUN: not ld.lld %t.o --script %s -o /dev/null 2>&1 | FileCheck %s - -# CHECK: {{.*}}.test:{{.*}}: { expected, but got AX -# CHECK-NEXT: >>> .out.aaa { *(.aaa) } > AX AT>FLASH -# CHECK-NEXT: >>> ^ - -MEMORY { - AX (ax) : ORIGIN = 0x3000, LENGTH = 0x4000 -} - -SECTIONS { - OVERLAY 0x1000 : AT ( 0x2000 ) { - .out.aaa { *(.aaa) } > AX AT>FLASH - } -} diff --git a/lld/test/ELF/linkerscript/overlay.test b/lld/test/ELF/linkerscript/overlay.test index 2d3c88759c63..942e0a2971be 100644 --- a/lld/test/ELF/linkerscript/overlay.test +++ b/lld/test/ELF/linkerscript/overlay.test @@ -1,31 +1,91 @@ # REQUIRES: x86 -# RUN: echo 'nop; .section .small, "a"; .long 0; .section .big, "a"; .quad 1;' \ -# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o -# RUN: ld.lld %t.o --script %s -o %t +# RUN: rm -rf %t && split-file %s %t && cd %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o +# RUN: ld.lld a.o -T a.t -o a -SECTIONS { - OVERLAY 0x1000 : AT ( 0x4000 ) { - .out.big { *(.big) } - .out.small { *(.small) } - } -} - -## Here we check that can handle OVERLAY which will produce sections +## Here we check that can handle OVERLAY which will produce sections ## .out.big and .out.small with the same starting VAs, but different LMAs. ## Section .big is larger than .small, we check that placing of section ## .text does not cause overlapping error and that ## .text's VA is 0x1000 + max(sizeof(.out.big), sizeof(.out.small)). -# RUN: llvm-readelf --sections -l %t | FileCheck %s +# RUN: llvm-readelf --sections -l a | FileCheck %s -# CHECK: Section Headers: -# CHECK: Name Type Address Off Size -# CHECK: .out.big PROGBITS 0000000000001000 001000 000008 -# CHECK: .out.small PROGBITS 0000000000001000 002000 000004 -# CHECK: .text PROGBITS 0000000000001008 002008 000001 +# CHECK: Name Type Address Off Size +# CHECK: .big1 PROGBITS 0000000000001000 001000 000008 +# CHECK-NEXT: .small1 PROGBITS 0000000000001000 002000 000004 +# CHECK-NEXT: .small2 PROGBITS 0000000000001008 002008 000004 +# CHECK-NEXT: .big2 PROGBITS 0000000000001008 003008 000008 +# CHECK-NEXT: .small3 PROGBITS 0000000000001010 003010 000004 +# CHECK-NEXT: .big3 PROGBITS 0000000000001014 003014 000008 +# CHECK-NEXT: .text PROGBITS 0000000000001024 003024 000001 # CHECK: Program Headers: # CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align -# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000004000 0x000008 0x000008 R 0x1000 -# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000004008 0x000004 0x000004 R 0x1000 -# CHECK-NEXT: LOAD 0x002008 0x0000000000001008 0x0000000000004010 0x000001 0x000001 R E 0x1000 +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000008 0x000008 R 0x1000 +# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000001008 0x000004 0x000004 R 0x1000 +# CHECK-NEXT: LOAD 0x002008 0x0000000000001008 0x0000000000002008 0x000004 0x000004 R 0x1000 +# CHECK-NEXT: LOAD 0x003008 0x0000000000001008 0x000000000000200c 0x000008 0x000008 R 0x1000 +## FIXME Fix p_paddr when the first section in an overlay is empty and discarded. +# CHECK-NEXT: LOAD 0x003010 0x0000000000001010 0x0000000000000000 0x000004 0x000004 R 0x1000 +# CHECK-NEXT: LOAD 0x003014 0x0000000000001014 0x0000000000000004 0x000008 0x000008 R 0x1000 +# CHECK-NEXT: LOAD 0x003024 0x0000000000001024 0x0000000000000014 0x000001 0x000001 R E 0x1000 + +# RUN: not ld.lld a.o -T err1.t 2>&1 | FileCheck %s --check-prefix=ERR1 --match-full-lines --strict-whitespace +# ERR1:{{.*}}error: err1.t:3: { expected, but got 0x3000 +# ERR1-NEXT:>>> .out.aaa 0x3000 : { *(.aaa) } +# ERR1-NEXT:>>> ^ + +# RUN: not ld.lld a.o -T err2.t 2>&1 | FileCheck %s --check-prefix=ERR2 --match-full-lines --strict-whitespace +# ERR2:{{.*}}error: err2.t:{{.*}}: { expected, but got AX +# ERR2-NEXT:>>> .out.aaa { *(.aaa) } > AX AT>FLASH +# ERR2-NEXT:>>> ^ + +#--- a.s +.globl _start +_start: + nop + +.section .small1, "a"; .long 0 +.section .big1, "a"; .quad 1 + +.section .small2, "a"; .long 0 +.section .big2, "a"; .quad 1 + +.section .small3, "a"; .long 0 +.section .big3, "a"; .quad 1 + +#--- a.t +SECTIONS { + OVERLAY 0x1000 : AT( 0x1000 ) { + .big1 { *(.big1) } + .small1 { *(.small1) } + } + OVERLAY 0x1008 : AT (0x2008) { + .small2 { *(.small2) } + .big2 { *(.big2) } + } + OVERLAY . : AT (0x2014) { + .empty3 { *(.empty3) } + .small3 { *(.small3) } + .big3 { *(.big3) } + } + .text : { *(.text) } +} + +#--- err1.t +SECTIONS { + OVERLAY 0x1000 : AT ( 0x2000 ) { + .out.aaa 0x3000 : { *(.aaa) } + } +} + +#--- err2.t +MEMORY { + AX (ax) : ORIGIN = 0x3000, LENGTH = 0x4000 +} +SECTIONS { + OVERLAY 0x1000 : AT ( 0x2000 ) { + .out.aaa { *(.aaa) } > AX AT>FLASH + } +} |