Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit e47abe7

Browse files
committed
[llvm-objdump] Label calls to the PLT.
Differential Revision: https://reviews.llvm.org/D50204 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340611 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 77a17af commit e47abe7

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: llvm-objdump -d %p/Inputs/cfi.elf-aarch64 | FileCheck %s
2+
3+
# CHECK: Disassembly of section .plt:
4+
# CHECK: __cfi_slowpath@plt:
5+
# CHECK: bl {{.*}} <__cfi_slowpath@plt>
Binary file not shown.
Binary file not shown.

test/tools/llvm-objdump/X86/plt.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: llvm-objdump -d %p/Inputs/stripped-elf.so | FileCheck -check-prefix=64 %s
2+
// RUN: llvm-objdump -d %p/Inputs/hello.exe.elf-i386 | FileCheck -check-prefix=32 %s
3+
// RUN: llvm-objdump -d %p/Inputs/hello.exe.nopie.elf-i386 | FileCheck -check-prefix=32 %s
4+
5+
# 64: Disassembly of section .plt:
6+
# 64: __gmon_start__@plt:
7+
# 64: __cxa_finalize@plt:
8+
# 64: callq {{.*}} <__cxa_finalize@plt>
9+
10+
# 32: Disassembly of section .plt:
11+
# 32: puts@plt:
12+
# 32: __libc_start_main@plt:
13+
# 32: calll {{.*}} <puts@plt>
14+
# 32: calll {{.*}} <__libc_start_main@plt>

tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "llvm/Support/InitLLVM.h"
5757
#include "llvm/Support/MemoryBuffer.h"
5858
#include "llvm/Support/SourceMgr.h"
59+
#include "llvm/Support/StringSaver.h"
5960
#include "llvm/Support/TargetRegistry.h"
6061
#include "llvm/Support/TargetSelect.h"
6162
#include "llvm/Support/raw_ostream.h"
@@ -1235,6 +1236,37 @@ addDynamicElfSymbols(const ObjectFile *Obj,
12351236
llvm_unreachable("Unsupported binary format");
12361237
}
12371238

1239+
static void addPltEntries(const ObjectFile *Obj,
1240+
std::map<SectionRef, SectionSymbolsTy> &AllSymbols,
1241+
StringSaver &Saver) {
1242+
Optional<SectionRef> Plt = None;
1243+
for (const SectionRef &Section : Obj->sections()) {
1244+
StringRef Name;
1245+
if (Section.getName(Name))
1246+
continue;
1247+
if (Name == ".plt")
1248+
Plt = Section;
1249+
}
1250+
if (!Plt)
1251+
return;
1252+
if (auto *ElfObj = dyn_cast<ELFObjectFileBase>(Obj)) {
1253+
for (auto PltEntry : ElfObj->getPltAddresses()) {
1254+
SymbolRef Symbol(PltEntry.first, ElfObj);
1255+
1256+
uint8_t SymbolType = getElfSymbolType(Obj, Symbol);
1257+
1258+
Expected<StringRef> NameOrErr = Symbol.getName();
1259+
if (!NameOrErr)
1260+
report_error(Obj->getFileName(), NameOrErr.takeError());
1261+
if (NameOrErr->empty())
1262+
continue;
1263+
StringRef Name = Saver.save((*NameOrErr + "@plt").str());
1264+
1265+
AllSymbols[*Plt].emplace_back(PltEntry.second, Name, SymbolType);
1266+
}
1267+
}
1268+
}
1269+
12381270
static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
12391271
if (StartAddress > StopAddress)
12401272
error("Start address should be less than stop address");
@@ -1342,6 +1374,10 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
13421374
if (AllSymbols.empty() && Obj->isELF())
13431375
addDynamicElfSymbols(Obj, AllSymbols);
13441376

1377+
BumpPtrAllocator A;
1378+
StringSaver Saver(A);
1379+
addPltEntries(Obj, AllSymbols, Saver);
1380+
13451381
// Create a mapping from virtual address to section.
13461382
std::vector<std::pair<uint64_t, SectionRef>> SectionAddresses;
13471383
for (SectionRef Sec : Obj->sections())

0 commit comments

Comments
 (0)