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 %t1
8 # RUN: llvm-objcopy --add-symbol='abs1=1' %t1 %t2
9 # RUN: llvm-readobj -S %t2 | FileCheck --check-prefix=SEC %s
10 # RUN: llvm-readelf -s %t2 | 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 %t1
29 # RUN: llvm-objcopy %t1 %t2
30 # RUN: llvm-readobj -S %t2 | FileCheck --implicit-check-not=.symtab /dev/null
32 ## Check that we create both .strtab and .symtab.
33 ## We reuse the existing .shstrtab (section names) for symbol names.
34 ## This may look strange but it works.
35 # RUN: llvm-objcopy --add-symbol='abs1=1' %t1 %t2
36 # RUN: llvm-readobj -S %t2 | FileCheck --check-prefix=SEC2 %s
37 # RUN: llvm-readelf -s %t2 | FileCheck %s
40 # SEC2-NEXT: Name: .shstrtab
41 # SEC2-NEXT: Type: SHT_STRTAB
43 # SEC2-NEXT: Name: .symtab
44 # SEC2-NEXT: Type: SHT_SYMTAB
57 ## Check the created .symtab does not link to .dynstr (SHF_ALLOC).
58 # RUN: yaml2obj --docnum=2 %s -o %t
59 # RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t %t1
60 # RUN: llvm-objcopy --add-symbol='abs1=1' %t1 %t2
61 # RUN: llvm-readobj -S %t2 | FileCheck --check-prefix=SEC3 %s
64 # SEC3-NEXT: Name: .shstrtab
65 # SEC3-NEXT: Type: SHT_STRTAB
67 # SEC3-NEXT: Type: SHT_SYMTAB