1 ## Test --add-symbol creates .symtab if it does not exist.
3 # RUN: yaml2obj --docnum=1 %s -o %t
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
13 # SEC-NEXT: Name: .strtab
14 # SEC-NEXT: Type: SHT_STRTAB
16 # SEC-NEXT: Name: .shstrtab
17 # SEC-NEXT: Type: SHT_STRTAB
19 # SEC-NEXT: Name: .symtab
20 # SEC-NEXT: Type: SHT_SYMTAB
24 # CHECK: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
25 # CHECK-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT ABS abs1
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
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
39 # SEC2-NEXT: Name: .shstrtab
40 # SEC2-NEXT: Type: SHT_STRTAB
42 # SEC2-NEXT: Name: .symtab
43 # SEC2-NEXT: Type: SHT_SYMTAB
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
75 # .shstrtab is reordered before .strtab
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
90 # SEC3-NEXT: Name: .shstrtab
91 # SEC3-NEXT: Type: SHT_STRTAB
93 # SEC3-NEXT: Type: SHT_SYMTAB
109 ## Check the created .symtab is correct when there are program headers.
110 # RUN: yaml2obj --docnum=4 %s -o %t4
111 # RUN: llvm-objcopy %t4 %t4.add --add-symbol foo=1234
112 # RUN: llvm-readelf -s %t4.add | FileCheck --check-prefix=SEC4 %s
114 # SEC4: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
115 # SEC4-NEXT: 1: 00000000000004d2 0 NOTYPE GLOBAL DEFAULT ABS foo