aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-01-28 14:11:35 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-01-28 14:11:35 +0000
commit87fa2e66e715b0d1d457f519a6f668cc6f56e23a (patch)
treefe137ff5ed70ea7825d1b746a5345a812bcab7e7 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parentf02e9f3783434a7440d563c046d0c677b758bb56 (diff)
downloadllvm-87fa2e66e715b0d1d457f519a6f668cc6f56e23a.zip
llvm-87fa2e66e715b0d1d457f519a6f668cc6f56e23a.tar.gz
llvm-87fa2e66e715b0d1d457f519a6f668cc6f56e23a.tar.bz2
[llvm-objdump] - Print LMAs when dumping section headers.
When --section-headers is used, GNU objdump prints both LMA and VMA for sections. llvm-objdump does not do that what makes it's output be slightly inconsistent. Patch teaches llvm-objdump to print LMA/VMA for ELF file formats. The behavior for other formats remains unchanged. Differential revision: https://reviews.llvm.org/D57146 llvm-svn: 352366
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index c84d8b6..1ba0cfc 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -185,6 +185,10 @@ static cl::alias SectionHeadersShorter("h",
cl::NotHidden,
cl::aliasopt(SectionHeaders));
+static cl::opt<bool>
+ ShowLMA("show-lma",
+ cl::desc("Display LMA column when dumping ELF section headers"));
+
cl::list<std::string>
llvm::FilterSections("section", cl::desc("Operate on the specified sections only. "
"With -macho dump segment,section"));
@@ -1517,25 +1521,48 @@ void llvm::printDynamicRelocations(const ObjectFile *Obj) {
}
}
+// Returns true if we need to show LMA column when dumping section headers. We
+// show it only when the platform is ELF and either we have at least one section
+// whose VMA and LMA are different and/or when --show-lma flag is used.
+static bool shouldDisplayLMA(const ObjectFile *Obj) {
+ if (!Obj->isELF())
+ return false;
+ for (const SectionRef &S : ToolSectionFilter(*Obj))
+ if (S.getAddress() != getELFSectionLMA(S))
+ return true;
+ return ShowLMA;
+}
+
void llvm::printSectionHeaders(const ObjectFile *Obj) {
- outs() << "Sections:\n"
- "Idx Name Size Address Type\n";
+ bool HasLMAColumn = shouldDisplayLMA(Obj);
+ if (HasLMAColumn)
+ outs() << "Sections:\n"
+ "Idx Name Size VMA LMA "
+ "Type\n";
+ else
+ outs() << "Sections:\n"
+ "Idx Name Size VMA Type\n";
+
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
StringRef Name;
error(Section.getName(Name));
- uint64_t Address = Section.getAddress();
- if (shouldAdjustVA(Section))
- Address += AdjustVMA;
-
+ uint64_t VMA = Section.getAddress();
uint64_t Size = Section.getSize();
bool Text = Section.isText();
bool Data = Section.isData();
bool BSS = Section.isBSS();
std::string Type = (std::string(Text ? "TEXT " : "") +
(Data ? "DATA " : "") + (BSS ? "BSS" : ""));
- outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n",
- (unsigned)Section.getIndex(), Name.str().c_str(), Size,
- Address, Type.c_str());
+
+ if (HasLMAColumn)
+ outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %016" PRIx64
+ " %s\n",
+ (unsigned)Section.getIndex(), Name.str().c_str(), Size,
+ VMA, getELFSectionLMA(Section), Type.c_str());
+ else
+ outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n",
+ (unsigned)Section.getIndex(), Name.str().c_str(), Size,
+ VMA, Type.c_str());
}
outs() << "\n";
}