diff --git a/llvm/lib/InterfaceStub/ELFObjHandler.cpp b/llvm/lib/InterfaceStub/ELFObjHandler.cpp --- a/llvm/lib/InterfaceStub/ELFObjHandler.cpp +++ b/llvm/lib/InterfaceStub/ELFObjHandler.cpp @@ -303,7 +303,8 @@ 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, so 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; diff --git a/llvm/test/tools/llvm-elfabi/write-stub-no-nonlocal-symbol.test b/llvm/test/tools/llvm-elfabi/write-stub-no-nonlocal-symbol.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-elfabi/write-stub-no-nonlocal-symbol.test @@ -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: }