[llvm] r285753 - Don't compute DotShstrtab eagerly.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 14:33:55 PDT 2016
Author: rafael
Date: Tue Nov 1 16:33:55 2016
New Revision: 285753
URL: http://llvm.org/viewvc/llvm-project?rev=285753&view=rev
Log:
Don't compute DotShstrtab eagerly.
This saves a field that is not always used. It also avoids failing a
program that doesn't need the section names.
Removed:
llvm/trunk/test/Object/Inputs/invalid-section-index2.elf
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/test/Object/invalid.test
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285753&r1=285752&r2=285753&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Tue Nov 1 16:33:55 2016
@@ -73,7 +73,6 @@ private:
const Elf_Ehdr *Header;
const Elf_Shdr *SectionHeaderTable = nullptr;
- StringRef DotShstrtab; // Section header string table.
public:
template<typename T>
@@ -154,7 +153,8 @@ public:
}
uint64_t getNumSections() const;
- uint32_t getStringTableIndex() const;
+ ErrorOr<StringRef> getSectionStringTable() const;
+ uint32_t getSectionStringTableIndex() const;
uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
const Elf_Shdr *SymTab,
ArrayRef<Elf_Word> ShndxTable) const;
@@ -175,6 +175,8 @@ public:
}
ErrorOr<StringRef> getSectionName(const Elf_Shdr *Section) const;
+ ErrorOr<StringRef> getSectionName(const Elf_Shdr *Section,
+ StringRef DotShstrtab) const;
template <typename T>
ErrorOr<ArrayRef<T>> getSectionContentsAsArray(const Elf_Shdr *Sec) const;
ErrorOr<ArrayRef<uint8_t> > getSectionContents(const Elf_Shdr *Sec) const;
@@ -299,15 +301,26 @@ uint64_t ELFFile<ELFT>::getNumSections()
return Header->e_shnum;
}
-template <class ELFT> uint32_t ELFFile<ELFT>::getStringTableIndex() const {
+template <class ELFT>
+uint32_t ELFFile<ELFT>::getSectionStringTableIndex() const {
if (Header->e_shstrndx == ELF::SHN_XINDEX)
return SectionHeaderTable->sh_link;
return Header->e_shstrndx;
}
template <class ELFT>
-ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
- : Buf(Object) {
+ErrorOr<StringRef> ELFFile<ELFT>::getSectionStringTable() const {
+ uint32_t Index = getSectionStringTableIndex();
+ if (!Index) // no section string table.
+ return "";
+ ErrorOr<const Elf_Shdr *> StrTabSecOrErr = getSection(Index);
+ if (std::error_code EC = StrTabSecOrErr.getError())
+ return EC;
+ return getStringTable(*StrTabSecOrErr);
+}
+
+template <class ELFT>
+ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC) : Buf(Object) {
const uint64_t FileSize = Buf.size();
if (sizeof(Elf_Ehdr) > FileSize) {
@@ -357,19 +370,6 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
return;
}
- // Get string table sections.
- uint32_t StringTableIndex = getStringTableIndex();
- if (StringTableIndex) {
- ErrorOr<const Elf_Shdr *> StrTabSecOrErr = getSection(StringTableIndex);
- if ((EC = StrTabSecOrErr.getError()))
- return;
-
- ErrorOr<StringRef> StringTableOrErr = getStringTable(*StrTabSecOrErr);
- if ((EC = StringTableOrErr.getError()))
- return;
- DotShstrtab = *StringTableOrErr;
- }
-
EC = std::error_code();
}
@@ -472,6 +472,15 @@ ELFFile<ELFT>::getStringTableForSymtab(c
template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
+ ErrorOr<StringRef> Table = getSectionStringTable();
+ if (std::error_code EC = Table.getError())
+ return EC;
+ return getSectionName(Section, *Table);
+}
+
+template <class ELFT>
+ErrorOr<StringRef> ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section,
+ StringRef DotShstrtab) const {
uint32_t Offset = Section->sh_name;
if (Offset == 0)
return StringRef();
Removed: llvm/trunk/test/Object/Inputs/invalid-section-index2.elf
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/invalid-section-index2.elf?rev=285752&view=auto
==============================================================================
Binary file - no diff available.
Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=285753&r1=285752&r2=285753&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Tue Nov 1 16:33:55 2016
@@ -42,7 +42,6 @@ RUN: not llvm-readobj --dyn-symbols %p/I
INVALID-DYNSYM-SIZE: Invalid entity size
RUN: not llvm-readobj -t %p/Inputs/invalid-section-index.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-INDEX %s
-RUN: not llvm-readobj -t %p/Inputs/invalid-section-index2.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-INDEX %s
INVALID-SECTION-INDEX: Invalid section index
RUN: not llvm-readobj -s %p/Inputs/invalid-section-size.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-SIZE %s
More information about the llvm-commits
mailing list