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@plt: +# CHECK: bl {{.*}} <_Znwm@plt> 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__@plt: +# CHECK: __cxa_finalize@plt: +# CHECK: callq {{.*}} <__cxa_finalize@plt> Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -56,6 +56,7 @@ #include "llvm/Support/InitLLVM.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/StringSaver.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" @@ -1236,6 +1237,34 @@ llvm_unreachable("Unsupported binary format"); } +static void addPltEntries(const ObjectFile *Obj, + std::map &AllSymbols, + StringSaver &Saver) { + 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(Obj)) { + for (auto PltEntry : ElfObj->getPltAddresses()) { + SymbolRef Symbol(PltEntry.first, ElfObj); + + uint8_t SymbolType = getElfSymbolType(Obj, Symbol); + + Expected NameOrErr = Symbol.getName(); + if (!NameOrErr) + report_error(Obj->getFileName(), NameOrErr.takeError()); + if (NameOrErr->empty()) + continue; + StringRef Name = Saver.save((*NameOrErr + "@plt").str()); + + AllSymbols[*Plt].emplace_back(PltEntry.second, Name, SymbolType); + } + } +} + static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (StartAddress > StopAddress) error("Start address should be less than stop address"); @@ -1343,6 +1372,10 @@ if (AllSymbols.empty() && Obj->isELF()) addDynamicElfSymbols(Obj, AllSymbols); + BumpPtrAllocator A; + StringSaver Saver(A); + addPltEntries(Obj, AllSymbols, Saver); + // Create a mapping from virtual address to section. std::vector> SectionAddresses; for (SectionRef Sec : Obj->sections())