2 ## Test the placement of .lrodata, .lbss, .ldata, and their -fdata-sections variants.
3 ## See also section-layout.s.
5 # RUN: rm -rf %t && split-file %s %t && cd %t
7 # RUN: llvm-mc -filetype=obj -triple=x86_64 --defsym=BSS=1 a.s -o a.o
8 # RUN: ld.lld --section-start=.note=0x200300 a.o -o a
9 # RUN: llvm-readelf -S -l -sX a | FileCheck %s
11 # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a1.o
12 # RUN: ld.lld --section-start=.note=0x200300 a1.o -o a1
13 # RUN: llvm-readelf -S -sX a1 | FileCheck %s --check-prefix=CHECK1
15 # RUN: ld.lld -T b.lds -z norelro a.o -z lrodata-after-bss -z nolrodata-after-bss -o b --fatal-warnings
16 # RUN: llvm-readelf -S -l b | FileCheck %s --check-prefix=CHECK2
18 # RUN: ld.lld --section-start=.note=0x200300 a.o -z lrodata-after-bss -o a3
19 # RUN: llvm-readelf -S -l -sX a3 | FileCheck %s --check-prefix=CHECK3
21 # CHECK: Name Type Address Off Size ES Flg Lk Inf Al
22 # CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
23 # CHECK-NEXT: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
24 # CHECK-NEXT: .lrodata PROGBITS 0000000000200301 000301 000002 00 Al 0 0 1
25 # CHECK-NEXT: .rodata PROGBITS 0000000000200303 000303 000001 00 A 0 0 1
26 # CHECK-NEXT: .text PROGBITS 0000000000201304 000304 000001 00 AX 0 0 4
27 # CHECK-NEXT: .tdata PROGBITS 0000000000202305 000305 000001 00 WAT 0 0 1
28 # CHECK-NEXT: .tbss NOBITS 0000000000202306 000306 000002 00 WAT 0 0 1
29 # CHECK-NEXT: .relro_padding NOBITS 0000000000202306 000306 000cfa 00 WA 0 0 1
30 # CHECK-NEXT: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
31 # CHECK-NEXT: .bss NOBITS 0000000000203307 000307 001800 00 WA 0 0 1
32 ## We spend size(.bss) % MAXPAGESIZE bytes for .bss.
33 # CHECK-NEXT: .ldata PROGBITS 0000000000205b07 000b07 000002 00 WAl 0 0 1
34 # CHECK-NEXT: .ldata2 PROGBITS 0000000000205b09 000b09 000001 00 WAl 0 0 1
35 # CHECK-NEXT: .lbss NOBITS 0000000000205b0a 000b0a 001201 00 WAl 0 0 1
36 # CHECK-NEXT: .comment PROGBITS 0000000000000000 000b0a {{.*}} 01 MS 0 0 1
38 # CHECK: Program Headers:
39 # CHECK-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
40 # CHECK-NEXT: PHDR 0x000040 0x0000000000200040 0x0000000000200040 {{.*}} {{.*}} R 0x8
41 # CHECK-NEXT: LOAD 0x000000 0x0000000000200000 0x0000000000200000 0x000304 0x000304 R 0x1000
42 # CHECK-NEXT: LOAD 0x000304 0x0000000000201304 0x0000000000201304 0x000001 0x000001 R E 0x1000
43 # CHECK-NEXT: LOAD 0x000305 0x0000000000202305 0x0000000000202305 0x000001 0x000cfb RW 0x1000
44 # CHECK-NEXT: LOAD 0x000306 0x0000000000203306 0x0000000000203306 0x000001 0x001801 RW 0x1000
45 # CHECK-NEXT: LOAD 0x000b07 0x0000000000205b07 0x0000000000205b07 0x000003 0x001204 RW 0x1000
47 # CHECK: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
48 # CHECK-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
49 # CHECK-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
50 # CHECK-NEXT: 0000000000206d0b 0 NOTYPE GLOBAL DEFAULT [[#]] (.lbss) _end
52 # CHECK1: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
53 # CHECK1-NEXT: .ldata PROGBITS 0000000000203307 000307 000002 00 WAl 0 0 1
54 # CHECK1-NEXT: .ldata2 PROGBITS 0000000000203309 000309 000001 00 WAl 0 0 1
55 # CHECK1-NEXT: .comment PROGBITS 0000000000000000 00030a {{.*}} 01 MS 0 0 1
57 # CHECK1: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
58 # CHECK1-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
59 # CHECK1-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
60 # CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _end
62 # CHECK2: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
63 # CHECK2-NEXT: .lrodata PROGBITS 0000000000200301 000301 000001 00 Al 0 0 1
64 ## With a SECTIONS command, we suppress the default rule placing .lrodata.* into .lrodata.
65 # CHECK2-NEXT: .lrodata.1 PROGBITS 0000000000200302 000302 000001 00 Al 0 0 1
66 # CHECK2-NEXT: .rodata PROGBITS 0000000000200303 000303 000001 00 A 0 0 1
67 # CHECK2-NEXT: .text PROGBITS 0000000000200304 000304 000001 00 AX 0 0 4
68 # CHECK2-NEXT: .tdata PROGBITS 0000000000200305 000305 000001 00 WAT 0 0 1
69 # CHECK2-NEXT: .tbss NOBITS 0000000000200306 000306 000001 00 WAT 0 0 1
70 # CHECK2-NEXT: .tbss.1 NOBITS 0000000000200307 000306 000001 00 WAT 0 0 1
71 # CHECK2-NEXT: .data PROGBITS 0000000000200306 000306 000001 00 WA 0 0 1
72 # CHECK2-NEXT: .bss NOBITS 0000000000200307 000307 001800 00 WA 0 0 1
73 # CHECK2-NEXT: .ldata PROGBITS 0000000000201b07 001b07 000002 00 WAl 0 0 1
74 # CHECK2-NEXT: .ldata2 PROGBITS 0000000000201b09 001b09 000001 00 WAl 0 0 1
75 # CHECK2-NEXT: .lbss NOBITS 0000000000201b0a 001b0a 001201 00 WAl 0 0 1
76 # CHECK2-NEXT: .comment PROGBITS 0000000000000000 001b0a {{.*}} 01 MS 0 0 1
78 # CHECK2: Program Headers:
79 # CHECK2-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
80 # CHECK2-NEXT: PHDR 0x000040 0x0000000000200040 0x0000000000200040 {{.*}} {{.*}} R 0x8
81 # CHECK2-NEXT: LOAD 0x000000 0x0000000000200000 0x0000000000200000 0x000304 0x000304 R 0x1000
82 # CHECK2-NEXT: LOAD 0x000304 0x0000000000200304 0x0000000000200304 0x000001 0x000001 R E 0x1000
83 # CHECK2-NEXT: LOAD 0x000305 0x0000000000200305 0x0000000000200305 0x001805 0x002a06 RW 0x1000
84 # CHECK2-NEXT: TLS 0x000305 0x0000000000200305 0x0000000000200305 0x000001 0x000003 R 0x1
86 # CHECK3: Name Type Address Off Size ES Flg Lk Inf Al
87 # CHECK3-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
88 # CHECK3-NEXT: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
89 # CHECK3-NEXT: .rodata PROGBITS 0000000000200301 000301 000001 00 A 0 0 1
90 # CHECK3-NEXT: .text PROGBITS 0000000000201304 000304 000001 00 AX 0 0 4
91 # CHECK3-NEXT: .tdata PROGBITS 0000000000202305 000305 000001 00 WAT 0 0 1
92 # CHECK3-NEXT: .tbss NOBITS 0000000000202306 000306 000002 00 WAT 0 0 1
93 # CHECK3-NEXT: .relro_padding NOBITS 0000000000202306 000306 000cfa 00 WA 0 0 1
94 # CHECK3-NEXT: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
95 # CHECK3-NEXT: .bss NOBITS 0000000000203307 000307 001800 00 WA 0 0 1
96 ## We spend (size(.bss) + size(.lbss)) % MAXPAGESIZE bytes.
97 # CHECK3-NEXT: .lbss NOBITS 0000000000204b07 000307 001201 00 WAl 0 0 1
98 # CHECK3-NEXT: .lrodata PROGBITS 0000000000206d08 000d08 000002 00 Al 0 0 1
99 # CHECK3-NEXT: .ldata PROGBITS 0000000000207d0a 000d0a 000002 00 WAl 0 0 1
100 # CHECK3-NEXT: .ldata2 PROGBITS 0000000000207d0c 000d0c 000001 00 WAl 0 0 1
101 # CHECK3-NEXT: .comment PROGBITS 0000000000000000 000d0d {{.*}} 01 MS 0 0 1
103 # CHECK3: Program Headers:
104 # CHECK3-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
105 # CHECK3-NEXT: PHDR 0x000040 0x0000000000200040 0x0000000000200040 {{.*}} {{.*}} R 0x8
106 # CHECK3-NEXT: LOAD 0x000000 0x0000000000200000 0x0000000000200000 0x000302 0x000302 R 0x1000
107 # CHECK3-NEXT: LOAD 0x000304 0x0000000000201304 0x0000000000201304 0x000001 0x000001 R E 0x1000
108 # CHECK3-NEXT: LOAD 0x000305 0x0000000000202305 0x0000000000202305 0x000001 0x000cfb RW 0x1000
109 # CHECK3-NEXT: LOAD 0x000306 0x0000000000203306 0x0000000000203306 0x000001 0x002a02 RW 0x1000
110 # CHECK3-NEXT: LOAD 0x000d08 0x0000000000206d08 0x0000000000206d08 0x000002 0x000002 R 0x1000
111 # CHECK3-NEXT: LOAD 0x000d0a 0x0000000000207d0a 0x0000000000207d0a 0x000003 0x000003 RW 0x1000
112 # CHECK3-NEXT: TLS 0x000305 0x0000000000202305 0x0000000000202305 0x000001 0x000003 R 0x1
114 # CHECK3: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
115 # CHECK3-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
116 # CHECK3-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
117 # CHECK3-NEXT: 0000000000207d0d 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _end
120 .globl _start, _etext, _edata, _end
124 .section .note,"a",@note; .space 1
125 .section .rodata,"a",@progbits; .space 1
126 .section .data,"aw",@progbits; .space 1
128 ## .bss is large than one MAXPAGESIZE to test file offsets.
129 .section .bss,"aw",@nobits; .space 0x1800
131 .section .tdata,"awT",@progbits; .space 1
132 .section .tbss,"awT",@nobits; .space 1
133 .section .tbss.1,"awT",@nobits; .space 1
135 .section .lrodata,"al"; .space 1
136 .section .lrodata.1,"al"; .space 1
137 .section .ldata,"awl"; .space 1
138 ## Input .ldata.rel.ro sections are placed in the output .ldata section.
139 .section .ldata.rel.ro,"awl"; .space 1
141 .section .lbss,"awl",@nobits; .space 0x1200
142 ## Input .lbss.rel.ro sections are placed in the output .lbss section.
143 .section .lbss.rel.ro,"awl",@nobits; .space 1
145 .section .ldata2,"awl"; .space 1
154 .ldata : { *(.ldata .ldata.*) }
156 .lbss : { *(.lbss .lbss.*) }