xref: /llvm-project/lld/test/ELF/linkerscript/overlay.test (revision e6895154914adf32fc4d805cffdf0bec084ae711)
1# REQUIRES: x86
2# RUN: rm -rf %t && split-file %s %t && cd %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
4# RUN: ld.lld a.o -T a.t -o a
5
6## Here we check that can handle OVERLAY which will produce sections
7## .out.big and .out.small with the same starting VAs, but different LMAs.
8## Section .big is larger than .small, we check that placing of section
9## .text does not cause overlapping error and that
10## .text's VA is 0x1000 + max(sizeof(.out.big), sizeof(.out.small)).
11
12# RUN: llvm-readelf --sections -l a | FileCheck %s
13
14# CHECK:      Name       Type     Address          Off    Size
15# CHECK:      .big1      PROGBITS 0000000000001000 001000 000008
16# CHECK-NEXT: .small1    PROGBITS 0000000000001000 002000 000004
17# CHECK-NEXT: .small2    PROGBITS 0000000000001008 002008 000004
18# CHECK-NEXT: .big2      PROGBITS 0000000000001008 003008 000008
19# CHECK-NEXT: .empty3    PROGBITS 0000000000001010 003010 000000
20# CHECK-NEXT: .small3    PROGBITS 0000000000001010 003010 000004
21# CHECK-NEXT: .big3      PROGBITS 0000000000001010 004010 000008
22# CHECK-NEXT: .text      PROGBITS 0000000000001018 004018 000001
23
24# CHECK:      Program Headers:
25# CHECK:      Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
26# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000008 0x000008 R   0x1000
27# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000001008 0x000004 0x000004 R   0x1000
28# CHECK-NEXT: LOAD 0x002008 0x0000000000001008 0x0000000000002008 0x000004 0x000004 R   0x1000
29# CHECK-NEXT: LOAD 0x003008 0x0000000000001008 0x000000000000200c 0x000008 0x000008 R   0x1000
30# CHECK-NEXT: LOAD 0x003010 0x0000000000001010 0x0000000000002014 0x000004 0x000004 R   0x1000
31# CHECK-NEXT: LOAD 0x004010 0x0000000000001010 0x0000000000002018 0x000008 0x000008 R   0x1000
32# CHECK-NEXT: LOAD 0x004018 0x0000000000001018 0x0000000000002020 0x000001 0x000001 R E 0x1000
33
34# RUN: not ld.lld a.o -T err1.t 2>&1 | FileCheck %s --check-prefix=ERR1 --match-full-lines --strict-whitespace
35#      ERR1:{{.*}}error: err1.t:3: { expected, but got 0x3000
36# ERR1-NEXT:>>>     .out.aaa 0x3000 : { *(.aaa) }
37# ERR1-NEXT:>>>              ^
38
39# RUN: not ld.lld a.o -T err2.t 2>&1 | FileCheck %s --check-prefix=ERR2 --match-full-lines --strict-whitespace
40#      ERR2:{{.*}}error: err2.t:{{.*}}: { expected, but got AX
41# ERR2-NEXT:>>>     .out.aaa { *(.aaa) } > AX AT>FLASH
42# ERR2-NEXT:>>>                            ^
43
44#--- a.s
45.globl _start
46_start:
47  nop
48
49.section .small1, "a"; .long 0
50.section .big1, "a"; .quad 1
51
52.section .small2, "a"; .long 0
53.section .big2, "a"; .quad 1
54
55.section .small3, "a"; .long 0
56.section .big3, "a"; .quad 1
57
58#--- a.t
59SECTIONS {
60## LMA defaults to VMA
61  OVERLAY 0x1000 : {
62    ".big1" { *(".big1") }
63    .small1 { *(.small1) }
64  }
65## .big2 starts at ADDR(.small2)
66  OVERLAY : AT (0x2008) {
67    .small2 { *(.small2) }
68    ".big2" { *(.big2) }
69  }
70## .empty3 is not discarded. .small3 and .big3 share its address.
71  OVERLAY . : AT (0x2014) {
72    .empty3 { *(.empty3) }
73    .small3 { *(.small3) }
74    .big3 { *(.big3) }
75  }
76  .text : { *(.text) }
77}
78
79#--- err1.t
80SECTIONS {
81  OVERLAY 0x1000 : AT ( 0x2000 ) {
82    .out.aaa 0x3000 : { *(.aaa) }
83  }
84}
85
86#--- err2.t
87MEMORY {
88  AX (ax)    : ORIGIN = 0x3000, LENGTH = 0x4000
89}
90SECTIONS {
91  OVERLAY 0x1000 : AT ( 0x2000 ) {
92    .out.aaa { *(.aaa) } > AX AT>FLASH
93  }
94}
95
96#--- unclosed.lds
97SECTIONS {
98  OVERLAY 0x1000 : AT ( 0x2000 ) {
99
100# RUN: not ld.lld a.o -T unclosed.lds 2>&1 | FileCheck %s --check-prefix=UNCLOSED
101# UNCLOSED:     error: unclosed.lds:2: unexpected EOF
102# UNCLOSED-NOT: {{.}}
103