mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:39:47 +00:00
[llvm-objdump][ELF][NFC] Create ELFDump.h
Summary: Continuing from D77285, the external interfaces implemented by `ELFDump.cpp` are now declared in `ELFDump.h` and moved into the `llvm::objdump` namespace. Externs defined in `ELFDump.cpp` that are unreferenced externally are also made static. Reviewers: jhenderson, MaskRay, DiggerLin, jasonliu, daltenty Reviewed By: jhenderson, MaskRay Subscribers: RKSimon, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78695
This commit is contained in:
parent
9ef37e59d4
commit
3c957e42f4
@ -11,6 +11,8 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ELFDump.h"
|
||||
|
||||
#include "llvm-objdump.h"
|
||||
#include "llvm/Demangle/Demangle.h"
|
||||
#include "llvm/Object/ELFObjectFile.h"
|
||||
@ -18,10 +20,10 @@
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::object;
|
||||
using namespace llvm::objdump;
|
||||
|
||||
namespace llvm {
|
||||
template <class ELFT>
|
||||
static Expected<StringRef> getDynamicStrTab(const ELFFile<ELFT> *Elf) {
|
||||
auto DynamicEntriesOrError = Elf->dynamicEntries();
|
||||
@ -117,9 +119,9 @@ static Error getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
Error getELFRelocationValueString(const ELFObjectFileBase *Obj,
|
||||
const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
Error objdump::getELFRelocationValueString(const ELFObjectFileBase *Obj,
|
||||
const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
if (auto *ELF32LE = dyn_cast<ELF32LEObjectFile>(Obj))
|
||||
return getRelocationValueString(ELF32LE, Rel, Result);
|
||||
if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
|
||||
@ -148,7 +150,7 @@ static uint64_t getSectionLMA(const ELFFile<ELFT> *Obj,
|
||||
return Sec.getAddress();
|
||||
}
|
||||
|
||||
uint64_t getELFSectionLMA(const object::ELFSectionRef &Sec) {
|
||||
uint64_t objdump::getELFSectionLMA(const object::ELFSectionRef &Sec) {
|
||||
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Sec.getObject()))
|
||||
return getSectionLMA(ELFObj->getELFFile(), Sec);
|
||||
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Sec.getObject()))
|
||||
@ -160,7 +162,7 @@ uint64_t getELFSectionLMA(const object::ELFSectionRef &Sec) {
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void printDynamicSection(const ELFFile<ELFT> *Elf, StringRef Filename) {
|
||||
static void printDynamicSection(const ELFFile<ELFT> *Elf, StringRef Filename) {
|
||||
ArrayRef<typename ELFT::Dyn> DynamicEntries =
|
||||
unwrapOrError(Elf->dynamicEntries(), Filename);
|
||||
|
||||
@ -196,7 +198,7 @@ void printDynamicSection(const ELFFile<ELFT> *Elf, StringRef Filename) {
|
||||
}
|
||||
}
|
||||
|
||||
template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
|
||||
template <class ELFT> static void printProgramHeaders(const ELFFile<ELFT> *o) {
|
||||
outs() << "Program Header:\n";
|
||||
auto ProgramHeaderOrError = o->program_headers();
|
||||
if (!ProgramHeaderOrError)
|
||||
@ -263,8 +265,8 @@ template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void printSymbolVersionDependency(ArrayRef<uint8_t> Contents,
|
||||
StringRef StrTab) {
|
||||
static void printSymbolVersionDependency(ArrayRef<uint8_t> Contents,
|
||||
StringRef StrTab) {
|
||||
outs() << "Version References:\n";
|
||||
|
||||
const uint8_t *Buf = Contents.data();
|
||||
@ -288,9 +290,9 @@ void printSymbolVersionDependency(ArrayRef<uint8_t> Contents,
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void printSymbolVersionDefinition(const typename ELFT::Shdr &Shdr,
|
||||
ArrayRef<uint8_t> Contents,
|
||||
StringRef StrTab) {
|
||||
static void printSymbolVersionDefinition(const typename ELFT::Shdr &Shdr,
|
||||
ArrayRef<uint8_t> Contents,
|
||||
StringRef StrTab) {
|
||||
outs() << "Version definitions:\n";
|
||||
|
||||
const uint8_t *Buf = Contents.data();
|
||||
@ -320,7 +322,8 @@ void printSymbolVersionDefinition(const typename ELFT::Shdr &Shdr,
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void printSymbolVersionInfo(const ELFFile<ELFT> *Elf, StringRef FileName) {
|
||||
static void printSymbolVersionInfo(const ELFFile<ELFT> *Elf,
|
||||
StringRef FileName) {
|
||||
ArrayRef<typename ELFT::Shdr> Sections =
|
||||
unwrapOrError(Elf->sections(), FileName);
|
||||
for (const typename ELFT::Shdr &Shdr : Sections) {
|
||||
@ -341,7 +344,7 @@ void printSymbolVersionInfo(const ELFFile<ELFT> *Elf, StringRef FileName) {
|
||||
}
|
||||
}
|
||||
|
||||
void printELFFileHeader(const object::ObjectFile *Obj) {
|
||||
void objdump::printELFFileHeader(const object::ObjectFile *Obj) {
|
||||
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
||||
printProgramHeaders(ELFObj->getELFFile());
|
||||
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
||||
@ -352,7 +355,7 @@ void printELFFileHeader(const object::ObjectFile *Obj) {
|
||||
printProgramHeaders(ELFObj->getELFFile());
|
||||
}
|
||||
|
||||
void printELFDynamicSection(const object::ObjectFile *Obj) {
|
||||
void objdump::printELFDynamicSection(const object::ObjectFile *Obj) {
|
||||
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
||||
printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
|
||||
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
||||
@ -363,7 +366,7 @@ void printELFDynamicSection(const object::ObjectFile *Obj) {
|
||||
printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
|
||||
}
|
||||
|
||||
void printELFSymbolVersionInfo(const object::ObjectFile *Obj) {
|
||||
void objdump::printELFSymbolVersionInfo(const object::ObjectFile *Obj) {
|
||||
if (const auto *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
||||
printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
|
||||
else if (const auto *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
||||
@ -373,4 +376,3 @@ void printELFSymbolVersionInfo(const object::ObjectFile *Obj) {
|
||||
else if (const auto *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
|
||||
printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
|
||||
}
|
||||
} // namespace llvm
|
||||
|
39
tools/llvm-objdump/ELFDump.h
Normal file
39
tools/llvm-objdump/ELFDump.h
Normal file
@ -0,0 +1,39 @@
|
||||
//===-- ELFDump.h - ELF-specific dumper -------------------------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TOOLS_LLVM_OBJDUMP_ELFDUMP_H
|
||||
#define LLVM_TOOLS_LLVM_OBJDUMP_ELFDUMP_H
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class Error;
|
||||
|
||||
namespace object {
|
||||
class ELFObjectFileBase;
|
||||
class ELFSectionRef;
|
||||
class ObjectFile;
|
||||
class RelocationRef;
|
||||
} // namespace object
|
||||
|
||||
namespace objdump {
|
||||
|
||||
Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
|
||||
const object::RelocationRef &Rel,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
uint64_t getELFSectionLMA(const object::ELFSectionRef &Sec);
|
||||
|
||||
void printELFFileHeader(const object::ObjectFile *O);
|
||||
void printELFDynamicSection(const object::ObjectFile *Obj);
|
||||
void printELFSymbolVersionInfo(const object::ObjectFile *Obj);
|
||||
|
||||
} // namespace objdump
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "llvm-objdump.h"
|
||||
#include "COFFDump.h"
|
||||
#include "ELFDump.h"
|
||||
#include "MachODump.h"
|
||||
#include "WasmDump.h"
|
||||
#include "XCOFFDump.h"
|
||||
|
@ -117,16 +117,7 @@ private:
|
||||
SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O,
|
||||
uint64_t *Idx = nullptr);
|
||||
|
||||
Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
|
||||
const object::RelocationRef &Rel,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
|
||||
uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec);
|
||||
|
||||
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
|
||||
void printELFFileHeader(const object::ObjectFile *O);
|
||||
void printELFDynamicSection(const object::ObjectFile *Obj);
|
||||
void printELFSymbolVersionInfo(const object::ObjectFile *Obj);
|
||||
void printRawClangAST(const object::ObjectFile *O);
|
||||
void printRelocations(const object::ObjectFile *O);
|
||||
void printDynamicRelocations(const object::ObjectFile *O);
|
||||
|
Loading…
Reference in New Issue
Block a user