[PATCH] D50204: [llvm-objdump] Label calls to the PLT
Joel Galenson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 2 15:40:16 PDT 2018
jgalenson created this revision.
jgalenson added reviewers: pcc, eugenis, echristo, paulsemel.
Herald added a reviewer: javed.absar.
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D50204
Files:
test/tools/llvm-objdump/AArch64/Inputs/simple-inheritance.elf-aarch64
test/tools/llvm-objdump/AArch64/plt.test
test/tools/llvm-objdump/X86/plt.test
tools/llvm-objdump/llvm-objdump.cpp
Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -1235,6 +1235,37 @@
llvm_unreachable("Unsupported binary format");
}
+static void addPltEntries(const ObjectFile *Obj,
+ std::map<SectionRef, SectionSymbolsTy> &AllSymbols,
+ std::vector<std::string> &PltEntryNames) {
+ const SectionRef *Plt =
+ &*find_if(Obj->sections(), [&](const SectionRef &Section) {
+ StringRef Str;
+ return !Section.getName(Str) && Str == ".plt";
+ });
+ if (!Plt)
+ return;
+ if (auto *ElfObj = dyn_cast<ELFObjectFileBase>(Obj)) {
+ for (auto PltEntry : ElfObj->getPltAddresses()) {
+ SymbolRef Symbol(PltEntry.first, ElfObj);
+
+ uint8_t SymbolType = getElfSymbolType(Obj, Symbol);
+
+ Expected<StringRef> Name = Symbol.getName();
+ if (!Name)
+ report_error(Obj->getFileName(), Name.takeError());
+ if (Name->empty())
+ continue;
+
+ // We need to keep a permanent copy of the new name so the StringRef in
+ // AllSymbols works.
+ PltEntryNames.push_back((*Name + "@plt").str());
+
+ AllSymbols[*Plt].emplace_back(PltEntry.second, PltEntryNames.back(), SymbolType);
+ }
+ }
+}
+
static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
if (StartAddress > StopAddress)
error("Start address should be less than stop address");
@@ -1342,6 +1373,9 @@
if (AllSymbols.empty() && Obj->isELF())
addDynamicElfSymbols(Obj, AllSymbols);
+ std::vector<std::string> PltEntryNames;
+ addPltEntries(Obj, AllSymbols, PltEntryNames);
+
// Create a mapping from virtual address to section.
std::vector<std::pair<uint64_t, SectionRef>> SectionAddresses;
for (SectionRef Sec : Obj->sections())
Index: test/tools/llvm-objdump/X86/plt.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objdump/X86/plt.test
@@ -0,0 +1,6 @@
+// RUN: llvm-objdump -d %p/Inputs/stripped-elf.so | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK: __gmon_start__ at plt:
+# CHECK: __cxa_finalize at plt:
+# CHECK: callq {{.*}} <__cxa_finalize at plt>
\ No newline at end of file
Index: test/tools/llvm-objdump/AArch64/plt.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objdump/AArch64/plt.test
@@ -0,0 +1,5 @@
+// RUN: llvm-objdump -d %p/Inputs/simple-inheritance.elf-aarch64 | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK: _Znwm at plt:
+# CHECK: bl {{.*}} <_Znwm at plt>
\ No newline at end of file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50204.158848.patch
Type: text/x-patch
Size: 2719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180802/b9f75c33/attachment.bin>
More information about the llvm-commits
mailing list