[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / linkerscript / memory.s
blobe3c19bc3d03a4402ed36a8fe556835f37bf0980d
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
4 ## Check simple RAM-only memory region.
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-readelf -S %t1 | FileCheck --check-prefix=RAM %s
14 # RAM: [ 1] .text PROGBITS 0000000000008000 001000 000001
15 # RAM-NEXT: [ 2] .data PROGBITS 0000000000008001 001001 001000
17 ## Check RAM and ROM memory regions.
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-readelf -S %t1 | FileCheck --check-prefix=RAMROM %s
30 # RAMROM: [ 1] .text PROGBITS 0000000080000000 001000 000001
31 # RAMROM-NEXT: [ 2] .data PROGBITS 0000000000000000 002000 001000
33 ## Check memory region placement by attributes.
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-readelf -S %t1 | FileCheck --check-prefix=ATTRS %s
46 # ATTRS: [ 1] .text PROGBITS 0000000080000000 001000 000001
47 # ATTRS-NEXT: [ 2] .data PROGBITS 0000000000000000 002000 001000
49 ## ORIGIN/LENGTH support expressions with symbol assignments.
50 # RUN: echo 'MEMORY { ram : ORIGIN = symbol, LENGTH = 4097 } \
51 # RUN: SECTIONS { \
52 # RUN: .text : { *(.text) } > ram \
53 # RUN: .data : { *(.data) } > ram \
54 # RUN: }' > %t.script
55 # RUN: ld.lld -T %t.script %t --defsym symbol=0x5000 -o %t.relro
56 # RUN: llvm-readelf -S %t.relro | FileCheck --check-prefix=RELRO %s
57 # RUN: echo 'symbol = 0x5000;' > %t1.script
58 # RUN: ld.lld -T %t.script -T %t1.script %t -o %t.relro2
59 # RUN: llvm-readelf -S %t.relro2 | FileCheck --check-prefix=RELRO %s
61 # RELRO: [ 1] .text PROGBITS 0000000000005000 001000 000001
62 # RELRO-NEXT: [ 2] .data PROGBITS 0000000000005001 001001 001000
64 # RUN: echo 'MEMORY { ram : ORIGIN = CONSTANT(COMMONPAGESIZE), LENGTH = CONSTANT(COMMONPAGESIZE)+1 } \
65 # RUN: SECTIONS { \
66 # RUN: .text : { *(.text) } > ram \
67 # RUN: .data : { *(.data) } > ram \
68 # RUN: }' > %t.script
69 # RUN: ld.lld -T %t.script %t -o %t.pagesize
70 # RUN: llvm-readelf -S %t.pagesize | FileCheck --check-prefix=PAGESIZE %s
72 # PAGESIZE: [ 1] .text PROGBITS 0000000000001000 001000 000001
73 # PAGESIZE-NEXT: [ 2] .data PROGBITS 0000000000001001 001001 001000
75 .text
76 .global _start
77 _start:
78 nop
80 .data
82 .long 1
83 .zero 4092