Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / x86-64-section-layout.s
blob37201279fa0a5d081aadc8992ec0adf79660f037
1 # REQUIRES: x86
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 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 a1 | FileCheck %s --check-prefix=CHECK1
15 # RUN: ld.lld -T b.lds -z norelro a.o -o b
16 # RUN: llvm-readelf -S -l b | FileCheck %s --check-prefix=CHECK2
18 # CHECK: Name Type Address Off Size ES Flg Lk Inf Al
19 # CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
20 # CHECK-NEXT: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
21 # CHECK-NEXT: .lrodata PROGBITS 0000000000200301 000301 000002 00 Al 0 0 1
22 # CHECK-NEXT: .rodata PROGBITS 0000000000200303 000303 000001 00 A 0 0 1
23 # CHECK-NEXT: .text PROGBITS 0000000000201304 000304 000001 00 AX 0 0 4
24 # CHECK-NEXT: .tdata PROGBITS 0000000000202305 000305 000001 00 WAT 0 0 1
25 # CHECK-NEXT: .tbss NOBITS 0000000000202306 000306 000002 00 WAT 0 0 1
26 # CHECK-NEXT: .relro_padding NOBITS 0000000000202306 000306 000cfa 00 WA 0 0 1
27 # CHECK-NEXT: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
28 # CHECK-NEXT: .bss NOBITS 0000000000203307 000307 001800 00 WA 0 0 1
29 ## We spend size(.bss) % MAXPAGESIZE bytes for .bss.
30 # CHECK-NEXT: .ldata PROGBITS 0000000000205b07 000b07 000002 00 WAl 0 0 1
31 # CHECK-NEXT: .ldata2 PROGBITS 0000000000205b09 000b09 000001 00 WAl 0 0 1
32 # CHECK-NEXT: .lbss NOBITS 0000000000205b0a 000b0a 000002 00 WAl 0 0 1
33 # CHECK-NEXT: .comment PROGBITS 0000000000000000 000b0a {{.*}} 01 MS 0 0 1
35 # CHECK: Program Headers:
36 # CHECK-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
37 # CHECK-NEXT: PHDR 0x000040 0x0000000000200040 0x0000000000200040 {{.*}} {{.*}} R 0x8
38 # CHECK-NEXT: LOAD 0x000000 0x0000000000200000 0x0000000000200000 0x000304 0x000304 R 0x1000
39 # CHECK-NEXT: LOAD 0x000304 0x0000000000201304 0x0000000000201304 0x000001 0x000001 R E 0x1000
40 # CHECK-NEXT: LOAD 0x000305 0x0000000000202305 0x0000000000202305 0x000001 0x000cfb RW 0x1000
41 # CHECK-NEXT: LOAD 0x000306 0x0000000000203306 0x0000000000203306 0x000001 0x001801 RW 0x1000
42 # CHECK-NEXT: LOAD 0x000b07 0x0000000000205b07 0x0000000000205b07 0x000003 0x000005 RW 0x1000
44 # CHECK1: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
45 # CHECK1-NEXT: .ldata PROGBITS 0000000000203307 000307 000002 00 WAl 0 0 1
46 # CHECK1-NEXT: .ldata2 PROGBITS 0000000000203309 000309 000001 00 WAl 0 0 1
47 # CHECK1-NEXT: .comment PROGBITS 0000000000000000 00030a {{.*}} 01 MS 0 0 1
49 # CHECK2: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
50 # CHECK2-NEXT: .lrodata PROGBITS 0000000000200301 000301 000001 00 Al 0 0 1
51 ## With a SECTIONS command, we suppress the default rule placing .lrodata.* into .lrodata.
52 # CHECK2-NEXT: .lrodata.1 PROGBITS 0000000000200302 000302 000001 00 Al 0 0 1
53 # CHECK2-NEXT: .rodata PROGBITS 0000000000200303 000303 000001 00 A 0 0 1
54 # CHECK2-NEXT: .text PROGBITS 0000000000200304 000304 000001 00 AX 0 0 4
55 # CHECK2-NEXT: .tdata PROGBITS 0000000000200305 000305 000001 00 WAT 0 0 1
56 # CHECK2-NEXT: .tbss NOBITS 0000000000200306 000306 000001 00 WAT 0 0 1
57 # CHECK2-NEXT: .tbss.1 NOBITS 0000000000200307 000306 000001 00 WAT 0 0 1
58 # CHECK2-NEXT: .data PROGBITS 0000000000200306 000306 000001 00 WA 0 0 1
59 # CHECK2-NEXT: .bss NOBITS 0000000000200307 000307 001800 00 WA 0 0 1
60 # CHECK2-NEXT: .ldata PROGBITS 0000000000201b07 001b07 000002 00 WAl 0 0 1
61 # CHECK2-NEXT: .ldata2 PROGBITS 0000000000201b09 001b09 000001 00 WAl 0 0 1
62 # CHECK2-NEXT: .lbss NOBITS 0000000000201b0a 001b0a 000002 00 WAl 0 0 1
63 # CHECK2-NEXT: .comment PROGBITS 0000000000000000 001b0a {{.*}} 01 MS 0 0 1
65 # CHECK2: Program Headers:
66 # CHECK2-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
67 # CHECK2-NEXT: PHDR 0x000040 0x0000000000200040 0x0000000000200040 {{.*}} {{.*}} R 0x8
68 # CHECK2-NEXT: LOAD 0x000000 0x0000000000200000 0x0000000000200000 0x000304 0x000304 R 0x1000
69 # CHECK2-NEXT: LOAD 0x000304 0x0000000000200304 0x0000000000200304 0x000001 0x000001 R E 0x1000
70 # CHECK2-NEXT: LOAD 0x000305 0x0000000000200305 0x0000000000200305 0x001805 0x001807 RW 0x1000
71 # CHECK2-NEXT: TLS 0x000305 0x0000000000200305 0x0000000000200305 0x000001 0x000003 R 0x1
73 #--- a.s
74 .globl _start
75 _start:
76 ret
78 .section .note,"a",@note; .space 1
79 .section .rodata,"a",@progbits; .space 1
80 .section .data,"aw",@progbits; .space 1
81 .ifdef BSS
82 ## .bss is large than one MAXPAGESIZE to test file offsets.
83 .section .bss,"aw",@nobits; .space 0x1800
84 .endif
85 .section .tdata,"awT",@progbits; .space 1
86 .section .tbss,"awT",@nobits; .space 1
87 .section .tbss.1,"awT",@nobits; .space 1
89 .section .lrodata,"al"; .space 1
90 .section .lrodata.1,"al"; .space 1
91 .section .ldata,"awl"; .space 1
92 ## Input .ldata.rel.ro sections are placed in the output .ldata section.
93 .section .ldata.rel.ro,"awl"; .space 1
94 .ifdef BSS
95 .section .lbss,"awl",@nobits; .space 1
96 ## Input .lbss.rel.ro sections are placed in the output .lbss section.
97 .section .lbss.rel.ro,"awl",@nobits; .space 1
98 .endif
99 .section .ldata2,"awl"; .space 1
101 #--- b.lds
102 SECTIONS {
103 . = 0x200300;
104 .rodata : {}
105 .text : {}
106 .data : {}
107 .bss : {}
108 .ldata : { *(.ldata .ldata.*) }
109 .ldata2 : {}
110 .lbss : { *(.lbss .lbss.*) }