[llvm-objdump][COFF][NFC] Split format-specific interfaces; add namespace

Summary:
This patch addresses, for the interfaces implemented by `COFFDump.cpp`,
multiple issues identified with the current structure of
`llvm-objdump.h` in the review of D72973.

This patch moves implementation details of the tool into an
`llvm::objdump` namespace for external linkage names, splits the
implementation details into separate headers for each implementation
file, and uses qualified names when declaring members of the
`llvm::objdump` namespace in place of leaving the namespace definition
open.

Reviewers: jhenderson, DiggerLin, jasonliu, daltenty, MaskRay

Reviewed By: jhenderson, MaskRay

Subscribers: MaskRay, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77285
This commit is contained in:
Hubert Tong 2020-04-02 18:17:52 -04:00
parent b94afc19eb
commit 2aab46ab02
4 changed files with 49 additions and 18 deletions

View File

@ -14,6 +14,8 @@
///
//===----------------------------------------------------------------------===//
#include "COFFDump.h"
#include "llvm-objdump.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Object/COFF.h"
@ -24,10 +26,10 @@
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::Win64EH;
namespace llvm {
// Returns the name of the unwind code.
static StringRef getUnwindCodeTypeName(uint8_t Code) {
switch(Code) {
@ -473,7 +475,7 @@ static bool getPDataSection(const COFFObjectFile *Obj,
return false;
}
Error getCOFFRelocationValueString(const COFFObjectFile *Obj,
Error objdump::getCOFFRelocationValueString(const COFFObjectFile *Obj,
const RelocationRef &Rel,
SmallVectorImpl<char> &Result) {
symbol_iterator SymI = Rel.getSymbol();
@ -596,7 +598,7 @@ static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
printWin64EHUnwindInfo(UI);
}
void printCOFFUnwindInfo(const COFFObjectFile *Obj) {
void objdump::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) {
WithColor::error(errs(), "llvm-objdump")
<< "unsupported image machine type "
@ -625,7 +627,7 @@ void printCOFFUnwindInfo(const COFFObjectFile *Obj) {
}
}
void printCOFFFileHeader(const object::ObjectFile *Obj) {
void objdump::printCOFFFileHeader(const object::ObjectFile *Obj) {
const COFFObjectFile *file = dyn_cast<const COFFObjectFile>(Obj);
printTLSDirectory(file);
printLoadConfiguration(file);
@ -633,7 +635,7 @@ void printCOFFFileHeader(const object::ObjectFile *Obj) {
printExportTable(file);
}
void printCOFFSymbolTable(const object::COFFImportFile *i) {
void objdump::printCOFFSymbolTable(const object::COFFImportFile *i) {
unsigned Index = 0;
bool IsCode = i->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
@ -656,7 +658,7 @@ void printCOFFSymbolTable(const object::COFFImportFile *i) {
}
}
void printCOFFSymbolTable(const COFFObjectFile *coff) {
void objdump::printCOFFSymbolTable(const COFFObjectFile *coff) {
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
if (!Symbol)
@ -735,4 +737,3 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
}
}
}
} // namespace llvm

View File

@ -0,0 +1,37 @@
//===-- COFFDump.h ----------------------------------------------*- 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_COFFDUMP_H
#define LLVM_TOOLS_LLVM_OBJDUMP_COFFDUMP_H
#include "llvm/ADT/SmallVector.h"
namespace llvm {
class Error;
namespace object {
class COFFObjectFile;
class COFFImportFile;
class ObjectFile;
class RelocationRef;
} // namespace object
namespace objdump {
Error getCOFFRelocationValueString(const object::COFFObjectFile *Obj,
const object::RelocationRef &Rel,
llvm::SmallVectorImpl<char> &Result);
void printCOFFUnwindInfo(const object::COFFObjectFile *O);
void printCOFFFileHeader(const object::ObjectFile *O);
void printCOFFSymbolTable(const object::COFFImportFile *I);
void printCOFFSymbolTable(const object::COFFObjectFile *O);
} // namespace objdump
} // namespace llvm
#endif

View File

@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-objdump.h"
#include "COFFDump.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetOperations.h"
@ -72,6 +73,7 @@
#include <utility>
using namespace llvm::object;
using namespace llvm::objdump;
namespace llvm {

View File

@ -18,8 +18,6 @@ namespace llvm {
class StringRef;
namespace object {
class COFFObjectFile;
class COFFImportFile;
class ELFObjectFileBase;
class ELFSectionRef;
class MachOObjectFile;
@ -97,9 +95,6 @@ SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O,
Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
const object::RelocationRef &Rel,
llvm::SmallVectorImpl<char> &Result);
Error getCOFFRelocationValueString(const object::COFFObjectFile *Obj,
const object::RelocationRef &Rel,
llvm::SmallVectorImpl<char> &Result);
Error getWasmRelocationValueString(const object::WasmObjectFile *Obj,
const object::RelocationRef &RelRef,
llvm::SmallVectorImpl<char> &Result);
@ -115,7 +110,6 @@ uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec);
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
void parseInputMachO(StringRef Filename);
void parseInputMachO(object::MachOUniversalBinary *UB);
void printCOFFUnwindInfo(const object::COFFObjectFile *O);
void printMachOUnwindInfo(const object::MachOObjectFile *O);
void printMachOExportsTrie(const object::MachOObjectFile *O);
void printMachORebaseTable(object::MachOObjectFile *O);
@ -125,9 +119,6 @@ void printMachOWeakBindTable(object::MachOObjectFile *O);
void printELFFileHeader(const object::ObjectFile *O);
void printELFDynamicSection(const object::ObjectFile *Obj);
void printELFSymbolVersionInfo(const object::ObjectFile *Obj);
void printCOFFFileHeader(const object::ObjectFile *O);
void printCOFFSymbolTable(const object::COFFImportFile *I);
void printCOFFSymbolTable(const object::COFFObjectFile *O);
void printMachOFileHeader(const object::ObjectFile *O);
void printMachOLoadCommands(const object::ObjectFile *O);
void printWasmFileHeader(const object::ObjectFile *O);