1# RUN: yaml2obj --docnum=1 %s -o %t.elf-x86-64 2# RUN: yaml2obj --docnum=2 %s -o %t2.elf-x86-64 3 4--- !ELF 5FileHeader: 6 Class: ELFCLASS64 7 Data: ELFDATA2LSB 8 Type: ET_REL 9 Machine: EM_X86_64 10Sections: 11 - Name: .text 12 Type: SHT_PROGBITS 13 Flags: [ SHF_ALLOC, SHF_EXECINSTR ] 14Symbols: 15 - Name: main 16 Type: STT_FUNC 17 Section: .text 18 Binding: STB_GLOBAL 19 - Name: SomeOtherFunction 20 Binding: STB_GLOBAL 21 - Name: puts 22 Binding: STB_GLOBAL 23 24--- !ELF 25FileHeader: 26 Class: ELFCLASS64 27 Data: ELFDATA2LSB 28 Type: ET_REL 29 Machine: EM_X86_64 30Sections: 31 - Name: .text 32 Type: SHT_PROGBITS 33 Flags: [ SHF_ALLOC, SHF_EXECINSTR ] 34Symbols: 35 - Name: bar 36 Type: STT_FUNC 37 Section: .text 38 - Name: foo 39 Type: STT_FUNC 40 Section: .text 41 Binding: STB_GLOBAL 42 Value: 0x0000000000000006 43 - Name: main 44 Type: STT_FUNC 45 Section: .text 46 Binding: STB_GLOBAL 47 Value: 0x0000000000000016 48 49# RUN: rm -f %t.a 50# RUN: llvm-ar rcsU %t.a %t.elf-x86-64 %t2.elf-x86-64 51# RUN: llvm-nm -M %t.a | FileCheck %s 52 53# RUN: rm -f %t.a 54# RUN: env SYM64_THRESHOLD=836 llvm-ar rcsU %t.a %t.elf-x86-64 %t2.elf-x86-64 55# RUN: llvm-nm -M %t.a | FileCheck %s 56# RUN: grep '/SYM64/' %t.a 57 58# RUN: rm -f %t.a 59# RUN: env SYM64_THRESHOLD=837 llvm-ar rcsU %t.a %t.elf-x86-64 %t2.elf-x86-64 60# RUN: llvm-nm -M %t.a | FileCheck %s 61# RUN: not grep '/SYM64/' %t.a 62 63# CHECK: Archive map 64# CHECK-NEXT: main in {{.*}}.elf-x86-64 65# CHECK-NEXT: foo in {{.*}}2.elf-x86-64 66# CHECK-NEXT: main in {{.*}}2.elf-x86-64 67# CHECK-NOT: bar 68 69 70# RUN: rm -f %t.a 71# RUN: llvm-ar --format=gnu rcT %t.a %t.elf-x86-64 %t2.elf-x86-64 72# RUN: llvm-nm -M %t.a | FileCheck -DFILE=%/t.elf-x86-64 -DFILE2=%/t2.elf-x86-64 --check-prefix=THIN %s 73 74# THIN: Archive map 75# THIN-NEXT: main in [[FILE]] 76# THIN-NEXT: foo in [[FILE2]] 77# THIN-NEXT: main in [[FILE2]] 78 79 80# CHECK: {{.*}}.elf-x86-64: 81# CHECK-NEXT: U SomeOtherFunction 82# CHECK-NEXT: 0000000000000000 T main 83# CHECK-NEXT: U puts 84 85# CHECK: {{.*}}2.elf-x86-64: 86# CHECK-NEXT: 0000000000000000 t bar 87# CHECK-NEXT: 0000000000000006 T foo 88# CHECK-NEXT: 0000000000000016 T main 89 90# RUN: rm -f %t.a 91# RUN: llvm-ar rcSU %t.a %t.elf-x86-64 %t2.elf-x86-64 92# RUN: llvm-nm -M %t.a | FileCheck %s --check-prefix=NOMAP 93 94# NOMAP-NOT: Archive map 95 96# RUN: llvm-ar s %t.a 97# RUN: llvm-nm -M %t.a | FileCheck %s 98 99## Check that the archive does have a corrupt symbol table. 100# RUN: rm -f %t.a 101# RUN: cp %p/Inputs/archive-test.a-corrupt-symbol-table %t.a 102# RUN: llvm-nm -M %t.a | FileCheck %s --check-prefix=CORRUPT 103 104# CORRUPT: Archive map 105# CORRUPT-NEXT: mbin in trivial-object-test.elf-x86-64 106# CORRUPT-NEXT: foo in trivial-object-test2.elf-x86-64 107# CORRUPT-NEXT: main in trivial-object-test2.elf-x86-64 108 109# CORRUPT: {{.*}}.elf-x86-64: 110# CORRUPT-NEXT: U SomeOtherFunction 111# CORRUPT-NEXT: 0000000000000000 T main 112# CORRUPT-NEXT: U puts 113 114# CORRUPT: {{.*}}2.elf-x86-64: 115# CORRUPT-NEXT: 0000000000000000 t bar 116# CORRUPT-NEXT: 0000000000000006 T foo 117# CORRUPT-NEXT: 0000000000000016 T main 118 119## Check that the we *don't* update the symbol table. 120# RUN: llvm-ar s %t.a 121# RUN: llvm-nm -M %t.a | FileCheck %s --check-prefix=CORRUPT 122 123## Repeat the test with llvm-ranlib. 124 125# RUN: rm -f %t.a 126# RUN: llvm-ar rcSU %t.a %t.elf-x86-64 %t2.elf-x86-64 127# RUN: llvm-nm -M %t.a | FileCheck %s --check-prefix=NOMAP 128 129# RUN: llvm-ranlib %t.a 130# RUN: llvm-nm -M %t.a | FileCheck %s 131 132# RUN: llvm-nm -M %p/Inputs/macho-archive-x86_64.a | FileCheck %s --check-prefix=BSD-MachO 133# RUN: llvm-nm -M %p/Inputs/macho-archive-unsorted-x86_64.a | FileCheck %s --check-prefix=BSD-MachO 134 135# BSD-MachO: Archive map 136# BSD-MachO: _bar in bar.o 137# BSD-MachO: _foo in foo.o 138 139# RUN: rm -f %t.a 140# RUN: llvm-ar --format=bsd rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test2.macho-x86-64 141# RUN: llvm-nm -M %t.a | FileCheck --check-prefix=MACHO %s 142 143# RUN: rm -f %t.a 144# RUN: env SYM64_THRESHOLD=784 llvm-ar --format=darwin rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test2.macho-x86-64 145# RUN: llvm-nm -M %t.a | FileCheck --check-prefix=MACHO %s 146# RUN: grep '__\.SYMDEF_64' %t.a 147 148# RUN: rm -f %t.a 149# RUN: env SYM64_THRESHOLD=785 llvm-ar --format=darwin rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test2.macho-x86-64 150# RUN: llvm-nm -M %t.a | FileCheck --check-prefix=MACHO %s 151# RUN: not grep '__\.SYMDEF_64' %t.a 152 153# MACHO: Archive map 154# MACHO-NEXT: _main in trivial-object-test.macho-x86-64 155# MACHO-NEXT: _foo in trivial-object-test2.macho-x86-64 156# MACHO-NEXT: _main in trivial-object-test2.macho-x86-64 157# MACHO-NOT: {{^}}bar 158 159# MACHO: trivial-object-test.macho-x86-64 160# MACHO-NEXT: 0000000000000028 s L_.str 161# MACHO-NEXT: U _SomeOtherFunction 162# MACHO-NEXT: 0000000000000000 T _main 163# MACHO-NEXT: U _puts 164 165# MACHO: trivial-object-test2.macho-x86-64 166# MACHO-NEXT: 0000000000000000 t _bar 167# MACHO-NEXT: 0000000000000001 T _foo 168# MACHO-NEXT: 0000000000000002 T _main 169 170# RUN: llvm-nm -M %p/Inputs/macho-toc64-archive-x86_64.a | FileCheck --check-prefix=MACHO-TOC64 %s 171 172# MACHO-TOC64: Archive map 173# MACHO-TOC64-NEXT: _test in test.o 174# MACHO-TOC64-NEXT: _test in xtest.o 175 176# RUN: rm -f %t.a 177# RUN: llvm-ar --format=gnu rcsU %t.a %p/Inputs/coff-short-import-code %p/Inputs/coff-short-import-data 178# RUN: llvm-nm -M %t.a | FileCheck --check-prefix=COFF-SHORT-IMPORT %s 179 180# COFF-SHORT-IMPORT: Archive map 181# COFF-SHORT-IMPORT-NEXT: __imp__foo in coff-short-import-code 182# COFF-SHORT-IMPORT-NEXT: _foo in coff-short-import-code 183# COFF-SHORT-IMPORT-NEXT: __imp__bar in coff-short-import-data 184# COFF-SHORT-IMPORT-NOT: _bar in coff-short-import-data 185 186## Test that we pad the symbol table so that it ends in a multiple of 8 bytes: 187## 8 + 60 + 36 == 104 188# RUN: rm -f %t.a 189# RUN: llvm-ar --format=bsd rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64 190# RUN: FileCheck --check-prefix=MACHO-SYMTAB-ALIGN %s < %t.a 191# MACHO-SYMTAB-ALIGN: !<arch> 192# MACHO-SYMTAB-ALIGN-NEXT: #1/12 {{..........}} 0 0 0 36 ` 193 194## Test that we pad the symbol table so that it ends in a multiple of 8 bytes: 195## 8 + 60 + 52 == 120 196# RUN: rm -f %t.a 197# RUN: llvm-ar --format=bsd rcsD %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test.macho-x86-64 198# RUN: FileCheck --check-prefix=MACHO-SYMTAB-ALIGN2 %s < %t.a 199# MACHO-SYMTAB-ALIGN2: !<arch> 200# MACHO-SYMTAB-ALIGN2-NEXT: #1/12 0 0 0 0 52 ` 201 202## With a gnu symbol table we only align to two 203# 8 + 60 + 14 = 82 204# RUN: rm -f %t.a 205# RUN: llvm-ar --format=gnu rcsD %t.a %p/Inputs/trivial-object-test.macho-x86-64 206# RUN: FileCheck --check-prefix=GNU-SYMTAB-ALIGN %s < %t.a 207# GNU-SYMTAB-ALIGN: !<arch> 208# GNU-SYMTAB-ALIGN-NEXT: / 0 0 0 0 14 ` 209 210 211## ** Test the behavior of an empty archive: 212 213## No symbol table emitted for GNU archives 214# RUN: rm -f %t.a 215# RUN: llvm-ar rcs --format=gnu %t.a 216# RUN: not grep -q '/ ' %t.a 217 218## No symbol table for BSD archives 219# RUN: rm -f %t.a 220# RUN: llvm-ar rcs --format=bsd %t.a 221# RUN: not grep -q '__\.SYMDEF' %t.a 222 223## And we do emit a symbol table for DARWIN archives 224# RUN: rm -f %t.a 225# RUN: llvm-ar rcs --format=darwin %t.a 226# RUN: grep -q '__\.SYMDEF' %t.a 227