1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

[llvm/Object] - Add a test for "empty string table" error.

This error was never tested. In this patch I improved
the error message, added the test case and also simplified
the code that processes a similar error right below.

Differential revision: https://reviews.llvm.org/D65396

llvm-svn: 367391
This commit is contained in:
George Rimar 2019-07-31 08:12:01 +00:00
parent f23c0662fd
commit 9a12e50547
2 changed files with 24 additions and 5 deletions

View File

@ -599,12 +599,10 @@ ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
return V.takeError(); return V.takeError();
ArrayRef<char> Data = *V; ArrayRef<char> Data = *V;
if (Data.empty()) if (Data.empty())
// TODO: this error is untested. return createError("SHT_STRTAB string table section " +
return createError("empty string table"); getSecIndexForError(this, Section) + " is empty");
if (Data.back() != '\0') if (Data.back() != '\0')
return createError(object::getELFSectionTypeName(getHeader()->e_machine, return createError("SHT_STRTAB string table section " +
Section->sh_type) +
" string table section " +
getSecIndexForError(this, Section) + getSecIndexForError(this, Section) +
" is non-null terminated"); " is non-null terminated");
return StringRef(Data.begin(), Data.size()); return StringRef(Data.begin(), Data.size());

View File

@ -606,3 +606,24 @@ FileHeader:
Type: ET_REL Type: ET_REL
Machine: EM_X86_64 Machine: EM_X86_64
SHOffset: 0xffffffffffffffff SHOffset: 0xffffffffffffffff
## Check that llvm-objdump reports an error when it tries to dump a
## symbol name and .strtab is empty.
# RUN: yaml2obj %s --docnum=29 -o %t29
# RUN: not llvm-objdump -syms %t29 2>&1 | FileCheck -DFILE=%t29 --check-prefix=STRTAB-EMPTY2 %s
# STRTAB-EMPTY2: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .strtab
Type: SHT_STRTAB
Content: ""
Symbols:
- Name: foo