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