1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3
4## Check simple RAM-only memory region.
5
6# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0x8000, LENGTH = 256K } \
7# RUN: SECTIONS { \
8# RUN:   .text : { *(.text) } > ram \
9# RUN:   .data : { *(.data) } > ram \
10# RUN: }" > %t.script
11# RUN: ld.lld -o %t1 --script %t.script %t
12# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=RAM %s
13
14# RAM:       1 .text         00000001 0000000000008000 TEXT DATA
15# RAM-NEXT:  2 .data         00001000 0000000000008001 DATA
16
17## Check RAM and ROM memory regions.
18
19# RUN: echo "MEMORY { \
20# RUN:   ram (rwx) : ORIGIN = 0, LENGTH = 1024M \
21# RUN:   rom (rx) : org = (0x80 * 0x1000 * 0x1000), len = 64M \
22# RUN: } \
23# RUN: SECTIONS { \
24# RUN:   .text : { *(.text) } > rom \
25# RUN:   .data : { *(.data) } > ram \
26# RUN: }" > %t.script
27# RUN: ld.lld -o %t1 --script %t.script %t
28# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=RAMROM %s
29
30# RAMROM:       1 .text         00000001 0000000080000000 TEXT DATA
31# RAMROM-NEXT:  2 .data         00001000 0000000000000000 DATA
32
33## Check memory region placement by attributes.
34
35# RUN: echo "MEMORY { \
36# RUN:   ram (!rx) : ORIGIN = 0, LENGTH = 1024M \
37# RUN:   rom (rx) : o = 0x80000000, l = 64M \
38# RUN: } \
39# RUN: SECTIONS { \
40# RUN:   .text : { *(.text) } \
41# RUN:   .data : { *(.data) } > ram \
42# RUN: }" > %t.script
43# RUN: ld.lld -o %t1 --script %t.script %t
44# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=ATTRS %s
45
46# ATTRS:  1 .text         00000001 0000000080000000 TEXT DATA
47# ATTRS:  2 .data         00001000 0000000000000000 DATA
48
49## Check bad `ORIGIN`.
50
51# RUN: echo "MEMORY { ram (rwx) : XYZ = 0x8000 } }" > %t.script
52# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
53# RUN:  | FileCheck -check-prefix=ERR1 %s
54# ERR1: {{.*}}.script:1: expected one of: ORIGIN, org, or o
55
56## Check bad `LENGTH`.
57
58# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0x8000, XYZ = 256K } }" > %t.script
59# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
60# RUN:  | FileCheck -check-prefix=ERR2 %s
61# ERR2: {{.*}}.script:1: expected one of: LENGTH, len, or l
62
63## Check duplicate regions.
64
65# RUN: echo "MEMORY { ram (rwx) : o = 8, l = 256K ram (rx) : o = 0, l = 256K }" > %t.script
66# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
67# RUN:  | FileCheck -check-prefix=ERR3 %s
68# ERR3: {{.*}}.script:1: region 'ram' already defined
69
70## Check no region available.
71
72# RUN: echo "MEMORY { ram (!rx) : ORIGIN = 0x8000, LENGTH = 256K } \
73# RUN: SECTIONS { \
74# RUN:   .text : { *(.text) } \
75# RUN:   .data : { *(.data) } > ram \
76# RUN: }" > %t.script
77# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
78# RUN:  | FileCheck -check-prefix=ERR4 %s
79# ERR4: {{.*}}: no memory region specified for section '.text'
80
81## Check undeclared region.
82
83# RUN: echo "SECTIONS { .text : { *(.text) } > ram }" > %t.script
84# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
85# RUN:  | FileCheck -check-prefix=ERR5 %s
86# ERR5: {{.*}}: memory region 'ram' not declared
87
88## Check region overflow.
89
90# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0, LENGTH = 2K } \
91# RUN: SECTIONS { \
92# RUN:   .text : { *(.text) } > ram \
93# RUN:   .data : { *(.data) } > ram \
94# RUN: }" > %t.script
95# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
96# RUN:  | FileCheck -check-prefix=ERR6 %s
97# ERR6: {{.*}}: section '.data' will not fit in region 'ram': overflowed by 2049 bytes
98
99## Check invalid region attributes.
100
101# RUN: echo "MEMORY { ram (abc) : ORIGIN = 8000, LENGTH = 256K } }" > %t.script
102# RUN: not ld.lld -o %t2 --script %t.script %t 2>&1 \
103# RUN:  | FileCheck -check-prefix=ERR7 %s
104# ERR7: {{.*}}.script:1: invalid memory region attribute
105
106.text
107.global _start
108_start:
109  nop
110
111.data
112b:
113  .long 1
114  .zero 4092
115