1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test
Fangrui Song ccee3bcf0b [llvm-objcopy] --add-symbol: address post-commit reviews of D69093
* Improve comments.
* Reorder the assignment to Obj.SectionNames before the symbol table
  creation code. Add a test.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D69526
2019-10-31 09:12:06 -07:00

108 lines
3.1 KiB
Plaintext

## Test --add-symbol creates .symtab if it does not exist.
# RUN: yaml2obj --docnum=1 %s -o %t
## If a non-SHF_ALLOC SHT_STRTAB exists but SHT_SYMTAB does not, create .symtab
## and set its sh_link to the SHT_STRTAB.
# RUN: llvm-objcopy --remove-section=.symtab %t %t.no.symtab
# RUN: llvm-objcopy --add-symbol='abs1=1' %t.no.symtab %t.add.both
# RUN: llvm-readobj -S %t.add.both | FileCheck --check-prefix=SEC %s
# RUN: llvm-readelf -s %t.add.both | FileCheck %s
# SEC: Index: 1
# SEC-NEXT: Name: .strtab
# SEC-NEXT: Type: SHT_STRTAB
# SEC: Index: 2
# SEC-NEXT: Name: .shstrtab
# SEC-NEXT: Type: SHT_STRTAB
# SEC: Index: 3
# SEC-NEXT: Name: .symtab
# SEC-NEXT: Type: SHT_SYMTAB
# SEC-NOT: }
# SEC: Link: 1
# CHECK: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
# CHECK-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT ABS abs1
## Don't create .symtab if --add-symbol is not specified.
# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t %t.no
# RUN: llvm-objcopy %t.no %t.nop
# RUN: llvm-readobj -S %t.nop | FileCheck --implicit-check-not=.symtab --implicit-check-not=.strtab /dev/null
## Reuse the existing .shstrtab (section names) for symbol names.
## This may look strange but it works.
# RUN: llvm-objcopy --add-symbol='abs1=1' %t.no %t.add.symtab
# RUN: llvm-readobj -S %t.add.symtab | FileCheck --check-prefix=SEC2 %s --implicit-check-not=.strtab
# RUN: llvm-readelf -s %t.add.symtab | FileCheck %s
# SEC2: Index: 1
# SEC2-NEXT: Name: .shstrtab
# SEC2-NEXT: Type: SHT_STRTAB
# SEC2: Index: 2
# SEC2-NEXT: Name: .symtab
# SEC2-NEXT: Type: SHT_SYMTAB
# SEC2-NOT: }
# SEC2: Link: 1
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .strtab
Type: SHT_STRTAB
- Name: .shstrtab
Type: SHT_STRTAB
Symbols: []
...
## Check that we prefer the string table that is not the section header string table.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t2 %t2.no
# RUN: llvm-objcopy --add-symbol='abs1=1' %t2.no %t2.add.symtab
# RUN: llvm-readobj -S %t2.add.symtab | FileCheck --check-prefix=SEC2 %s
# RUN: llvm-readelf -s %t2.add.symtab | FileCheck %s
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
# .shstrtab is reordered before .strtab
- Name: .shstrtab
Type: SHT_STRTAB
- Name: .strtab
Type: SHT_STRTAB
Symbols: []
...
## Check the created .symtab does not link to .dynstr (SHF_ALLOC).
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t3 %t3.no
# RUN: llvm-objcopy --add-symbol='abs1=1' %t3.no %t3.not.dynstr
# RUN: llvm-readobj -S %t3.not.dynstr | FileCheck --check-prefix=SEC3 %s
# SEC3: Index: 1
# SEC3-NEXT: Name: .shstrtab
# SEC3-NEXT: Type: SHT_STRTAB
# SEC3: Name: .symtab
# SEC3-NEXT: Type: SHT_SYMTAB
# SEC3-NOT: }
# SEC3: Link: 1
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
DynamicSymbols:
- Name: dummy
Binding: STB_GLOBAL
Symbols: []
...