Skip to content

Commit

Permalink
[Object][ELF] Handle the dynamic string table in files without a sect…
Browse files Browse the repository at this point in the history
…ion table.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241937 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Bigcheese committed Jul 10, 2015
1 parent a8043e2 commit d37a9df
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
20 changes: 15 additions & 5 deletions include/llvm/Object/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ class ELFFile {
StringRef DotShstrtab; // Section header string table.
StringRef DotStrtab; // Symbol header string table.
const Elf_Shdr *dot_symtab_sec = nullptr; // Symbol table section.
StringRef DynSymStrTab; // Dynnamic symbol string table.
const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
const Elf_Hash *HashTable = nullptr;

Expand All @@ -200,6 +199,7 @@ class ELFFile {

DynRegionInfo DynamicRegion;
DynRegionInfo DynHashRegion;
DynRegionInfo DynStrRegion;
DynRegionInfo DynRelaRegion;

// Pointer to SONAME entry in dynamic string table
Expand Down Expand Up @@ -655,7 +655,9 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
ErrorOr<StringRef> SymtabOrErr = getStringTable(*SectionOrErr);
if ((EC = SymtabOrErr.getError()))
return;
DynSymStrTab = *SymtabOrErr;
DynStrRegion.Addr = SymtabOrErr->data();
DynStrRegion.Size = SymtabOrErr->size();
DynStrRegion.EntSize = 1;
break;
}
case ELF::SHT_DYNAMIC:
Expand Down Expand Up @@ -764,6 +766,14 @@ void ELFFile<ELFT>::scanDynamicTable() {
HashTable =
reinterpret_cast<const Elf_Hash *>(toMappedAddr(DynI->getPtr()));
break;
case ELF::DT_STRTAB:
if (!DynStrRegion.Addr)
DynStrRegion.Addr = toMappedAddr(DynI->getPtr());
break;
case ELF::DT_STRSZ:
if (!DynStrRegion.Size)
DynStrRegion.Size = DynI->getVal();
break;
case ELF::DT_RELA:
if (!DynRelaRegion.Addr)
DynRelaRegion.Addr = toMappedAddr(DynI->getPtr());
Expand Down Expand Up @@ -897,9 +907,9 @@ ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {

template <class ELFT>
const char *ELFFile<ELFT>::getDynamicString(uintX_t Offset) const {
if (!DotDynSymSec || Offset >= DynSymStrTab.size())
if (Offset >= DynStrRegion.Size)
return nullptr;
return (const char *)DynSymStrTab.begin() + Offset;
return (const char *)DynStrRegion.Addr + Offset;
}

template <class ELFT>
Expand Down Expand Up @@ -1012,7 +1022,7 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolVersion(const Elf_Shdr *section,
IsDefault = false;
}

if (name_offset >= DynSymStrTab.size())
if (name_offset >= DynStrRegion.Size)
return object_error::parse_failed;
return StringRef(getDynamicString(name_offset));
}
Expand Down
30 changes: 29 additions & 1 deletion test/Object/no-section-table.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
RUN: llvm-readobj %p/Inputs/no-section-table.so -hash-table | FileCheck %s
RUN: llvm-readobj %p/Inputs/no-section-table.so -hash-table -dynamic-table \
RUN: | FileCheck %s

CHECK: DynamicSection [ (24 entries)
CHECK: Tag Type Name/Value
CHECK: 0x0000000000000001 NEEDED SharedLibrary (libc.so.6)
CHECK: 0x000000000000000C INIT 0x4B8
CHECK: 0x000000000000000D FINI 0x618
CHECK: 0x0000000000000019 INIT_ARRAY 0x2006C0
CHECK: 0x000000000000001B INIT_ARRAYSZ 8 (bytes)
CHECK: 0x000000000000001A FINI_ARRAY 0x2006C8
CHECK: 0x000000000000001C FINI_ARRAYSZ 8 (bytes)
CHECK: 0x0000000000000004 HASH 0x158
CHECK: 0x0000000000000005 STRTAB 0x2D8
CHECK: 0x0000000000000006 SYMTAB 0x1A0
CHECK: 0x000000000000000A STRSZ 179 (bytes)
CHECK: 0x000000000000000B SYMENT 24 (bytes)
CHECK: 0x0000000000000003 PLTGOT 0x2008C0
CHECK: 0x0000000000000002 PLTRELSZ 48 (bytes)
CHECK: 0x0000000000000014 PLTREL RELA
CHECK: 0x0000000000000017 JMPREL 0x488
CHECK: 0x0000000000000007 RELA 0x3C8
CHECK: 0x0000000000000008 RELASZ 192 (bytes)
CHECK: 0x0000000000000009 RELAENT 24 (bytes)
CHECK: 0x000000006FFFFFFE VERNEED 0x3A8
CHECK: 0x000000006FFFFFFF VERNEEDNUM 1
CHECK: 0x000000006FFFFFF0 VERSYM 0x38C
CHECK: 0x000000006FFFFFF9 unknown 0x3
CHECK: 0x0000000000000000 NULL 0x0
CHECK: ]
CHECK: HashTable {
CHECK: Num Buckets: 3
CHECK: Num Chains: 13
Expand Down

0 comments on commit d37a9df

Please sign in to comment.