Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -945,6 +945,9 @@ template void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec, const Elf_Shdr *SymTab); + template + void printRelRelaReloc(const RelTy &Rel, StringRef SymbolName); + template void printDynamicRelocation(const RelTy &Rel); void printSymbols(); @@ -6198,23 +6201,28 @@ return; } - std::string TargetName = Target->second; + printRelRelaReloc(Rel, Target->second); +} + +template +template +void LLVMStyle::printRelRelaReloc(const RelTy &Rel, + StringRef SymbolName) { SmallString<32> RelocName; this->Obj.getRelocationTypeName(Rel.getType(this->Obj.isMips64EL()), RelocName); - uintX_t Addend = getAddend(Rel).getValueOr(0); if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); W.printHex("Offset", Rel.r_offset); W.printNumber("Type", RelocName, (int)Rel.getType(this->Obj.isMips64EL())); - W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-", + W.printNumber("Symbol", !SymbolName.empty() ? SymbolName : "-", Rel.getSymbol(this->Obj.isMips64EL())); W.printHex("Addend", Addend); } else { raw_ostream &OS = W.startLine(); OS << W.hex(Rel.r_offset) << " " << RelocName << " " - << (!TargetName.empty() ? TargetName : "-") << " " << W.hex(Addend) + << (!SymbolName.empty() ? SymbolName : "-") << " " << W.hex(Addend) << "\n"; } } @@ -6407,25 +6415,9 @@ template template void LLVMStyle::printDynamicRelocation(const RelTy &Rel) { - SmallString<32> RelocName; - this->Obj.getRelocationTypeName(Rel.getType(this->Obj.isMips64EL()), - RelocName); - std::string SymbolName = - getSymbolForReloc(this->Obj, this->FileName, this->dumper(), Rel).Name; - - uintX_t Addend = getAddend(Rel).getValueOr(0); - if (opts::ExpandRelocs) { - DictScope Group(W, "Relocation"); - W.printHex("Offset", Rel.r_offset); - W.printNumber("Type", RelocName, (int)Rel.getType(this->Obj.isMips64EL())); - W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-"); - W.printHex("Addend", Addend); - } else { - raw_ostream &OS = W.startLine(); - OS << W.hex(Rel.r_offset) << " " << RelocName << " " - << (!SymbolName.empty() ? SymbolName : "-") << " " << W.hex(Addend) - << "\n"; - } + RelSymbol S = + getSymbolForReloc(this->Obj, this->FileName, this->dumper(), Rel); + printRelRelaReloc(Rel, S.Name); } template