[llvm] r242839 - [Object][ELF] Handle files with no section header string table.
Michael J. Spencer
bigcheesegs at gmail.com
Tue Jul 21 14:40:33 PDT 2015
Author: mspencer
Date: Tue Jul 21 16:40:33 2015
New Revision: 242839
URL: http://llvm.org/viewvc/llvm-project?rev=242839&view=rev
Log:
[Object][ELF] Handle files with no section header string table.
Added:
llvm/trunk/test/Object/Inputs/no-section-header-string-table.elf-x86-64
llvm/trunk/test/Object/no-section-header-string-table.test
Modified:
llvm/trunk/include/llvm/Object/ELF.h
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=242839&r1=242838&r2=242839&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Tue Jul 21 16:40:33 2015
@@ -629,14 +629,18 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
}
// Get string table sections.
- ErrorOr<const Elf_Shdr *> StrTabSecOrErr = getSection(getStringTableIndex());
- if ((EC = StrTabSecOrErr.getError()))
- return;
-
- ErrorOr<StringRef> SymtabOrErr = getStringTable(*StrTabSecOrErr);
- if ((EC = SymtabOrErr.getError()))
- return;
- DotShstrtab = *SymtabOrErr;
+ uintX_t StringTableIndex = getStringTableIndex();
+ if (StringTableIndex) {
+ ErrorOr<const Elf_Shdr *> StrTabSecOrErr =
+ getSection(getStringTableIndex());
+ if ((EC = StrTabSecOrErr.getError()))
+ return;
+
+ ErrorOr<StringRef> SymtabOrErr = getStringTable(*StrTabSecOrErr);
+ if ((EC = SymtabOrErr.getError()))
+ return;
+ DotShstrtab = *SymtabOrErr;
+ }
// Build symbol name side-mapping if there is one.
if (SymbolTableSectionHeaderIndex) {
@@ -746,6 +750,8 @@ template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
uint32_t Offset = Section->sh_name;
+ if (Offset == 0)
+ return StringRef();
if (Offset >= DotShstrtab.size())
return object_error::parse_failed;
return StringRef(DotShstrtab.data() + Offset);
Added: llvm/trunk/test/Object/Inputs/no-section-header-string-table.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/no-section-header-string-table.elf-x86-64?rev=242839&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/no-section-header-string-table.elf-x86-64 (added) and llvm/trunk/test/Object/Inputs/no-section-header-string-table.elf-x86-64 Tue Jul 21 16:40:33 2015 differ
Added: llvm/trunk/test/Object/no-section-header-string-table.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/no-section-header-string-table.test?rev=242839&view=auto
==============================================================================
--- llvm/trunk/test/Object/no-section-header-string-table.test (added)
+++ llvm/trunk/test/Object/no-section-header-string-table.test Tue Jul 21 16:40:33 2015
@@ -0,0 +1,10 @@
+RUN: llvm-readobj %p/Inputs/no-section-header-string-table.elf-x86-64 --sections \
+RUN: | FileCheck %s
+
+CHECK: Type: SHT_PROGBITS (0x1)
+CHECK: Type: SHT_PROGBITS (0x1)
+CHECK: Type: SHT_PROGBITS (0x1)
+CHECK: Type: SHT_RELA (0x4)
+CHECK: Type: SHT_SYMTAB (0x2)
+CHECK: Type: SHT_STRTAB (0x3)
+CHECK: Type: SHT_STRTAB (0x3)
More information about the llvm-commits
mailing list