[llvm] 4368739 - [llvm-readobj] - Remove code duplication when printing dynamic relocations. NFCI.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 06:11:46 PDT 2020
Author: Georgii Rymar
Date: 2020-09-07T16:11:12+03:00
New Revision: 4368739941eb1336197dde0e92eb23ce79739ac7
URL: https://github.com/llvm/llvm-project/commit/4368739941eb1336197dde0e92eb23ce79739ac7
DIFF: https://github.com/llvm/llvm-project/commit/4368739941eb1336197dde0e92eb23ce79739ac7.diff
LOG: [llvm-readobj] - Remove code duplication when printing dynamic relocations. NFCI.
LLVM style code can be simplified to avoid the duplication of logic
related to printing dynamic relocations.
Differential revision: https://reviews.llvm.org/D87089
Added:
Modified:
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 9c1b2e320937..df3799c8fbe6 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -960,6 +960,7 @@ template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
void printRelrReloc(const Elf_Relr &R) override;
void printDynamicReloc(const Relocation<ELFT> &R) override;
+ void printRelRelaReloc(const Relocation<ELFT> &R, StringRef SymbolName);
void printSymbols();
void printDynamicSymbols();
void printSymbolSection(const Elf_Sym *Symbol, const Elf_Sym *First);
@@ -6156,7 +6157,12 @@ void LLVMStyle<ELFT>::printReloc(const Relocation<ELFT> &R, unsigned RelIndex,
return;
}
- std::string TargetName = Target->Name;
+ printRelRelaReloc(R, Target->Name);
+}
+
+template <class ELFT>
+void LLVMStyle<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
+ StringRef SymbolName) {
SmallString<32> RelocName;
this->Obj.getRelocationTypeName(R.Type, RelocName);
@@ -6165,12 +6171,12 @@ void LLVMStyle<ELFT>::printReloc(const Relocation<ELFT> &R, unsigned RelIndex,
DictScope Group(W, "Relocation");
W.printHex("Offset", R.Offset);
W.printNumber("Type", RelocName, R.Type);
- W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-", R.Symbol);
+ W.printNumber("Symbol", !SymbolName.empty() ? SymbolName : "-", R.Symbol);
W.printHex("Addend", Addend);
} else {
raw_ostream &OS = W.startLine();
OS << W.hex(R.Offset) << " " << RelocName << " "
- << (!TargetName.empty() ? TargetName : "-") << " " << W.hex(Addend)
+ << (!SymbolName.empty() ? SymbolName : "-") << " " << W.hex(Addend)
<< "\n";
}
}
@@ -6362,24 +6368,9 @@ template <class ELFT> void LLVMStyle<ELFT>::printDynamicRelocations() {
template <class ELFT>
void LLVMStyle<ELFT>::printDynamicReloc(const Relocation<ELFT> &R) {
- SmallString<32> RelocName;
- this->Obj.getRelocationTypeName(R.Type, RelocName);
- std::string SymbolName =
- getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R).Name;
-
- uintX_t Addend = R.Addend.getValueOr(0);
- if (opts::ExpandRelocs) {
- DictScope Group(W, "Relocation");
- W.printHex("Offset", R.Offset);
- W.printNumber("Type", RelocName, R.Type);
- W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-");
- W.printHex("Addend", Addend);
- } else {
- raw_ostream &OS = W.startLine();
- OS << W.hex(R.Offset) << " " << RelocName << " "
- << (!SymbolName.empty() ? SymbolName : "-") << " " << W.hex(Addend)
- << "\n";
- }
+ RelSymbol<ELFT> S =
+ getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R);
+ printRelRelaReloc(R, S.Name);
}
template <class ELFT>
More information about the llvm-commits
mailing list