llvm.org GIT mirror llvm / cbbdae4
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285753 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
3 changed file(s) with 27 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
7272
7373 const Elf_Ehdr *Header;
7474 const Elf_Shdr *SectionHeaderTable = nullptr;
75 StringRef DotShstrtab; // Section header string table.
7675
7776 public:
7877 template
153152 }
154153
155154 uint64_t getNumSections() const;
156 uint32_t getStringTableIndex() const;
155 ErrorOr getSectionStringTable() const;
156 uint32_t getSectionStringTableIndex() const;
157157 uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
158158 const Elf_Shdr *SymTab,
159159 ArrayRef ShndxTable) const;
174174 }
175175
176176 ErrorOr getSectionName(const Elf_Shdr *Section) const;
177 ErrorOr getSectionName(const Elf_Shdr *Section,
178 StringRef DotShstrtab) const;
177179 template
178180 ErrorOr> getSectionContentsAsArray(const Elf_Shdr *Sec) const;
179181 ErrorOr > getSectionContents(const Elf_Shdr *Sec) const;
298300 return Header->e_shnum;
299301 }
300302
301 template uint32_t ELFFile::getStringTableIndex() const {
303 template
304 uint32_t ELFFile::getSectionStringTableIndex() const {
302305 if (Header->e_shstrndx == ELF::SHN_XINDEX)
303306 return SectionHeaderTable->sh_link;
304307 return Header->e_shstrndx;
305308 }
306309
307310 template
308 ELFFile::ELFFile(StringRef Object, std::error_code &EC)
309 : Buf(Object) {
311 ErrorOr ELFFile::getSectionStringTable() const {
312 uint32_t Index = getSectionStringTableIndex();
313 if (!Index) // no section string table.
314 return "";
315 ErrorOr StrTabSecOrErr = getSection(Index);
316 if (std::error_code EC = StrTabSecOrErr.getError())
317 return EC;
318 return getStringTable(*StrTabSecOrErr);
319 }
320
321 template
322 ELFFile::ELFFile(StringRef Object, std::error_code &EC) : Buf(Object) {
310323 const uint64_t FileSize = Buf.size();
311324
312325 if (sizeof(Elf_Ehdr) > FileSize) {
354367 // Section table goes past end of file!
355368 EC = object_error::parse_failed;
356369 return;
357 }
358
359 // Get string table sections.
360 uint32_t StringTableIndex = getStringTableIndex();
361 if (StringTableIndex) {
362 ErrorOr StrTabSecOrErr = getSection(StringTableIndex);
363 if ((EC = StrTabSecOrErr.getError()))
364 return;
365
366 ErrorOr StringTableOrErr = getStringTable(*StrTabSecOrErr);
367 if ((EC = StringTableOrErr.getError()))
368 return;
369 DotShstrtab = *StringTableOrErr;
370370 }
371371
372372 EC = std::error_code();
471471 template
472472 ErrorOr
473473 ELFFile::getSectionName(const Elf_Shdr *Section) const {
474 ErrorOr Table = getSectionStringTable();
475 if (std::error_code EC = Table.getError())
476 return EC;
477 return getSectionName(Section, *Table);
478 }
479
480 template
481 ErrorOr ELFFile::getSectionName(const Elf_Shdr *Section,
482 StringRef DotShstrtab) const {
474483 uint32_t Offset = Section->sh_name;
475484 if (Offset == 0)
476485 return StringRef();
test/Object/Inputs/invalid-section-index2.elf less more
Binary diff not shown
4141 INVALID-DYNSYM-SIZE: Invalid entity size
4242
4343 RUN: not llvm-readobj -t %p/Inputs/invalid-section-index.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-INDEX %s
44 RUN: not llvm-readobj -t %p/Inputs/invalid-section-index2.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-INDEX %s
4544 INVALID-SECTION-INDEX: Invalid section index
4645
4746 RUN: not llvm-readobj -s %p/Inputs/invalid-section-size.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-SIZE %s