Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / partition-synthetic-sections.s
blobd38597856e165ef13a770c4250d7a02859dcbd66
1 // Test that synthetic sections are created correctly for each partition.
3 // REQUIRES: x86
5 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/verneed1.s -o %t1.o
6 // RUN: echo "v1 {}; v2 {}; v3 { global: f1; local: *; };" > %t1.script
7 // RUN: ld.lld -shared %t1.o --version-script %t1.script -o %t1.so -soname verneed1.so.0 -z separate-code
9 // RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
10 // RUN: echo "x1 { global: p0; }; x2 { global: p1; p1alias; };" > %t.script
11 // RUN: ld.lld %t.o %t1.so --version-script %t.script -o %t --shared --gc-sections --eh-frame-hdr -soname main.so -z separate-code
13 // RUN: llvm-objcopy --extract-main-partition %t %t0
14 // RUN: llvm-objcopy --extract-partition=part1 %t %t1
16 // RUN: llvm-readelf --all --unwind %t0 | FileCheck --check-prefixes=CHECK,PART0 %s
17 // RUN: llvm-readelf --all --unwind %t1 | FileCheck --check-prefixes=CHECK,PART1 %s
19 // FIXME: llvm-objcopy does not preserve padding (see pr42145) so for now we
20 // check the combined output file.
21 // RUN: od -Ax -x %t | FileCheck %s -check-prefix=FILL
23 // RUN: llvm-objdump -s -j .rodata -j .dynstr %t0 | FileCheck --check-prefix=PART-INDEX %s
25 // CHECK: Section Headers:
26 // CHECK-NEXT: Name
27 // CHECK-NEXT: NULL
28 // CHECK-NEXT: .dynsym DYNSYM {{0*}}[[DYNSYM_ADDR:[^ ]*]]
29 // CHECK-NEXT: .gnu.version VERSYM {{0*}}[[VERSYM_ADDR:[^ ]*]]
30 // CHECK-NEXT: .gnu.version_d VERDEF {{0*}}[[VERDEF_ADDR:[^ ]*]]
31 // CHECK-NEXT: .gnu.version_r VERNEED {{0*}}[[VERNEED_ADDR:[^ ]*]]
32 // CHECK-NEXT: .gnu.hash GNU_HASH {{0*}}[[GNU_HASH_ADDR:[^ ]*]]
33 // CHECK-NEXT: .hash HASH {{0*}}[[HASH_ADDR:[^ ]*]]
34 // CHECK-NEXT: .dynstr STRTAB {{0*}}[[DYNSTR_ADDR:[^ ]*]]
35 // CHECK-NEXT: .rela.dyn RELA {{0*}}[[RELA_DYN_ADDR:[^ ]*]]
36 // PART0-NEXT: .rela.plt RELA {{0*}}[[RELA_PLT_ADDR:[^ ]*]]
37 // CHECK-NEXT: .eh_frame_hdr PROGBITS {{0*}}[[EH_FRAME_HDR_ADDR:[^ ]*]]
38 // CHECK-NEXT: .eh_frame PROGBITS {{0*}}[[EH_FRAME_ADDR:[^ ]*]]
39 // PART0-NEXT: .rodata PROGBITS
40 // CHECK-NEXT: .text PROGBITS {{0*}}[[TEXT_ADDR:[^ ]*]]
41 // PART0-NEXT: .plt PROGBITS
42 // PART0-NEXT: .init_array INIT_ARRAY {{0*}}[[INIT_ARRAY_ADDR:[^ ]*]]
43 // CHECK-NEXT: .dynamic DYNAMIC {{0*}}[[DYNAMIC_ADDR:[^ ]*]]
44 // PART0-NEXT: .relro_padding NOBITS
45 // PART0-NEXT: .data PROGBITS 000000000000[[DATA_SEGMENT:.]]178
46 // PART1-NEXT: .data PROGBITS 000000000000[[DATA_SEGMENT:.]]130
47 // PART0-NEXT: .got.plt PROGBITS {{0*}}[[GOT_PLT_ADDR:[^ ]*]]
48 // PART0-NEXT: .part.end NOBITS {{0*}}[[PART_END_ADDR:[^ ]*]]
49 // CHECK-NEXT: .comment PROGBITS
50 // CHECK-NEXT: .symtab SYMTAB
51 // CHECK-NEXT: .shstrtab STRTAB
52 // CHECK-NEXT: .strtab STRTAB
53 // CHECK-NEXT: Key to Flags
55 // CHECK: Program Headers:
56 // CHECK-NEXT: Type
57 // PART0-NEXT: PHDR {{.*}} 0x000230 0x000230 R
58 // PART1-NEXT: PHDR {{.*}} 0x0001f8 0x0001f8 R
59 // PART0-NEXT: LOAD 0x000000 0x0000000000000000 0x0000000000000000 {{.*}} R 0x1000
60 // PART0-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 {{.*}} R E 0x1000
61 // PART0-NEXT: LOAD 0x002000 0x0000000000002000 0x0000000000002000 {{.*}} RW 0x1000
62 // PART0-NEXT: LOAD 0x002178 0x0000000000003178 0x0000000000003178 {{.*}} RW 0x1000
63 // PART0-NEXT: LOAD 0x003150 0x0000000000008150 0x0000000000008150 0x000000 0x001000 RW 0x1000
64 // PART1-NEXT: LOAD 0x000000 0x0000000000004000 0x0000000000004000 {{.*}} R 0x1000
65 // PART1-NEXT: LOAD 0x001000 0x0000000000005000 0x0000000000005000 {{.*}} R E 0x1000
66 // PART1-NEXT: LOAD 0x002000 0x0000000000006000 0x0000000000006000 {{.*}} RW 0x1000
67 // PART1-NEXT: LOAD 0x002130 0x0000000000007130 0x0000000000007130 {{.*}} RW 0x1000
68 // CHECK-NEXT: DYNAMIC {{.*}} 0x{{0*}}[[DYNAMIC_ADDR]] 0x{{0*}}[[DYNAMIC_ADDR]] {{.*}} RW 0x8
69 // PART0-NEXT: GNU_RELRO 0x002000 0x0000000000002000 0x0000000000002000 {{.*}} R 0x1
70 // PART1-NEXT: GNU_RELRO 0x002000 0x0000000000006000 0x0000000000006000 {{.*}} R 0x1
71 // CHECK-NEXT: GNU_EH_FRAME {{.*}} 0x{{0*}}[[EH_FRAME_HDR_ADDR]] 0x{{0*}}[[EH_FRAME_HDR_ADDR]] {{.*}} R 0x4
72 // CHECK-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x0
73 // CHECK-EMPTY:
75 // CHECK: Dynamic section
76 // CHECK-NEXT: Tag
77 // CHECK-NEXT: 0x0000000000000001 (NEEDED) Shared library: [verneed1.so.0]
78 // PART0-NEXT: 0x000000000000000e (SONAME) Library soname: [main.so]
79 // PART1-NEXT: 0x0000000000000001 (NEEDED) Shared library: [main.so]
80 // PART1-NEXT: 0x000000000000000e (SONAME) Library soname: [part1]
81 // CHECK-NEXT: 0x0000000000000007 (RELA) 0x[[RELA_DYN_ADDR]]
82 // CHECK-NEXT: 0x0000000000000008 (RELASZ)
83 // CHECK-NEXT: 0x0000000000000009 (RELAENT) 24 (bytes)
84 // PART1-NEXT: 0x000000006ffffff9 (RELACOUNT) 1
85 // PART0-NEXT: 0x0000000000000017 (JMPREL) 0x[[RELA_PLT_ADDR]]
86 // PART0-NEXT: 0x0000000000000002 (PLTRELSZ) 48 (bytes)
87 // PART0-NEXT: 0x0000000000000003 (PLTGOT) 0x[[GOT_PLT_ADDR]]
88 // PART0-NEXT: 0x0000000000000014 (PLTREL) RELA
89 // CHECK-NEXT: 0x0000000000000006 (SYMTAB) 0x[[DYNSYM_ADDR]]
90 // CHECK-NEXT: 0x000000000000000b (SYMENT) 24 (bytes)
91 // CHECK-NEXT: 0x0000000000000005 (STRTAB) 0x[[DYNSTR_ADDR]]
92 // CHECK-NEXT: 0x000000000000000a (STRSZ)
93 // CHECK-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x[[GNU_HASH_ADDR]]
94 // CHECK-NEXT: 0x0000000000000004 (HASH) 0x[[HASH_ADDR]]
95 // PART0-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x[[INIT_ARRAY_ADDR]]
96 // PART0-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
97 // CHECK-NEXT: 0x000000006ffffff0 (VERSYM) 0x[[VERSYM_ADDR]]
98 // CHECK-NEXT: 0x000000006ffffffc (VERDEF) 0x[[VERDEF_ADDR]]
99 // CHECK-NEXT: 0x000000006ffffffd (VERDEFNUM) 3
100 // CHECK-NEXT: 0x000000006ffffffe (VERNEED) 0x[[VERNEED_ADDR]]
101 // CHECK-NEXT: 0x000000006fffffff (VERNEEDNUM) 1
102 // PART0-NEXT: 0x0000000000000000 (NULL) 0x0
104 // CHECK: Relocation section '.rela.dyn'
105 // CHECK-NEXT: Offset
106 // PART0-NEXT: 000000000000[[DATA_SEGMENT]]178 {{.*}} R_X86_64_64 {{.*}} f1@v3 + 0
107 // PART0-NEXT: {{0*}}[[INIT_ARRAY_ADDR]] {{.*}} R_X86_64_64 {{.*}} p0@@x1 + 0
108 // PART1-NEXT: 000000000000[[DATA_SEGMENT]]148 {{.*}} R_X86_64_RELATIVE 3178
109 // PART1-NEXT: 000000000000[[DATA_SEGMENT]]130 {{.*}} R_X86_64_64 {{.*}} f2@v2 + 0
110 // PART1-NEXT: 000000000000[[DATA_SEGMENT]]138 {{.*}} R_X86_64_64 {{.*}} p0@x1 + 0
111 // PART1-NEXT: 000000000000[[DATA_SEGMENT]]140 {{.*}} R_X86_64_64 {{.*}} p0@x1 + 0
113 // PART0: Relocation section '.rela.plt'
114 // PART0-NEXT: Offset
115 // PART0-NEXT: 000000000000[[DATA_SEGMENT]]198 {{.*}} R_X86_64_JUMP_SLOT {{.*}} f1@v3 + 0
116 // PART0-NEXT: 000000000000[[DATA_SEGMENT]]1a0 {{.*}} R_X86_64_JUMP_SLOT {{.*}} f2@v2 + 0
118 // CHECK-NEXT: EHFrameHeader
119 // CHECK: Address: 0x[[EH_FRAME_HDR_ADDR]]
120 // CHECK: eh_frame_ptr: 0x[[EH_FRAME_ADDR]]
121 // CHECK: initial_location: 0x[[TEXT_ADDR]]
122 // CHECK: address: 0x[[FDE_ADDR:.*]]
124 // CHECK: .eh_frame section
125 // CHECK: 0x[[EH_FRAME_ADDR]]] CIE length=20
126 // CHECK-NOT: FDE
127 // CHECK: 0x[[FDE_ADDR]]] FDE length=16 cie={{.}}0x[[EH_FRAME_ADDR]]
128 // CHECK-NEXT: initial_location: 0x[[TEXT_ADDR]]
129 // CHECK-NOT: FDE
130 // CHECK: CIE length=0
132 // CHECK: Symbol table '.dynsym'
133 // PART0: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND f1@v3
134 // PART0: 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND f2@v2
135 // PART0: 3: {{0*}}[[TEXT_ADDR]] 0 NOTYPE GLOBAL DEFAULT {{.*}} p0@@x1
136 // PART1: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND f2@v2
137 // PART1: 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND p0@x1
138 // PART1: 3: {{0*}}[[TEXT_ADDR]] 0 NOTYPE GLOBAL DEFAULT {{.*}} p1@@x2
139 // PART1: 4: {{0*}}[[TEXT_ADDR]] 0 NOTYPE GLOBAL DEFAULT {{.*}} p1alias@@x2
140 // CHECK-EMPTY:
142 // PART0: Symbol table '.symtab'
143 // PART0: 0000000000000488 0 NOTYPE LOCAL HIDDEN {{.*}} __part_index_begin
144 // PART0: 0000000000000494 0 NOTYPE LOCAL HIDDEN {{.*}} __part_index_end
146 // PART-INDEX: Contents of section .dynstr:
147 // PART-INDEX-NEXT: 03a8 00703000 66310066 32007061 72743100 .p0.f1.f2.part1.
148 // PART-INDEX: Contents of section .rodata:
149 // 0x48c + 0xffffff26 = 0x3b2
150 // 0x490 + 0x3b70 = 0x4000
151 // PART-INDEX-NEXT: 0488 2affffff 743b0000 50410000
153 // CHECK: Version symbols section '.gnu.version'
154 // CHECK-NEXT: Addr:
155 // PART0-NEXT: 000: 0 (*local*) 4 (v3) 5 (v2) 2 (x1)
156 // PART1-NEXT: 000: 0 (*local*) 5 (v2) 2 (x1) 3 (x2)
158 // CHECK: Version definition section '.gnu.version_d'
159 // CHECK-NEXT: Addr:
160 // PART0-NEXT: 0x0000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: main.so
161 // PART1-NEXT: 0x0000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: part1
162 // CHECK-NEXT: 0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: x1
163 // CHECK-NEXT: 0x0038: Rev: 1 Flags: none Index: 3 Cnt: 1 Name: x2
165 // CHECK: Version needs section '.gnu.version_r'
166 // CHECK-NEXT: Addr:
167 // CHECK-NEXT: 0x0000: Version: 1 File: verneed1.so.0 Cnt: 2
168 // CHECK-NEXT: 0x0010: Name: v2 Flags: none Version: 5
169 // CHECK-NEXT: 0x0020: Name: v3 Flags: none Version: 4
171 // PART0: Histogram for bucket list length (total of 4 buckets)
172 // PART0-NEXT: Length Number % of total Coverage
173 // PART0-NEXT: 0 1 ( 25.0%) 0.0%
174 // PART0-NEXT: 1 3 ( 75.0%) 100.0%
175 // PART0-NEXT: Histogram for `.gnu.hash' bucket list length (total of 1 buckets)
176 // PART0-NEXT: Length Number % of total Coverage
177 // PART0-NEXT: 0 0 ( 0.0%) 0.0%
178 // PART0-NEXT: 1 1 (100.0%) 100.0%
180 // PART1: Histogram for bucket list length (total of 5 buckets)
181 // PART1-NEXT: Length Number % of total Coverage
182 // PART1-NEXT: 0 3 ( 60.0%) 0.0%
183 // PART1-NEXT: 1 2 ( 40.0%) 100.0%
184 // PART1-NEXT: Histogram for `.gnu.hash' bucket list length (total of 1 buckets)
185 // PART1-NEXT: Length Number % of total Coverage
186 // PART1-NEXT: 0 0 ( 0.0%) 0.0%
187 // PART1-NEXT: 1 0 ( 0.0%) 0.0%
188 // PART1-NEXT: 2 1 (100.0%) 100.0%
190 // FILL: 001040 cccc cccc cccc cccc cccc cccc cccc cccc
191 // FILL-NEXT: *
192 // FILL-NEXT: 002000
194 // FILL: 004010 cccc cccc cccc cccc cccc cccc cccc cccc
195 // FILL-NEXT: *
196 // FILL-NEXT: 005000
198 .section .llvm_sympart,"",@llvm_sympart
199 .asciz "part1"
200 .quad p1
202 .section .llvm_sympart2,"",@llvm_sympart
203 .asciz "part1"
204 .quad p1alias
206 .section .text.p0,"ax",@progbits
207 .globl p0
209 .cfi_startproc
210 lea d0(%rip), %rax
211 call f1
213 .cfi_endproc
215 .section .data.d0,"aw",@progbits
217 .quad f1
219 .section .text.p1,"ax",@progbits
220 .globl p1
222 .globl p1alias
223 p1alias:
224 .cfi_startproc
225 lea d1(%rip), %rax
226 call f2
228 .cfi_endproc
230 .section .data.d1,"aw",@progbits
232 .quad f2
233 .quad p0
234 .quad p0
235 .quad d0
237 .section .init_array,"aw",@init_array
238 .quad p0
240 .globl __part_index_begin
241 .globl __part_index_end