xref: /llvm-project/lld/test/ELF/linkerscript/memory-attr.test (revision 8cdf1c1edb937b192d162f299127fad8d9dc0faa)
1REQUIRES: x86
2
3RUN: split-file %s %ts
4RUN: llvm-mc -filetype=obj -triple=x86_64 %ts/s -o %t.o
5
6## Check assigning sections to memory regions by attributes.
7
8#--- s
9  .text
10  .zero 8
11
12  .rodata
13  .zero 8
14
15  .data
16  .zero 8
17
18#--- t1
19## Check memory region attribute 'a'.
20
21# RUN: ld.lld -o %t1 -T %ts/t1 %t.o
22# RUN: llvm-readelf -S %t1 | FileCheck %s --check-prefix=TEST1
23
24# TEST1:      Name     Type      Address
25# TEST1:      .text    PROGBITS  0000000000002000
26# TEST1-NEXT: .rodata  PROGBITS  0000000000002008
27# TEST1-NEXT: .data    PROGBITS  0000000000002010
28
29MEMORY
30{
31  ## All sections have SHF_ALLOC attribute, so no one can be added here.
32  NOMEM (rwx!a) : org = 0x1000, l = 1K
33  ## All sections are assigned to this memory region.
34  MEM   (a)     : org = 0x2000, l = 1K
35}
36
37SECTIONS
38{
39  .text   : { *(.text) }
40  .rodata : { *(.rodata) }
41  .data   : { *(.data) }
42}
43
44#--- t2
45## Check that memory region attributes 'r', 'w', and 'x' are supported both in
46## positive and negative forms.
47
48# RUN: ld.lld -o %t2 -T %ts/t2 %t.o
49# RUN: llvm-readelf -S %t2 | FileCheck %s --check-prefix=TEST2
50
51# TEST2:      Name     Type      Address
52# TEST2:      .text    PROGBITS  0000000000004000
53# TEST2-NEXT: .rodata  PROGBITS  0000000000003000
54# TEST2-NEXT: .data    PROGBITS  0000000000002000
55
56MEMORY
57{
58  ## While all sections are allocatable, '.text' and '.rodata' are read-only and
59  ## '.data' is writable, so no sections should be assigned to this region.
60  NOMEM (a!rw) : org = 0x1000, l = 1K
61  ## Only writable section '.data' is allowed here.
62  RAM   (w)    : org = 0x2000, l = 1K
63  ## Executable sections are not allowed here, so only '.rodata' should be
64  ## assigned to the region.
65  ROM   (r!x)  : org = 0x3000, l = 1K
66  ## An executable section '.text' comes here.
67  EXEC  (x)    : org = 0x4000, l = 1K
68}
69
70SECTIONS
71{
72  .text   : { *(.text) }
73  .rodata : { *(.rodata) }
74  .data   : { *(.data) }
75}
76