1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[llvm-readelf] - Do not report a misleading warning when there is no string table.

This is a follow-up for D82955, which allows to continue dumping when a symbol table is broken.
When we are unable to get the string table and trying to print symbols,
the existent tool logic together with D82955 reports an error:

"st_name (0x??) is past the end of the string table of size 0x??"

Though, when there is no string table, this message becomes misleading and excessive.
It is easy to fix it though and that is what this patch does.

Differential revision: https://reviews.llvm.org/D83042
This commit is contained in:
Georgii Rymar 2020-07-02 16:06:26 +03:00
parent 73e2acf290
commit 1de44904a6
2 changed files with 19 additions and 16 deletions

View File

@ -129,7 +129,6 @@ DynamicSymbols:
# STRTAB-LINK-ERR-LLVM: Symbols [
# STRTAB-LINK-ERR-LLVM-NEXT: warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255
# STRTAB-LINK-ERR-LLVM-NEXT: warning: '[[FILE]]': st_name (0x0) is past the end of the string table of size 0x0
# STRTAB-LINK-ERR-LLVM-NEXT: Symbol {
# STRTAB-LINK-ERR-LLVM-NEXT: Name: <?> (0)
# STRTAB-LINK-ERR-LLVM-NEXT: Value: 0x0
@ -139,7 +138,6 @@ DynamicSymbols:
# STRTAB-LINK-ERR-LLVM-NEXT: Other: 0
# STRTAB-LINK-ERR-LLVM-NEXT: Section: Undefined (0x0)
# STRTAB-LINK-ERR-LLVM-NEXT: }
# STRTAB-LINK-ERR-LLVM-NEXT: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x0
# STRTAB-LINK-ERR-LLVM-NEXT: Symbol {
# STRTAB-LINK-ERR-LLVM-NEXT: Name: <?> (1)
# STRTAB-LINK-ERR-LLVM-NEXT: Value: 0x1
@ -154,9 +152,7 @@ DynamicSymbols:
# STRTAB-LINK-ERR-GNU: warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255
# STRTAB-LINK-ERR-GNU: Symbol table '.symtab' contains 2 entries:
# STRTAB-LINK-ERR-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# STRTAB-LINK-ERR-GNU-NEXT: warning: '[[FILE]]': st_name (0x0) is past the end of the string table of size 0x0
# STRTAB-LINK-ERR-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND <?>
# STRTAB-LINK-ERR-GNU-NEXT: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x0
# STRTAB-LINK-ERR-GNU-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT 1 <?>
--- !ELF

View File

@ -336,7 +336,8 @@ public:
Elf_Rel_Range dyn_rels() const;
Elf_Rela_Range dyn_relas() const;
Elf_Relr_Range dyn_relrs() const;
std::string getFullSymbolName(const Elf_Sym *Symbol, StringRef StrTable,
std::string getFullSymbolName(const Elf_Sym *Symbol,
Optional<StringRef> StrTable,
bool IsDynamic) const;
Expected<unsigned> getSymbolSectionIndex(const Elf_Sym *Symbol,
const Elf_Sym *FirstSym) const;
@ -670,7 +671,8 @@ ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr *Sec) const {
template <class ELFT>
void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
StringRef StrTable, SymtabName;
Optional<StringRef> StrTable;
StringRef SymtabName;
size_t Entries = 0;
Elf_Sym_Range Syms(nullptr, nullptr);
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
@ -753,8 +755,9 @@ public:
virtual void printSymtabMessage(const ELFFile<ELFT> *Obj, StringRef Name,
size_t Offset, bool NonVisibilityBitsUsed) {}
virtual void printSymbol(const ELFFile<ELFT> *Obj, const Elf_Sym *Symbol,
const Elf_Sym *FirstSym, StringRef StrTable,
bool IsDynamic, bool NonVisibilityBitsUsed) = 0;
const Elf_Sym *FirstSym,
Optional<StringRef> StrTable, bool IsDynamic,
bool NonVisibilityBitsUsed) = 0;
virtual void printProgramHeaders(const ELFFile<ELFT> *Obj,
bool PrintProgramHeaders,
cl::boolOrDefault PrintSectionMapping) = 0;
@ -907,7 +910,7 @@ private:
void printRelocation(const ELFO *Obj, const Elf_Sym *Sym,
StringRef SymbolName, const Elf_Rela &R, bool IsRela);
void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First,
StringRef StrTable, bool IsDynamic,
Optional<StringRef> StrTable, bool IsDynamic,
bool NonVisibilityBitsUsed) override;
std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol,
const Elf_Sym *FirstSym);
@ -976,7 +979,7 @@ private:
void printDynamicSymbols(const ELFO *Obj);
void printSymbolSection(const Elf_Sym *Symbol, const Elf_Sym *First);
void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First,
StringRef StrTable, bool IsDynamic,
Optional<StringRef> StrTable, bool IsDynamic,
bool /*NonVisibilityBitsUsed*/) override;
void printProgramHeaders(const ELFO *Obj);
void printSectionMapping(const ELFO *Obj) {}
@ -1175,10 +1178,13 @@ ELFDumper<ELFT>::getSymbolVersionByIndex(uint32_t SymbolVersionIndex,
template <typename ELFT>
std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
StringRef StrTable,
Optional<StringRef> StrTable,
bool IsDynamic) const {
if (!StrTable)
return "<?>";
std::string SymbolName;
if (Expected<StringRef> NameOrErr = Symbol->getName(StrTable)) {
if (Expected<StringRef> NameOrErr = Symbol->getName(*StrTable)) {
SymbolName = maybeDemangle(*NameOrErr);
} else {
reportUniqueWarning(NameOrErr.takeError());
@ -3966,8 +3972,9 @@ std::string GNUStyle<ELFT>::getSymbolSectionNdx(const ELFO *Obj,
template <class ELFT>
void GNUStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol,
const Elf_Sym *FirstSym, StringRef StrTable,
bool IsDynamic, bool NonVisibilityBitsUsed) {
const Elf_Sym *FirstSym,
Optional<StringRef> StrTable, bool IsDynamic,
bool NonVisibilityBitsUsed) {
static int Idx = 0;
static bool Dynamic = true;
@ -6263,8 +6270,8 @@ void LLVMStyle<ELFT>::printSymbolSection(const Elf_Sym *Symbol,
template <class ELFT>
void LLVMStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol,
const Elf_Sym *First, StringRef StrTable,
bool IsDynamic,
const Elf_Sym *First,
Optional<StringRef> StrTable, bool IsDynamic,
bool /*NonVisibilityBitsUsed*/) {
std::string FullSymbolName =
this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic);