2013-01-06 11:56:49 +08:00
|
|
|
//===-- ELFDump.cpp - ELF-specific dumper -----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-01-06 11:56:49 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This file implements the ELF-specific dumper for llvm-objdump.
|
2013-01-06 11:56:49 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-objdump.h"
|
2019-01-18 19:33:26 +08:00
|
|
|
#include "llvm/Demangle/Demangle.h"
|
2013-08-09 06:27:13 +08:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
2013-01-06 11:56:49 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
2019-04-15 23:31:42 +08:00
|
|
|
namespace llvm {
|
2018-07-25 19:09:20 +08:00
|
|
|
template <class ELFT>
|
2019-04-15 23:31:42 +08:00
|
|
|
static Expected<StringRef> getDynamicStrTab(const ELFFile<ELFT> *Elf) {
|
2018-07-25 19:09:20 +08:00
|
|
|
auto DynamicEntriesOrError = Elf->dynamicEntries();
|
|
|
|
if (!DynamicEntriesOrError)
|
|
|
|
return DynamicEntriesOrError.takeError();
|
|
|
|
|
2019-04-07 16:28:56 +08:00
|
|
|
for (const typename ELFT::Dyn &Dyn : *DynamicEntriesOrError) {
|
2018-07-25 19:09:20 +08:00
|
|
|
if (Dyn.d_tag == ELF::DT_STRTAB) {
|
|
|
|
auto MappedAddrOrError = Elf->toMappedAddr(Dyn.getPtr());
|
|
|
|
if (!MappedAddrOrError)
|
|
|
|
consumeError(MappedAddrOrError.takeError());
|
|
|
|
return StringRef(reinterpret_cast<const char *>(*MappedAddrOrError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the dynamic segment is not present, we fall back on the sections.
|
|
|
|
auto SectionsOrError = Elf->sections();
|
|
|
|
if (!SectionsOrError)
|
|
|
|
return SectionsOrError.takeError();
|
|
|
|
|
2019-04-07 16:28:56 +08:00
|
|
|
for (const typename ELFT::Shdr &Sec : *SectionsOrError) {
|
2018-07-25 19:09:20 +08:00
|
|
|
if (Sec.sh_type == ELF::SHT_DYNSYM)
|
|
|
|
return Elf->getStringTableForSymtab(Sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return createError("dynamic string table not found");
|
|
|
|
}
|
|
|
|
|
2019-01-18 19:33:26 +08:00
|
|
|
template <class ELFT>
|
2019-04-09 00:24:08 +08:00
|
|
|
static Error getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
|
|
|
const RelocationRef &RelRef,
|
|
|
|
SmallVectorImpl<char> &Result) {
|
2019-01-18 19:33:26 +08:00
|
|
|
const ELFFile<ELFT> &EF = *Obj->getELFFile();
|
|
|
|
DataRefImpl Rel = RelRef.getRawDataRefImpl();
|
|
|
|
auto SecOrErr = EF.getSection(Rel.d.a);
|
|
|
|
if (!SecOrErr)
|
2019-04-09 00:24:08 +08:00
|
|
|
return SecOrErr.takeError();
|
2019-01-18 19:33:26 +08:00
|
|
|
|
|
|
|
int64_t Addend = 0;
|
|
|
|
// If there is no Symbol associated with the relocation, we set the undef
|
|
|
|
// boolean value to 'true'. This will prevent us from calling functions that
|
|
|
|
// requires the relocation to be associated with a symbol.
|
|
|
|
//
|
|
|
|
// In SHT_REL case we would need to read the addend from section data.
|
|
|
|
// GNU objdump does not do that and we just follow for simplicity atm.
|
|
|
|
bool Undef = false;
|
|
|
|
if ((*SecOrErr)->sh_type == ELF::SHT_RELA) {
|
2019-04-07 16:29:04 +08:00
|
|
|
const typename ELFT::Rela *ERela = Obj->getRela(Rel);
|
2019-01-18 19:33:26 +08:00
|
|
|
Addend = ERela->r_addend;
|
|
|
|
Undef = ERela->getSymbol(false) == 0;
|
|
|
|
} else if ((*SecOrErr)->sh_type != ELF::SHT_REL) {
|
2019-04-09 00:24:08 +08:00
|
|
|
return make_error<BinaryError>();
|
2019-01-18 19:33:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default scheme is to print Target, as well as "+ <addend>" for nonzero
|
|
|
|
// addend. Should be acceptable for all normal purposes.
|
|
|
|
std::string FmtBuf;
|
|
|
|
raw_string_ostream Fmt(FmtBuf);
|
|
|
|
|
|
|
|
if (!Undef) {
|
|
|
|
symbol_iterator SI = RelRef.getSymbol();
|
2019-04-07 16:28:56 +08:00
|
|
|
const typename ELFT::Sym *Sym = Obj->getSymbol(SI->getRawDataRefImpl());
|
2019-01-18 19:33:26 +08:00
|
|
|
if (Sym->getType() == ELF::STT_SECTION) {
|
|
|
|
Expected<section_iterator> SymSI = SI->getSection();
|
|
|
|
if (!SymSI)
|
2019-04-09 00:24:08 +08:00
|
|
|
return SymSI.takeError();
|
2019-04-07 16:28:56 +08:00
|
|
|
const typename ELFT::Shdr *SymSec =
|
|
|
|
Obj->getSection((*SymSI)->getRawDataRefImpl());
|
2019-01-18 19:33:26 +08:00
|
|
|
auto SecName = EF.getSectionName(SymSec);
|
|
|
|
if (!SecName)
|
2019-04-09 00:24:08 +08:00
|
|
|
return SecName.takeError();
|
2019-01-18 19:33:26 +08:00
|
|
|
Fmt << *SecName;
|
|
|
|
} else {
|
|
|
|
Expected<StringRef> SymName = SI->getName();
|
|
|
|
if (!SymName)
|
2019-04-09 00:24:08 +08:00
|
|
|
return SymName.takeError();
|
2019-01-18 19:33:26 +08:00
|
|
|
if (Demangle)
|
|
|
|
Fmt << demangle(*SymName);
|
|
|
|
else
|
|
|
|
Fmt << *SymName;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Fmt << "*ABS*";
|
|
|
|
}
|
2019-11-19 19:58:50 +08:00
|
|
|
if (Addend != 0) {
|
|
|
|
Fmt << (Addend < 0
|
|
|
|
? "-"
|
|
|
|
: "+") << format("0x%" PRIx64,
|
|
|
|
(Addend < 0 ? -(uint64_t)Addend : (uint64_t)Addend));
|
|
|
|
}
|
2019-01-18 19:33:26 +08:00
|
|
|
Fmt.flush();
|
|
|
|
Result.append(FmtBuf.begin(), FmtBuf.end());
|
2019-04-09 00:24:08 +08:00
|
|
|
return Error::success();
|
2019-01-18 19:33:26 +08:00
|
|
|
}
|
|
|
|
|
2019-04-15 23:31:42 +08:00
|
|
|
Error getELFRelocationValueString(const ELFObjectFileBase *Obj,
|
|
|
|
const RelocationRef &Rel,
|
|
|
|
SmallVectorImpl<char> &Result) {
|
2019-01-18 19:33:26 +08:00
|
|
|
if (auto *ELF32LE = dyn_cast<ELF32LEObjectFile>(Obj))
|
|
|
|
return getRelocationValueString(ELF32LE, Rel, Result);
|
|
|
|
if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
|
|
|
|
return getRelocationValueString(ELF64LE, Rel, Result);
|
|
|
|
if (auto *ELF32BE = dyn_cast<ELF32BEObjectFile>(Obj))
|
|
|
|
return getRelocationValueString(ELF32BE, Rel, Result);
|
|
|
|
auto *ELF64BE = cast<ELF64BEObjectFile>(Obj);
|
|
|
|
return getRelocationValueString(ELF64BE, Rel, Result);
|
|
|
|
}
|
|
|
|
|
2019-01-28 22:11:35 +08:00
|
|
|
template <class ELFT>
|
|
|
|
static uint64_t getSectionLMA(const ELFFile<ELFT> *Obj,
|
|
|
|
const object::ELFSectionRef &Sec) {
|
|
|
|
auto PhdrRangeOrErr = Obj->program_headers();
|
|
|
|
if (!PhdrRangeOrErr)
|
2019-04-25 12:31:26 +08:00
|
|
|
report_fatal_error(toString(PhdrRangeOrErr.takeError()));
|
2019-01-28 22:11:35 +08:00
|
|
|
|
|
|
|
// Search for a PT_LOAD segment containing the requested section. Use this
|
|
|
|
// segment's p_addr to calculate the section's LMA.
|
2019-04-07 16:29:04 +08:00
|
|
|
for (const typename ELFT::Phdr &Phdr : *PhdrRangeOrErr)
|
2019-01-28 22:11:35 +08:00
|
|
|
if ((Phdr.p_type == ELF::PT_LOAD) && (Phdr.p_vaddr <= Sec.getAddress()) &&
|
|
|
|
(Phdr.p_vaddr + Phdr.p_memsz > Sec.getAddress()))
|
|
|
|
return Sec.getAddress() - Phdr.p_vaddr + Phdr.p_paddr;
|
|
|
|
|
|
|
|
// Return section's VMA if it isn't in a PT_LOAD segment.
|
|
|
|
return Sec.getAddress();
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:31:42 +08:00
|
|
|
uint64_t getELFSectionLMA(const object::ELFSectionRef &Sec) {
|
2019-01-28 22:11:35 +08:00
|
|
|
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Sec.getObject()))
|
|
|
|
return getSectionLMA(ELFObj->getELFFile(), Sec);
|
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Sec.getObject()))
|
|
|
|
return getSectionLMA(ELFObj->getELFFile(), Sec);
|
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64LEObjectFile>(Sec.getObject()))
|
|
|
|
return getSectionLMA(ELFObj->getELFFile(), Sec);
|
|
|
|
const auto *ELFObj = cast<ELF64BEObjectFile>(Sec.getObject());
|
|
|
|
return getSectionLMA(ELFObj->getELFFile(), Sec);
|
|
|
|
}
|
|
|
|
|
2018-07-25 19:09:20 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void printDynamicSection(const ELFFile<ELFT> *Elf, StringRef Filename) {
|
2019-04-07 16:19:55 +08:00
|
|
|
ArrayRef<typename ELFT::Dyn> DynamicEntries =
|
|
|
|
unwrapOrError(Elf->dynamicEntries(), Filename);
|
2020-01-16 21:13:23 +08:00
|
|
|
|
|
|
|
// Find the maximum tag name length to format the value column properly.
|
|
|
|
size_t MaxLen = 0;
|
|
|
|
for (const typename ELFT::Dyn &Dyn : DynamicEntries)
|
|
|
|
MaxLen = std::max(MaxLen, Elf->getDynamicTagAsString(Dyn.d_tag).size());
|
|
|
|
std::string TagFmt = " %-" + std::to_string(MaxLen) + "s ";
|
|
|
|
|
2018-07-25 19:09:20 +08:00
|
|
|
outs() << "Dynamic Section:\n";
|
2019-04-07 16:19:55 +08:00
|
|
|
for (const typename ELFT::Dyn &Dyn : DynamicEntries) {
|
2018-07-25 19:09:20 +08:00
|
|
|
if (Dyn.d_tag == ELF::DT_NULL)
|
|
|
|
continue;
|
|
|
|
|
2019-03-02 12:20:28 +08:00
|
|
|
std::string Str = Elf->getDynamicTagAsString(Dyn.d_tag);
|
2020-01-16 21:13:23 +08:00
|
|
|
outs() << format(TagFmt.c_str(), Str.c_str());
|
2018-07-25 19:09:20 +08:00
|
|
|
|
|
|
|
const char *Fmt =
|
|
|
|
ELFT::Is64Bits ? "0x%016" PRIx64 "\n" : "0x%08" PRIx64 "\n";
|
2019-02-28 00:37:15 +08:00
|
|
|
if (Dyn.d_tag == ELF::DT_NEEDED || Dyn.d_tag == ELF::DT_RPATH ||
|
|
|
|
Dyn.d_tag == ELF::DT_RUNPATH || Dyn.d_tag == ELF::DT_SONAME ||
|
|
|
|
Dyn.d_tag == ELF::DT_AUXILIARY || Dyn.d_tag == ELF::DT_FILTER) {
|
2018-07-25 19:09:20 +08:00
|
|
|
Expected<StringRef> StrTabOrErr = getDynamicStrTab(Elf);
|
|
|
|
if (StrTabOrErr) {
|
|
|
|
const char *Data = StrTabOrErr.get().data();
|
|
|
|
outs() << (Data + Dyn.d_un.d_val) << "\n";
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-21 19:07:31 +08:00
|
|
|
reportWarning(toString(StrTabOrErr.takeError()), Filename);
|
2018-07-25 19:09:20 +08:00
|
|
|
consumeError(StrTabOrErr.takeError());
|
|
|
|
}
|
|
|
|
outs() << format(Fmt, (uint64_t)Dyn.d_un.d_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:27:13 +08:00
|
|
|
template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
|
2013-01-06 11:56:49 +08:00
|
|
|
outs() << "Program Header:\n";
|
2016-11-04 01:28:33 +08:00
|
|
|
auto ProgramHeaderOrError = o->program_headers();
|
2016-11-16 13:10:28 +08:00
|
|
|
if (!ProgramHeaderOrError)
|
2019-04-25 12:31:26 +08:00
|
|
|
report_fatal_error(toString(ProgramHeaderOrError.takeError()));
|
2019-04-07 16:28:56 +08:00
|
|
|
for (const typename ELFT::Phdr &Phdr : *ProgramHeaderOrError) {
|
2015-07-20 21:35:33 +08:00
|
|
|
switch (Phdr.p_type) {
|
2016-12-24 22:53:45 +08:00
|
|
|
case ELF::PT_DYNAMIC:
|
|
|
|
outs() << " DYNAMIC ";
|
2013-01-06 11:56:49 +08:00
|
|
|
break;
|
|
|
|
case ELF::PT_GNU_EH_FRAME:
|
|
|
|
outs() << "EH_FRAME ";
|
|
|
|
break;
|
2017-01-17 06:58:26 +08:00
|
|
|
case ELF::PT_GNU_RELRO:
|
|
|
|
outs() << " RELRO ";
|
|
|
|
break;
|
2019-11-30 03:12:49 +08:00
|
|
|
case ELF::PT_GNU_PROPERTY:
|
|
|
|
outs() << " PROPERTY ";
|
|
|
|
break;
|
2016-12-24 22:53:45 +08:00
|
|
|
case ELF::PT_GNU_STACK:
|
|
|
|
outs() << " STACK ";
|
|
|
|
break;
|
2013-02-21 04:18:10 +08:00
|
|
|
case ELF::PT_INTERP:
|
|
|
|
outs() << " INTERP ";
|
|
|
|
break;
|
2016-12-24 22:53:45 +08:00
|
|
|
case ELF::PT_LOAD:
|
|
|
|
outs() << " LOAD ";
|
2013-02-21 04:18:10 +08:00
|
|
|
break;
|
2017-01-17 07:13:46 +08:00
|
|
|
case ELF::PT_NOTE:
|
|
|
|
outs() << " NOTE ";
|
|
|
|
break;
|
2017-01-17 06:01:41 +08:00
|
|
|
case ELF::PT_OPENBSD_BOOTDATA:
|
|
|
|
outs() << " OPENBSD_BOOTDATA ";
|
|
|
|
break;
|
|
|
|
case ELF::PT_OPENBSD_RANDOMIZE:
|
|
|
|
outs() << " OPENBSD_RANDOMIZE ";
|
|
|
|
break;
|
|
|
|
case ELF::PT_OPENBSD_WXNEEDED:
|
|
|
|
outs() << " OPENBSD_WXNEEDED ";
|
|
|
|
break;
|
2013-02-21 10:21:29 +08:00
|
|
|
case ELF::PT_PHDR:
|
|
|
|
outs() << " PHDR ";
|
|
|
|
break;
|
2013-02-28 01:57:17 +08:00
|
|
|
case ELF::PT_TLS:
|
|
|
|
outs() << " TLS ";
|
|
|
|
break;
|
2013-01-06 11:56:49 +08:00
|
|
|
default:
|
|
|
|
outs() << " UNKNOWN ";
|
|
|
|
}
|
|
|
|
|
2013-01-15 15:44:25 +08:00
|
|
|
const char *Fmt = ELFT::Is64Bits ? "0x%016" PRIx64 " " : "0x%08" PRIx64 " ";
|
2013-01-06 13:23:59 +08:00
|
|
|
|
2015-07-20 21:35:33 +08:00
|
|
|
outs() << "off " << format(Fmt, (uint64_t)Phdr.p_offset) << "vaddr "
|
|
|
|
<< format(Fmt, (uint64_t)Phdr.p_vaddr) << "paddr "
|
|
|
|
<< format(Fmt, (uint64_t)Phdr.p_paddr)
|
|
|
|
<< format("align 2**%u\n",
|
|
|
|
countTrailingZeros<uint64_t>(Phdr.p_align))
|
|
|
|
<< " filesz " << format(Fmt, (uint64_t)Phdr.p_filesz)
|
|
|
|
<< "memsz " << format(Fmt, (uint64_t)Phdr.p_memsz) << "flags "
|
|
|
|
<< ((Phdr.p_flags & ELF::PF_R) ? "r" : "-")
|
|
|
|
<< ((Phdr.p_flags & ELF::PF_W) ? "w" : "-")
|
|
|
|
<< ((Phdr.p_flags & ELF::PF_X) ? "x" : "-") << "\n";
|
2013-01-06 11:56:49 +08:00
|
|
|
}
|
|
|
|
outs() << "\n";
|
|
|
|
}
|
|
|
|
|
2019-02-25 21:13:19 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void printSymbolVersionDependency(ArrayRef<uint8_t> Contents,
|
|
|
|
StringRef StrTab) {
|
|
|
|
outs() << "Version References:\n";
|
|
|
|
|
|
|
|
const uint8_t *Buf = Contents.data();
|
|
|
|
while (Buf) {
|
2019-04-07 16:28:56 +08:00
|
|
|
auto *Verneed = reinterpret_cast<const typename ELFT::Verneed *>(Buf);
|
2019-02-25 21:13:19 +08:00
|
|
|
outs() << " required from "
|
|
|
|
<< StringRef(StrTab.drop_front(Verneed->vn_file).data()) << ":\n";
|
|
|
|
|
|
|
|
const uint8_t *BufAux = Buf + Verneed->vn_aux;
|
|
|
|
while (BufAux) {
|
2019-04-07 16:28:56 +08:00
|
|
|
auto *Vernaux = reinterpret_cast<const typename ELFT::Vernaux *>(BufAux);
|
2019-02-25 21:13:19 +08:00
|
|
|
outs() << " "
|
|
|
|
<< format("0x%08" PRIx32 " ", (uint32_t)Vernaux->vna_hash)
|
|
|
|
<< format("0x%02" PRIx16 " ", (uint16_t)Vernaux->vna_flags)
|
|
|
|
<< format("%02" PRIu16 " ", (uint16_t)Vernaux->vna_other)
|
|
|
|
<< StringRef(StrTab.drop_front(Vernaux->vna_name).data()) << '\n';
|
|
|
|
BufAux = Vernaux->vna_next ? BufAux + Vernaux->vna_next : nullptr;
|
|
|
|
}
|
|
|
|
Buf = Verneed->vn_next ? Buf + Verneed->vn_next : nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 21:06:16 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void printSymbolVersionDefinition(const typename ELFT::Shdr &Shdr,
|
|
|
|
ArrayRef<uint8_t> Contents,
|
|
|
|
StringRef StrTab) {
|
|
|
|
outs() << "Version definitions:\n";
|
|
|
|
|
|
|
|
const uint8_t *Buf = Contents.data();
|
|
|
|
uint32_t VerdefIndex = 1;
|
|
|
|
// sh_info contains the number of entries in the SHT_GNU_verdef section. To
|
|
|
|
// make the index column have consistent width, we should insert blank spaces
|
|
|
|
// according to sh_info.
|
|
|
|
uint16_t VerdefIndexWidth = std::to_string(Shdr.sh_info).size();
|
|
|
|
while (Buf) {
|
2019-04-07 16:29:04 +08:00
|
|
|
auto *Verdef = reinterpret_cast<const typename ELFT::Verdef *>(Buf);
|
2019-02-26 21:06:16 +08:00
|
|
|
outs() << format_decimal(VerdefIndex++, VerdefIndexWidth) << " "
|
|
|
|
<< format("0x%02" PRIx16 " ", (uint16_t)Verdef->vd_flags)
|
|
|
|
<< format("0x%08" PRIx32 " ", (uint32_t)Verdef->vd_hash);
|
|
|
|
|
|
|
|
const uint8_t *BufAux = Buf + Verdef->vd_aux;
|
|
|
|
uint16_t VerdauxIndex = 0;
|
|
|
|
while (BufAux) {
|
2019-04-07 16:29:04 +08:00
|
|
|
auto *Verdaux = reinterpret_cast<const typename ELFT::Verdaux *>(BufAux);
|
2019-02-26 21:06:16 +08:00
|
|
|
if (VerdauxIndex)
|
|
|
|
outs() << std::string(VerdefIndexWidth + 17, ' ');
|
|
|
|
outs() << StringRef(StrTab.drop_front(Verdaux->vda_name).data()) << '\n';
|
|
|
|
BufAux = Verdaux->vda_next ? BufAux + Verdaux->vda_next : nullptr;
|
|
|
|
++VerdauxIndex;
|
|
|
|
}
|
|
|
|
Buf = Verdef->vd_next ? Buf + Verdef->vd_next : nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 21:13:19 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void printSymbolVersionInfo(const ELFFile<ELFT> *Elf, StringRef FileName) {
|
2019-04-07 16:19:55 +08:00
|
|
|
ArrayRef<typename ELFT::Shdr> Sections =
|
|
|
|
unwrapOrError(Elf->sections(), FileName);
|
|
|
|
for (const typename ELFT::Shdr &Shdr : Sections) {
|
2019-02-26 21:06:16 +08:00
|
|
|
if (Shdr.sh_type != ELF::SHT_GNU_verneed &&
|
|
|
|
Shdr.sh_type != ELF::SHT_GNU_verdef)
|
2019-02-25 21:13:19 +08:00
|
|
|
continue;
|
|
|
|
|
2019-04-07 16:19:55 +08:00
|
|
|
ArrayRef<uint8_t> Contents =
|
|
|
|
unwrapOrError(Elf->getSectionContents(&Shdr), FileName);
|
|
|
|
const typename ELFT::Shdr *StrTabSec =
|
|
|
|
unwrapOrError(Elf->getSection(Shdr.sh_link), FileName);
|
|
|
|
StringRef StrTab = unwrapOrError(Elf->getStringTable(StrTabSec), FileName);
|
2019-02-25 21:13:19 +08:00
|
|
|
|
2019-02-26 21:06:16 +08:00
|
|
|
if (Shdr.sh_type == ELF::SHT_GNU_verneed)
|
2019-04-07 16:19:55 +08:00
|
|
|
printSymbolVersionDependency<ELFT>(Contents, StrTab);
|
2019-02-26 21:06:16 +08:00
|
|
|
else
|
2019-04-07 16:19:55 +08:00
|
|
|
printSymbolVersionDefinition<ELFT>(Shdr, Contents, StrTab);
|
2019-02-25 21:13:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:31:42 +08:00
|
|
|
void printELFFileHeader(const object::ObjectFile *Obj) {
|
2018-11-15 19:51:13 +08:00
|
|
|
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
2013-08-09 06:27:13 +08:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2018-11-15 19:51:13 +08:00
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
2013-08-09 06:27:13 +08:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2018-11-15 19:51:13 +08:00
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
|
2013-08-09 06:27:13 +08:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2018-11-15 19:51:13 +08:00
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
|
2013-08-09 06:27:13 +08:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2013-01-06 11:56:49 +08:00
|
|
|
}
|
2018-07-25 19:09:20 +08:00
|
|
|
|
2019-04-15 23:31:42 +08:00
|
|
|
void printELFDynamicSection(const object::ObjectFile *Obj) {
|
2018-11-15 19:51:13 +08:00
|
|
|
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
2018-07-25 19:09:20 +08:00
|
|
|
printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
|
2018-11-15 19:51:13 +08:00
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
2018-07-25 19:09:20 +08:00
|
|
|
printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
|
2018-11-15 19:51:13 +08:00
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
|
2018-07-25 19:09:20 +08:00
|
|
|
printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
|
2018-11-15 19:51:13 +08:00
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
|
2018-07-25 19:09:20 +08:00
|
|
|
printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
|
|
|
|
}
|
2019-02-25 21:13:19 +08:00
|
|
|
|
2019-04-15 23:31:42 +08:00
|
|
|
void printELFSymbolVersionInfo(const object::ObjectFile *Obj) {
|
2019-02-25 21:13:19 +08:00
|
|
|
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
|
|
|
printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
|
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
|
|
|
printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
|
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
|
|
|
|
printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
|
|
|
|
else if (const auto *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
|
|
|
|
printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
|
|
|
|
}
|
2019-04-15 23:31:42 +08:00
|
|
|
} // namespace llvm
|