forked from OSchip/llvm-project
[elfabi] Fix a bug when .dynsym contains no non-local symbol
This patch fixed a bug when elbabi was supplied with a tbe file contains no non-local symbol. Before this patch, it wrote 0 to sh_info of the .dynsym section, making the ELF stub file invalid. This patch fixed this issue. Differential Revision: https://reviews.llvm.org/D96930
This commit is contained in:
parent
dbc89028d7
commit
784c7debb2
|
@ -303,7 +303,10 @@ private:
|
|||
SymTab.Shdr.sh_flags = SHF_ALLOC;
|
||||
SymTab.Shdr.sh_addr = SymTab.Addr;
|
||||
SymTab.Shdr.sh_offset = SymTab.Offset;
|
||||
SymTab.Shdr.sh_info = SymTab.Size / sizeof(Elf_Sym) > 1 ? 1 : 0;
|
||||
// Only non-local symbols are included in the tbe file, so .dynsym only
|
||||
// contains 1 local symbol (the undefined symbol at index 0). The sh_info
|
||||
// should always be 1.
|
||||
SymTab.Shdr.sh_info = 1;
|
||||
SymTab.Shdr.sh_size = SymTab.Size;
|
||||
SymTab.Shdr.sh_name = this->ShStrTab.Content.getOffset(SymTab.Name);
|
||||
SymTab.Shdr.sh_addralign = SymTab.Align;
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
## Test writing stub elf when symbol table contains no non-local symbol.
|
||||
|
||||
# RUN: llvm-elfabi %s --output-target=elf64-little %t
|
||||
# RUN: llvm-readobj -S %t | FileCheck %s -DCLASS="64-bit (0x2)" -DDE="LittleEndian (0x1)" -DHS=64 -DPHES=56 -DSHES=64 -DDYNSYMAL=8 -DDYNSYMES=24 -DDYNAMICAL=8 -DDYNAMICES=16 -DDYNTABZ=000000000
|
||||
|
||||
--- !tapi-tbe
|
||||
TbeVersion: 1.0
|
||||
Arch: x86_64
|
||||
NeededLibs:
|
||||
- libc.so.6
|
||||
Symbols: {}
|
||||
...
|
||||
|
||||
# CHECK: Section {
|
||||
# CHECK-NEXT: Index: 0
|
||||
# CHECK-NEXT: Name: (0)
|
||||
# CHECK-NEXT: Type: SHT_NULL
|
||||
# CHECK-NEXT: Flags [
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Address: 0x0
|
||||
# CHECK-NEXT: Offset: 0x0
|
||||
# CHECK-NEXT: Size: 0
|
||||
# CHECK-NEXT: Link: 0
|
||||
# CHECK-NEXT: Info: 0
|
||||
# CHECK-NEXT: AddressAlignment: 0
|
||||
# CHECK-NEXT: EntrySize: 0
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Section {
|
||||
# CHECK-NEXT: Index: 1
|
||||
# CHECK-NEXT: Name: .dynsym
|
||||
# CHECK-NEXT: Type: SHT_DYNSYM
|
||||
# CHECK-NEXT: Flags [
|
||||
# CHECK-NEXT: SHF_ALLOC
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Address:
|
||||
# CHECK-NEXT: Offset:
|
||||
# CHECK-NEXT: Size:
|
||||
# CHECK-NEXT: Link: 2
|
||||
# CHECK-NEXT: Info: 1
|
||||
# CHECK-NEXT: AddressAlignment: [[DYNSYMAL]]
|
||||
# CHECK-NEXT: EntrySize: [[DYNSYMES]]
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Section {
|
||||
# CHECK-NEXT: Index: 2
|
||||
# CHECK-NEXT: Name: .dynstr
|
||||
# CHECK-NEXT: Type: SHT_STRTAB
|
||||
# CHECK-NEXT: Flags [
|
||||
# CHECK-NEXT: SHF_ALLOC
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Address:
|
||||
# CHECK-NEXT: Offset:
|
||||
# CHECK-NEXT: Size:
|
||||
# CHECK-NEXT: Link: 0
|
||||
# CHECK-NEXT: Info: 0
|
||||
# CHECK-NEXT: AddressAlignment: 1
|
||||
# CHECK-NEXT: EntrySize: 0
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Section {
|
||||
# CHECK-NEXT: Index: 3
|
||||
# CHECK-NEXT: Name: .dynamic
|
||||
# CHECK-NEXT: Type: SHT_DYNAMIC
|
||||
# CHECK-NEXT: Flags [
|
||||
# CHECK-NEXT: SHF_ALLOC
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Address:
|
||||
# CHECK-NEXT: Offset:
|
||||
# CHECK-NEXT: Size:
|
||||
# CHECK-NEXT: Link: 2
|
||||
# CHECK-NEXT: Info: 0
|
||||
# CHECK-NEXT: AddressAlignment: [[DYNAMICAL]]
|
||||
# CHECK-NEXT: EntrySize: [[DYNAMICES]]
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Section {
|
||||
# CHECK-NEXT: Index: 4
|
||||
# CHECK-NEXT: Name: .shstrtab
|
||||
# CHECK-NEXT: Type: SHT_STRTAB
|
||||
# CHECK-NEXT: Flags [
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Address:
|
||||
# CHECK-NEXT: Offset:
|
||||
# CHECK-NEXT: Size:
|
||||
# CHECK-NEXT: Link: 0
|
||||
# CHECK-NEXT: Info: 0
|
||||
# CHECK-NEXT: AddressAlignment: 1
|
||||
# CHECK-NEXT: EntrySize: 0
|
||||
# CHECK-NEXT: }
|
Loading…
Reference in New Issue