1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3# RUN: echo "MEMORY {                                  \
4# RUN:   ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100    \
5# RUN:   RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100    \
6# RUN: }                                               \
7# RUN: INCLUDE \"%t.script.inc\"                       \
8# RUN: SECTIONS {                                      \
9# RUN:  .text : { *(.text*) } > ALIAS_TEXT             \
10# RUN:  .data : { *(.data*) } > ALIAS_DATA             \
11# RUN: }" > %t.script
12
13## .text to ROM, .data to RAM.
14# RUN: echo "REGION_ALIAS (\"ALIAS_TEXT\", ROM);" > %t.script.inc
15# RUN: echo "REGION_ALIAS (\"ALIAS_DATA\", RAM);" >> %t.script.inc
16# RUN: ld.lld %t --script %t.script -o %t2
17# RUN: llvm-objdump --section-headers %t2 | FileCheck %s
18# CHECK: .text       00000001 0000000000001000 TEXT
19# CHECK: .data       00000008 0000000000002000 DATA
20
21## All to ROM.
22# RUN: echo "REGION_ALIAS (\"ALIAS_TEXT\", ROM);" > %t.script.inc
23# RUN: echo "REGION_ALIAS (\"ALIAS_DATA\", ROM);" >> %t.script.inc
24# RUN: ld.lld %t --script %t.script -o %t2
25# RUN: llvm-objdump --section-headers %t2 | FileCheck %s --check-prefix=RAM
26# RAM: .text         00000001 0000000000001000 TEXT
27# RAM: .data         00000008 0000000000001001 DATA
28
29## Redefinition of region.
30# RUN: echo "REGION_ALIAS (\"ROM\", ROM);" > %t.script.inc
31# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
32# RUN:   FileCheck %s --check-prefix=ERR1
33# ERR1: {{.*}}script.inc:1: redefinition of memory region 'ROM'
34
35## Redefinition of alias.
36# RUN: echo "REGION_ALIAS (\"ALIAS_TEXT\", ROM);" > %t.script.inc
37# RUN: echo "REGION_ALIAS (\"ALIAS_TEXT\", ROM);" >> %t.script.inc
38# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
39# RUN:   FileCheck %s --check-prefix=ERR2
40# ERR2: {{.*}}script.inc:2: redefinition of memory region 'ALIAS_TEXT'
41
42## Attemp to create an alias for undefined region.
43# RUN: echo "REGION_ALIAS (\"ALIAS_TEXT\", FOO);" > %t.script.inc
44# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
45# RUN:   FileCheck %s --check-prefix=ERR3
46# ERR3: {{.*}}script.inc:1: memory region 'FOO' is not defined
47
48.text
49.global _start
50_start:
51 nop
52
53.section .data,"aw"
54.quad 0
55