1## Test --add-symbol creates .symtab if it does not exist. 2 3# RUN: yaml2obj --docnum=1 %s -o %t 4 5## If a non-SHF_ALLOC SHT_STRTAB exists but SHT_SYMTAB does not, create .symtab 6## and set its sh_link to the SHT_STRTAB. 7# RUN: llvm-objcopy --remove-section=.symtab %t %t.no.symtab 8# RUN: llvm-objcopy --add-symbol='abs1=1' %t.no.symtab %t.add.both 9# RUN: llvm-readobj -S %t.add.both | FileCheck --check-prefix=SEC %s 10# RUN: llvm-readelf -s %t.add.both | FileCheck %s 11 12# SEC: Index: 1 13# SEC-NEXT: Name: .strtab 14# SEC-NEXT: Type: SHT_STRTAB 15# SEC: Index: 2 16# SEC-NEXT: Name: .shstrtab 17# SEC-NEXT: Type: SHT_STRTAB 18# SEC: Index: 3 19# SEC-NEXT: Name: .symtab 20# SEC-NEXT: Type: SHT_SYMTAB 21# SEC-NOT: } 22# SEC: Link: 1 23 24# CHECK: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 25# CHECK-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT ABS abs1 26 27## Don't create .symtab if --add-symbol is not specified. 28# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t %t.no 29# RUN: llvm-objcopy %t.no %t.nop 30# RUN: llvm-readobj -S %t.nop | FileCheck --implicit-check-not=.symtab --implicit-check-not=.strtab /dev/null 31 32## Reuse the existing .shstrtab (section names) for symbol names. 33## This may look strange but it works. 34# RUN: llvm-objcopy --add-symbol='abs1=1' %t.no %t.add.symtab 35# RUN: llvm-readobj -S %t.add.symtab | FileCheck --check-prefix=SEC2 %s --implicit-check-not=.strtab 36# RUN: llvm-readelf -s %t.add.symtab | FileCheck %s 37 38# SEC2: Index: 1 39# SEC2-NEXT: Name: .shstrtab 40# SEC2-NEXT: Type: SHT_STRTAB 41# SEC2: Index: 2 42# SEC2-NEXT: Name: .symtab 43# SEC2-NEXT: Type: SHT_SYMTAB 44# SEC2-NOT: } 45# SEC2: Link: 1 46 47--- !ELF 48FileHeader: 49 Class: ELFCLASS64 50 Data: ELFDATA2LSB 51 Type: ET_REL 52 Machine: EM_X86_64 53Sections: 54 - Name: .strtab 55 Type: SHT_STRTAB 56 - Name: .shstrtab 57 Type: SHT_STRTAB 58Symbols: [] 59... 60 61## Check that we prefer the string table that is not the section header string table. 62# RUN: yaml2obj --docnum=2 %s -o %t2 63# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t2 %t2.no 64# RUN: llvm-objcopy --add-symbol='abs1=1' %t2.no %t2.add.symtab 65# RUN: llvm-readobj -S %t2.add.symtab | FileCheck --check-prefix=SEC2 %s 66# RUN: llvm-readelf -s %t2.add.symtab | FileCheck %s 67 68--- !ELF 69FileHeader: 70 Class: ELFCLASS64 71 Data: ELFDATA2LSB 72 Type: ET_REL 73 Machine: EM_X86_64 74Sections: 75 # .shstrtab is reordered before .strtab 76 - Name: .shstrtab 77 Type: SHT_STRTAB 78 - Name: .strtab 79 Type: SHT_STRTAB 80Symbols: [] 81... 82 83## Check the created .symtab does not link to .dynstr (SHF_ALLOC). 84# RUN: yaml2obj --docnum=3 %s -o %t3 85# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t3 %t3.no 86# RUN: llvm-objcopy --add-symbol='abs1=1' %t3.no %t3.not.dynstr 87# RUN: llvm-readobj -S %t3.not.dynstr | FileCheck --check-prefix=SEC3 %s 88 89# SEC3: Index: 3 90# SEC3-NEXT: Name: .shstrtab 91# SEC3-NEXT: Type: SHT_STRTAB 92# SEC3: Name: .symtab 93# SEC3-NEXT: Type: SHT_SYMTAB 94# SEC3-NOT: } 95# SEC3: Link: 3 96 97--- !ELF 98FileHeader: 99 Class: ELFCLASS64 100 Data: ELFDATA2LSB 101 Type: ET_DYN 102 Machine: EM_X86_64 103DynamicSymbols: 104 - Name: dummy 105 Binding: STB_GLOBAL 106Symbols: [] 107... 108