Index: llvm/test/tools/llvm-readobj/ELF/symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/symbols.test +++ llvm/test/tools/llvm-readobj/ELF/symbols.test @@ -129,7 +129,6 @@ # 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 @@ # 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 @@ # 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 Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -336,7 +336,8 @@ 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 StrTable, bool IsDynamic) const; Expected getSymbolSectionIndex(const Elf_Sym *Symbol, const Elf_Sym *FirstSym) const; @@ -670,7 +671,8 @@ template void ELFDumper::printSymbolsHelper(bool IsDynamic) const { - StringRef StrTable, SymtabName; + Optional StrTable; + StringRef SymtabName; size_t Entries = 0; Elf_Sym_Range Syms(nullptr, nullptr); const ELFFile *Obj = ObjF->getELFFile(); @@ -753,8 +755,9 @@ virtual void printSymtabMessage(const ELFFile *Obj, StringRef Name, size_t Offset, bool NonVisibilityBitsUsed) {} virtual void printSymbol(const ELFFile *Obj, const Elf_Sym *Symbol, - const Elf_Sym *FirstSym, StringRef StrTable, - bool IsDynamic, bool NonVisibilityBitsUsed) = 0; + const Elf_Sym *FirstSym, + Optional StrTable, bool IsDynamic, + bool NonVisibilityBitsUsed) = 0; virtual void printProgramHeaders(const ELFFile *Obj, bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) = 0; @@ -907,7 +910,7 @@ 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 StrTable, bool IsDynamic, bool NonVisibilityBitsUsed) override; std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *FirstSym); @@ -976,7 +979,7 @@ 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 StrTable, bool IsDynamic, bool /*NonVisibilityBitsUsed*/) override; void printProgramHeaders(const ELFO *Obj); void printSectionMapping(const ELFO *Obj) {} @@ -1175,10 +1178,13 @@ template std::string ELFDumper::getFullSymbolName(const Elf_Sym *Symbol, - StringRef StrTable, + Optional StrTable, bool IsDynamic) const { + if (!StrTable) + return ""; + std::string SymbolName; - if (Expected NameOrErr = Symbol->getName(StrTable)) { + if (Expected NameOrErr = Symbol->getName(*StrTable)) { SymbolName = maybeDemangle(*NameOrErr); } else { reportUniqueWarning(NameOrErr.takeError()); @@ -3966,8 +3972,9 @@ template void GNUStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, - const Elf_Sym *FirstSym, StringRef StrTable, - bool IsDynamic, bool NonVisibilityBitsUsed) { + const Elf_Sym *FirstSym, + Optional StrTable, bool IsDynamic, + bool NonVisibilityBitsUsed) { static int Idx = 0; static bool Dynamic = true; @@ -6263,8 +6270,8 @@ template void LLVMStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, - const Elf_Sym *First, StringRef StrTable, - bool IsDynamic, + const Elf_Sym *First, + Optional StrTable, bool IsDynamic, bool /*NonVisibilityBitsUsed*/) { std::string FullSymbolName = this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic);