Imported Upstream version 5.18.0.207

Former-commit-id: 3b152f462918d427ce18620a2cbe4f8b79650449
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-11-17 08:23:10 +00:00
parent 8e12397d70
commit eb85e2fc17
28480 changed files with 72 additions and 3866936 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,117 +0,0 @@
//===--- ARMWinEHPrinter.h - Windows on ARM Unwind Information Printer ----===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H
#define LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H
#include "llvm/Object/COFF.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/ScopedPrinter.h"
namespace llvm {
namespace ARM {
namespace WinEH {
class RuntimeFunction;
class Decoder {
static const size_t PDataEntrySize;
ScopedPrinter &SW;
raw_ostream &OS;
struct RingEntry {
uint8_t Mask;
uint8_t Value;
bool (Decoder::*Routine)(const uint8_t *, unsigned &, unsigned, bool);
};
static const RingEntry Ring[];
bool opcode_0xxxxxxx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_10Lxxxxx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_1100xxxx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11010Lxx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11011Lxx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11100xxx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_111010xx(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_1110110L(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11101110(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11101111(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11110101(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11110110(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11110111(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111000(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111001(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111010(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111011(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111100(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111101(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111110(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
bool opcode_11111111(const uint8_t *Opcodes, unsigned &Offset,
unsigned Length, bool Prologue);
void decodeOpcodes(ArrayRef<uint8_t> Opcodes, unsigned Offset,
bool Prologue);
void printRegisters(const std::pair<uint16_t, uint32_t> &RegisterMask);
ErrorOr<object::SectionRef>
getSectionContaining(const object::COFFObjectFile &COFF, uint64_t Address);
ErrorOr<object::SymbolRef>
getSymbol(const object::COFFObjectFile &COFF, uint64_t Address,
bool FunctionOnly = false);
ErrorOr<object::SymbolRef>
getRelocatedSymbol(const object::COFFObjectFile &COFF,
const object::SectionRef &Section, uint64_t Offset);
bool dumpXDataRecord(const object::COFFObjectFile &COFF,
const object::SectionRef &Section,
uint64_t FunctionAddress, uint64_t VA);
bool dumpUnpackedEntry(const object::COFFObjectFile &COFF,
const object::SectionRef Section, uint64_t Offset,
unsigned Index, const RuntimeFunction &Entry);
bool dumpPackedEntry(const object::COFFObjectFile &COFF,
const object::SectionRef Section, uint64_t Offset,
unsigned Index, const RuntimeFunction &Entry);
bool dumpProcedureDataEntry(const object::COFFObjectFile &COFF,
const object::SectionRef Section, unsigned Entry,
ArrayRef<uint8_t> Contents);
void dumpProcedureData(const object::COFFObjectFile &COFF,
const object::SectionRef Section);
public:
Decoder(ScopedPrinter &SW) : SW(SW), OS(SW.getOStream()) {}
std::error_code dumpProcedureData(const object::COFFObjectFile &COFF);
};
}
}
}
#endif

View File

@ -1,29 +0,0 @@
set(LLVM_LINK_COMPONENTS
DebugInfoCodeView
Object
BinaryFormat
Support
DebugInfoCodeView
DebugInfoMSF
DebugInfoPDB
)
add_llvm_tool(llvm-readobj
ARMWinEHPrinter.cpp
COFFDumper.cpp
COFFImportDumper.cpp
ELFDumper.cpp
Error.cpp
llvm-readobj.cpp
MachODumper.cpp
ObjDumper.cpp
WasmDumper.cpp
Win64EHDumper.cpp
WindowsResourceDumper.cpp
)
add_llvm_tool_symlink(llvm-readelf llvm-readobj)
if(LLVM_INSTALL_BINUTILS_SYMLINKS)
add_llvm_tool_symlink(readelf llvm-readobj)
endif()

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
//===-- COFFImportDumper.cpp - COFF import library dumper -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file implements the COFF import library dumper for llvm-readobj.
///
//===----------------------------------------------------------------------===//
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/COFFImportFile.h"
using namespace llvm::object;
namespace llvm {
void dumpCOFFImportFile(const COFFImportFile *File) {
outs() << '\n';
outs() << "File: " << File->getFileName() << "\n";
outs() << "Format: COFF-import-file\n";
const coff_import_header *H = File->getCOFFImportHeader();
switch (H->getType()) {
case COFF::IMPORT_CODE: outs() << "Type: code\n"; break;
case COFF::IMPORT_DATA: outs() << "Type: data\n"; break;
case COFF::IMPORT_CONST: outs() << "Type: const\n"; break;
}
switch (H->getNameType()) {
case COFF::IMPORT_ORDINAL: outs() << "Name type: ordinal\n"; break;
case COFF::IMPORT_NAME: outs() << "Name type: name\n"; break;
case COFF::IMPORT_NAME_NOPREFIX: outs() << "Name type: noprefix\n"; break;
case COFF::IMPORT_NAME_UNDECORATE: outs() << "Name type: undecorate\n"; break;
}
for (const object::BasicSymbolRef &Sym : File->symbols()) {
outs() << "Symbol: ";
Sym.printName(outs());
outs() << "\n";
}
}
} // namespace llvm

View File

@ -1 +0,0 @@
5605eaea7555d5cb4ebbffe21c80f617aae07922

View File

@ -1,57 +0,0 @@
//===- Error.cpp - system_error extensions for llvm-readobj -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This defines a new error_category for the llvm-readobj tool.
//
//===----------------------------------------------------------------------===//
#include "Error.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
namespace {
// FIXME: This class is only here to support the transition to llvm::Error. It
// will be removed once this transition is complete. Clients should prefer to
// deal with the Error value directly, rather than converting to error_code.
class _readobj_error_category : public std::error_category {
public:
const char* name() const noexcept override;
std::string message(int ev) const override;
};
} // namespace
const char *_readobj_error_category::name() const noexcept {
return "llvm.readobj";
}
std::string _readobj_error_category::message(int EV) const {
switch (static_cast<readobj_error>(EV)) {
case readobj_error::success: return "Success";
case readobj_error::file_not_found:
return "No such file.";
case readobj_error::unsupported_file_format:
return "The file was not recognized as a valid object file.";
case readobj_error::unrecognized_file_format:
return "Unrecognized file type.";
case readobj_error::unsupported_obj_file_format:
return "Unsupported object file format.";
case readobj_error::unknown_symbol:
return "Unknown symbol.";
}
llvm_unreachable("An enumerator of readobj_error does not have a message "
"defined.");
}
namespace llvm {
const std::error_category &readobj_category() {
static _readobj_error_category o;
return o;
}
} // namespace llvm

View File

@ -1,41 +0,0 @@
//===- Error.h - system_error extensions for llvm-readobj -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This declares a new error_category for the llvm-readobj tool.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_READOBJ_ERROR_H
#define LLVM_TOOLS_LLVM_READOBJ_ERROR_H
#include <system_error>
namespace llvm {
const std::error_category &readobj_category();
enum class readobj_error {
success = 0,
file_not_found,
unsupported_file_format,
unrecognized_file_format,
unsupported_obj_file_format,
unknown_symbol
};
inline std::error_code make_error_code(readobj_error e) {
return std::error_code(static_cast<int>(e), readobj_category());
}
} // namespace llvm
namespace std {
template <> struct is_error_code_enum<llvm::readobj_error> : std::true_type {};
}
#endif

View File

@ -1,22 +0,0 @@
;===- ./tools/llvm-readobj/LLVMBuild.txt ---------------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[component_0]
type = Tool
name = llvm-readobj
parent = Tools
required_libraries = all-targets BitReader Object BinaryFormat DebugInfoCodeView DebugInfoPDB DebugInfoMSF

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
//===-- ObjDumper.cpp - Base dumper class -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file implements ObjDumper.
///
//===----------------------------------------------------------------------===//
#include "ObjDumper.h"
#include "Error.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
ObjDumper::ObjDumper(ScopedPrinter &Writer) : W(Writer) {}
ObjDumper::~ObjDumper() {
}
} // namespace llvm

View File

@ -1,112 +0,0 @@
//===-- ObjDumper.h ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
#define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
#include <memory>
#include <system_error>
namespace llvm {
namespace object {
class COFFImportFile;
class ObjectFile;
}
namespace codeview {
class MergingTypeTableBuilder;
}
class ScopedPrinter;
class ObjDumper {
public:
ObjDumper(ScopedPrinter &Writer);
virtual ~ObjDumper();
virtual void printFileHeaders() = 0;
virtual void printSections() = 0;
virtual void printRelocations() = 0;
virtual void printSymbols() = 0;
virtual void printDynamicSymbols() = 0;
virtual void printUnwindInfo() = 0;
// Only implemented for ELF at this time.
virtual void printDynamicRelocations() { }
virtual void printDynamicTable() { }
virtual void printNeededLibraries() { }
virtual void printProgramHeaders() { }
virtual void printHashTable() { }
virtual void printGnuHashTable() { }
virtual void printLoadName() {}
virtual void printVersionInfo() {}
virtual void printGroupSections() {}
virtual void printHashHistogram() {}
virtual void printNotes() {}
// Only implemented for ARM ELF at this time.
virtual void printAttributes() { }
// Only implemented for MIPS ELF at this time.
virtual void printMipsPLTGOT() { }
virtual void printMipsABIFlags() { }
virtual void printMipsReginfo() { }
virtual void printMipsOptions() { }
// Only implemented for PE/COFF.
virtual void printCOFFImports() { }
virtual void printCOFFExports() { }
virtual void printCOFFDirectives() { }
virtual void printCOFFBaseReloc() { }
virtual void printCOFFDebugDirectory() { }
virtual void printCOFFResources() {}
virtual void printCOFFLoadConfig() { }
virtual void printCodeViewDebugInfo() { }
virtual void
mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
llvm::codeview::MergingTypeTableBuilder &CVTypes) {}
// Only implemented for MachO.
virtual void printMachODataInCode() { }
virtual void printMachOVersionMin() { }
virtual void printMachODysymtab() { }
virtual void printMachOSegment() { }
virtual void printMachOIndirectSymbols() { }
virtual void printMachOLinkerOptions() { }
virtual void printStackMap() const = 0;
protected:
ScopedPrinter &W;
};
std::error_code createCOFFDumper(const object::ObjectFile *Obj,
ScopedPrinter &Writer,
std::unique_ptr<ObjDumper> &Result);
std::error_code createELFDumper(const object::ObjectFile *Obj,
ScopedPrinter &Writer,
std::unique_ptr<ObjDumper> &Result);
std::error_code createMachODumper(const object::ObjectFile *Obj,
ScopedPrinter &Writer,
std::unique_ptr<ObjDumper> &Result);
std::error_code createWasmDumper(const object::ObjectFile *Obj,
ScopedPrinter &Writer,
std::unique_ptr<ObjDumper> &Result);
void dumpCOFFImportFile(const object::COFFImportFile *File);
void dumpCodeViewMergedTypes(
ScopedPrinter &Writer, llvm::codeview::MergingTypeTableBuilder &IDTable,
llvm::codeview::MergingTypeTableBuilder &TypeTable);
} // namespace llvm
#endif

View File

@ -1,81 +0,0 @@
//===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
#define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
#include "llvm/Object/StackMapParser.h"
namespace llvm {
// Pretty print a stackmap to the given ostream.
template <typename OStreamT, typename StackMapParserT>
void prettyPrintStackMap(OStreamT &OS, const StackMapParserT &SMP) {
OS << "LLVM StackMap Version: " << SMP.getVersion()
<< "\nNum Functions: " << SMP.getNumFunctions();
// Functions:
for (const auto &F : SMP.functions())
OS << "\n Function address: " << F.getFunctionAddress()
<< ", stack size: " << F.getStackSize()
<< ", callsite record count: " << F.getRecordCount();
// Constants:
OS << "\nNum Constants: " << SMP.getNumConstants();
unsigned ConstantIndex = 0;
for (const auto &C : SMP.constants())
OS << "\n #" << ++ConstantIndex << ": " << C.getValue();
// Records:
OS << "\nNum Records: " << SMP.getNumRecords();
for (const auto &R : SMP.records()) {
OS << "\n Record ID: " << R.getID()
<< ", instruction offset: " << R.getInstructionOffset()
<< "\n " << R.getNumLocations() << " locations:";
unsigned LocationIndex = 0;
for (const auto &Loc : R.locations()) {
OS << "\n #" << ++LocationIndex << ": ";
switch (Loc.getKind()) {
case StackMapParserT::LocationKind::Register:
OS << "Register R#" << Loc.getDwarfRegNum();
break;
case StackMapParserT::LocationKind::Direct:
OS << "Direct R#" << Loc.getDwarfRegNum() << " + "
<< Loc.getOffset();
break;
case StackMapParserT::LocationKind::Indirect:
OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + "
<< Loc.getOffset() << "]";
break;
case StackMapParserT::LocationKind::Constant:
OS << "Constant " << Loc.getSmallConstant();
break;
case StackMapParserT::LocationKind::ConstantIndex:
OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
<< SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
break;
}
}
OS << "\n " << R.getNumLiveOuts() << " live-outs: [ ";
for (const auto &LO : R.liveouts())
OS << "R#" << LO.getDwarfRegNum() << " ("
<< LO.getSizeInBytes() << "-bytes) ";
OS << "]\n";
}
OS << "\n";
}
}
#endif

View File

@ -1,226 +0,0 @@
//===-- WasmDumper.cpp - Wasm-specific object file dumper -----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Wasm-specific dumper for llvm-readobj.
//
//===----------------------------------------------------------------------===//
#include "Error.h"
#include "ObjDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/Wasm.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
using namespace object;
namespace {
static const EnumEntry<unsigned> WasmSymbolTypes[] = {
#define ENUM_ENTRY(X) { #X, static_cast<unsigned>(WasmSymbol::SymbolType::X) }
ENUM_ENTRY(FUNCTION_IMPORT),
ENUM_ENTRY(FUNCTION_EXPORT),
ENUM_ENTRY(GLOBAL_IMPORT),
ENUM_ENTRY(GLOBAL_EXPORT),
ENUM_ENTRY(DEBUG_FUNCTION_NAME),
#undef ENUM_ENTRY
};
static const EnumEntry<uint32_t> WasmSectionTypes[] = {
#define ENUM_ENTRY(X) { #X, wasm::WASM_SEC_##X }
ENUM_ENTRY(CUSTOM),
ENUM_ENTRY(TYPE),
ENUM_ENTRY(IMPORT),
ENUM_ENTRY(FUNCTION),
ENUM_ENTRY(TABLE),
ENUM_ENTRY(MEMORY),
ENUM_ENTRY(GLOBAL),
ENUM_ENTRY(EXPORT),
ENUM_ENTRY(START),
ENUM_ENTRY(ELEM),
ENUM_ENTRY(CODE),
ENUM_ENTRY(DATA),
#undef ENUM_ENTRY
};
class WasmDumper : public ObjDumper {
public:
WasmDumper(const WasmObjectFile *Obj, ScopedPrinter &Writer)
: ObjDumper(Writer), Obj(Obj) {}
void printFileHeaders() override;
void printSections() override;
void printRelocations() override;
void printSymbols() override;
void printDynamicSymbols() override { llvm_unreachable("unimplemented"); }
void printUnwindInfo() override { llvm_unreachable("unimplemented"); }
void printStackMap() const override { llvm_unreachable("unimplemented"); }
protected:
void printSymbol(const SymbolRef &Sym);
void printRelocation(const SectionRef &Section, const RelocationRef &Reloc);
private:
const WasmObjectFile *Obj;
};
void WasmDumper::printFileHeaders() {
W.printHex("Version", Obj->getHeader().Version);
}
void WasmDumper::printRelocation(const SectionRef &Section,
const RelocationRef &Reloc) {
SmallString<64> RelocTypeName;
uint64_t RelocType = Reloc.getType();
Reloc.getTypeName(RelocTypeName);
const wasm::WasmRelocation &WasmReloc = Obj->getWasmRelocation(Reloc);
bool HasAddend = false;
switch (RelocType) {
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
HasAddend = true;
break;
default:
break;
}
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printNumber("Type", RelocTypeName, RelocType);
W.printHex("Offset", Reloc.getOffset());
W.printHex("Index", WasmReloc.Index);
if (HasAddend)
W.printNumber("Addend", WasmReloc.Addend);
} else {
raw_ostream& OS = W.startLine();
OS << W.hex(Reloc.getOffset()) << " " << RelocTypeName << "["
<< WasmReloc.Index << "]";
if (HasAddend)
OS << " " << WasmReloc.Addend;
OS << "\n";
}
}
void WasmDumper::printRelocations() {
ListScope D(W, "Relocations");
int SectionNumber = 0;
for (const SectionRef &Section : Obj->sections()) {
bool PrintedGroup = false;
StringRef Name;
error(Section.getName(Name));
++SectionNumber;
for (const RelocationRef &Reloc : Section.relocations()) {
if (!PrintedGroup) {
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
W.indent();
PrintedGroup = true;
}
printRelocation(Section, Reloc);
}
if (PrintedGroup) {
W.unindent();
W.startLine() << "}\n";
}
}
}
void WasmDumper::printSymbols() {
ListScope Group(W, "Symbols");
for (const SymbolRef &Symbol : Obj->symbols())
printSymbol(Symbol);
}
void WasmDumper::printSections() {
ListScope Group(W, "Sections");
for (const SectionRef &Section : Obj->sections()) {
const WasmSection &WasmSec = Obj->getWasmSection(Section);
DictScope SectionD(W, "Section");
W.printEnum("Type", WasmSec.Type, makeArrayRef(WasmSectionTypes));
W.printNumber("Size", static_cast<uint64_t>(WasmSec.Content.size()));
W.printNumber("Offset", WasmSec.Offset);
switch (WasmSec.Type) {
case wasm::WASM_SEC_CUSTOM:
W.printString("Name", WasmSec.Name);
if (WasmSec.Name == "linking") {
const wasm::WasmLinkingData &LinkingData = Obj->linkingData();
W.printNumber("DataSize", LinkingData.DataSize);
if (!LinkingData.InitFunctions.empty()) {
ListScope Group(W, "InitFunctions");
for (const wasm::WasmInitFunc &F: LinkingData.InitFunctions)
W.startLine() << F.FunctionIndex << " (priority=" << F.Priority
<< ")\n";
}
}
break;
case wasm::WASM_SEC_DATA: {
ListScope Group(W, "Segments");
for (const WasmSegment &Segment : Obj->dataSegments()) {
const wasm::WasmDataSegment& Seg = Segment.Data;
DictScope Group(W, "Segment");
if (!Seg.Name.empty())
W.printString("Name", Seg.Name);
W.printNumber("Size", static_cast<uint64_t>(Seg.Content.size()));
if (Seg.Offset.Opcode == wasm::WASM_OPCODE_I32_CONST)
W.printNumber("Offset", Seg.Offset.Value.Int32);
}
break;
}
case wasm::WASM_SEC_MEMORY:
ListScope Group(W, "Memories");
for (const wasm::WasmLimits &Memory : Obj->memories()) {
DictScope Group(W, "Memory");
W.printNumber("InitialPages", Memory.Initial);
if (Memory.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) {
W.printNumber("MaxPages", WasmSec.Offset);
}
}
break;
}
if (opts::SectionRelocations) {
ListScope D(W, "Relocations");
for (const RelocationRef &Reloc : Section.relocations())
printRelocation(Section, Reloc);
}
if (opts::SectionData) {
W.printBinaryBlock("SectionData", WasmSec.Content);
}
}
}
void WasmDumper::printSymbol(const SymbolRef &Sym) {
DictScope D(W, "Symbol");
WasmSymbol Symbol = Obj->getWasmSymbol(Sym.getRawDataRefImpl());
W.printString("Name", Symbol.Name);
W.printEnum("Type", static_cast<unsigned>(Symbol.Type), makeArrayRef(WasmSymbolTypes));
W.printHex("Flags", Symbol.Flags);
}
}
namespace llvm {
std::error_code createWasmDumper(const object::ObjectFile *Obj,
ScopedPrinter &Writer,
std::unique_ptr<ObjDumper> &Result) {
const WasmObjectFile *WasmObj = dyn_cast<WasmObjectFile>(Obj);
assert(WasmObj && "createWasmDumper called with non-wasm object");
Result.reset(new WasmDumper(WasmObj, Writer));
return readobj_error::success;
}
} // namespace llvm

View File

@ -1,334 +0,0 @@
//===- Win64EHDumper.cpp - Win64 EH Printer ---------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Win64EHDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::Win64EH;
static const EnumEntry<unsigned> UnwindFlags[] = {
{ "ExceptionHandler", UNW_ExceptionHandler },
{ "TerminateHandler", UNW_TerminateHandler },
{ "ChainInfo" , UNW_ChainInfo }
};
static const EnumEntry<unsigned> UnwindOpInfo[] = {
{ "RAX", 0 },
{ "RCX", 1 },
{ "RDX", 2 },
{ "RBX", 3 },
{ "RSP", 4 },
{ "RBP", 5 },
{ "RSI", 6 },
{ "RDI", 7 },
{ "R8", 8 },
{ "R9", 9 },
{ "R10", 10 },
{ "R11", 11 },
{ "R12", 12 },
{ "R13", 13 },
{ "R14", 14 },
{ "R15", 15 }
};
static uint64_t getOffsetOfLSDA(const UnwindInfo& UI) {
return static_cast<const char*>(UI.getLanguageSpecificData())
- reinterpret_cast<const char*>(&UI);
}
static uint32_t getLargeSlotValue(ArrayRef<UnwindCode> UC) {
if (UC.size() < 3)
return 0;
return UC[1].FrameOffset + (static_cast<uint32_t>(UC[2].FrameOffset) << 16);
}
// Returns the name of the unwind code.
static StringRef getUnwindCodeTypeName(uint8_t Code) {
switch (Code) {
default: llvm_unreachable("Invalid unwind code");
case UOP_PushNonVol: return "PUSH_NONVOL";
case UOP_AllocLarge: return "ALLOC_LARGE";
case UOP_AllocSmall: return "ALLOC_SMALL";
case UOP_SetFPReg: return "SET_FPREG";
case UOP_SaveNonVol: return "SAVE_NONVOL";
case UOP_SaveNonVolBig: return "SAVE_NONVOL_FAR";
case UOP_SaveXMM128: return "SAVE_XMM128";
case UOP_SaveXMM128Big: return "SAVE_XMM128_FAR";
case UOP_PushMachFrame: return "PUSH_MACHFRAME";
}
}
// Returns the name of a referenced register.
static StringRef getUnwindRegisterName(uint8_t Reg) {
switch (Reg) {
default: llvm_unreachable("Invalid register");
case 0: return "RAX";
case 1: return "RCX";
case 2: return "RDX";
case 3: return "RBX";
case 4: return "RSP";
case 5: return "RBP";
case 6: return "RSI";
case 7: return "RDI";
case 8: return "R8";
case 9: return "R9";
case 10: return "R10";
case 11: return "R11";
case 12: return "R12";
case 13: return "R13";
case 14: return "R14";
case 15: return "R15";
}
}
// Calculates the number of array slots required for the unwind code.
static unsigned getNumUsedSlots(const UnwindCode &UnwindCode) {
switch (UnwindCode.getUnwindOp()) {
default: llvm_unreachable("Invalid unwind code");
case UOP_PushNonVol:
case UOP_AllocSmall:
case UOP_SetFPReg:
case UOP_PushMachFrame:
return 1;
case UOP_SaveNonVol:
case UOP_SaveXMM128:
return 2;
case UOP_SaveNonVolBig:
case UOP_SaveXMM128Big:
return 3;
case UOP_AllocLarge:
return (UnwindCode.getOpInfo() == 0) ? 2 : 3;
}
}
static std::string formatSymbol(const Dumper::Context &Ctx,
const coff_section *Section, uint64_t Offset,
uint32_t Displacement) {
std::string Buffer;
raw_string_ostream OS(Buffer);
SymbolRef Symbol;
if (!Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) {
Expected<StringRef> Name = Symbol.getName();
if (Name) {
OS << *Name;
if (Displacement > 0)
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
else
OS << format(" (0x%" PRIX64 ")", Offset);
return OS.str();
} else {
// TODO: Actually report errors helpfully.
consumeError(Name.takeError());
}
}
OS << format(" (0x%" PRIX64 ")", Offset);
return OS.str();
}
static std::error_code resolveRelocation(const Dumper::Context &Ctx,
const coff_section *Section,
uint64_t Offset,
const coff_section *&ResolvedSection,
uint64_t &ResolvedAddress) {
SymbolRef Symbol;
if (std::error_code EC =
Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
return EC;
Expected<uint64_t> ResolvedAddressOrErr = Symbol.getAddress();
if (!ResolvedAddressOrErr)
return errorToErrorCode(ResolvedAddressOrErr.takeError());
ResolvedAddress = *ResolvedAddressOrErr;
Expected<section_iterator> SI = Symbol.getSection();
if (!SI)
return errorToErrorCode(SI.takeError());
ResolvedSection = Ctx.COFF.getCOFFSection(**SI);
return std::error_code();
}
namespace llvm {
namespace Win64EH {
void Dumper::printRuntimeFunctionEntry(const Context &Ctx,
const coff_section *Section,
uint64_t Offset,
const RuntimeFunction &RF) {
SW.printString("StartAddress",
formatSymbol(Ctx, Section, Offset + 0, RF.StartAddress));
SW.printString("EndAddress",
formatSymbol(Ctx, Section, Offset + 4, RF.EndAddress));
SW.printString("UnwindInfoAddress",
formatSymbol(Ctx, Section, Offset + 8, RF.UnwindInfoOffset));
}
// Prints one unwind code. Because an unwind code can occupy up to 3 slots in
// the unwind codes array, this function requires that the correct number of
// slots is provided.
void Dumper::printUnwindCode(const UnwindInfo& UI, ArrayRef<UnwindCode> UC) {
assert(UC.size() >= getNumUsedSlots(UC[0]));
SW.startLine() << format("0x%02X: ", unsigned(UC[0].u.CodeOffset))
<< getUnwindCodeTypeName(UC[0].getUnwindOp());
switch (UC[0].getUnwindOp()) {
case UOP_PushNonVol:
OS << " reg=" << getUnwindRegisterName(UC[0].getOpInfo());
break;
case UOP_AllocLarge:
OS << " size="
<< ((UC[0].getOpInfo() == 0) ? UC[1].FrameOffset * 8
: getLargeSlotValue(UC));
break;
case UOP_AllocSmall:
OS << " size=" << (UC[0].getOpInfo() + 1) * 8;
break;
case UOP_SetFPReg:
if (UI.getFrameRegister() == 0)
OS << " reg=<invalid>";
else
OS << " reg=" << getUnwindRegisterName(UI.getFrameRegister())
<< format(", offset=0x%X", UI.getFrameOffset() * 16);
break;
case UOP_SaveNonVol:
OS << " reg=" << getUnwindRegisterName(UC[0].getOpInfo())
<< format(", offset=0x%X", UC[1].FrameOffset * 8);
break;
case UOP_SaveNonVolBig:
OS << " reg=" << getUnwindRegisterName(UC[0].getOpInfo())
<< format(", offset=0x%X", getLargeSlotValue(UC));
break;
case UOP_SaveXMM128:
OS << " reg=XMM" << static_cast<uint32_t>(UC[0].getOpInfo())
<< format(", offset=0x%X", UC[1].FrameOffset * 16);
break;
case UOP_SaveXMM128Big:
OS << " reg=XMM" << static_cast<uint32_t>(UC[0].getOpInfo())
<< format(", offset=0x%X", getLargeSlotValue(UC));
break;
case UOP_PushMachFrame:
OS << " errcode=" << (UC[0].getOpInfo() == 0 ? "no" : "yes");
break;
}
OS << "\n";
}
void Dumper::printUnwindInfo(const Context &Ctx, const coff_section *Section,
off_t Offset, const UnwindInfo &UI) {
DictScope UIS(SW, "UnwindInfo");
SW.printNumber("Version", UI.getVersion());
SW.printFlags("Flags", UI.getFlags(), makeArrayRef(UnwindFlags));
SW.printNumber("PrologSize", UI.PrologSize);
if (UI.getFrameRegister()) {
SW.printEnum("FrameRegister", UI.getFrameRegister(),
makeArrayRef(UnwindOpInfo));
SW.printHex("FrameOffset", UI.getFrameOffset());
} else {
SW.printString("FrameRegister", StringRef("-"));
SW.printString("FrameOffset", StringRef("-"));
}
SW.printNumber("UnwindCodeCount", UI.NumCodes);
{
ListScope UCS(SW, "UnwindCodes");
ArrayRef<UnwindCode> UC(&UI.UnwindCodes[0], UI.NumCodes);
for (const UnwindCode *UCI = UC.begin(), *UCE = UC.end(); UCI < UCE; ++UCI) {
unsigned UsedSlots = getNumUsedSlots(*UCI);
if (UsedSlots > UC.size()) {
errs() << "corrupt unwind data";
return;
}
printUnwindCode(UI, makeArrayRef(UCI, UCE));
UCI = UCI + UsedSlots - 1;
}
}
uint64_t LSDAOffset = Offset + getOffsetOfLSDA(UI);
if (UI.getFlags() & (UNW_ExceptionHandler | UNW_TerminateHandler)) {
SW.printString("Handler",
formatSymbol(Ctx, Section, LSDAOffset,
UI.getLanguageSpecificHandlerOffset()));
} else if (UI.getFlags() & UNW_ChainInfo) {
if (const RuntimeFunction *Chained = UI.getChainedFunctionEntry()) {
DictScope CS(SW, "Chained");
printRuntimeFunctionEntry(Ctx, Section, LSDAOffset, *Chained);
}
}
}
void Dumper::printRuntimeFunction(const Context &Ctx,
const coff_section *Section,
uint64_t SectionOffset,
const RuntimeFunction &RF) {
DictScope RFS(SW, "RuntimeFunction");
printRuntimeFunctionEntry(Ctx, Section, SectionOffset, RF);
const coff_section *XData;
uint64_t Offset;
resolveRelocation(Ctx, Section, SectionOffset + 8, XData, Offset);
ArrayRef<uint8_t> Contents;
error(Ctx.COFF.getSectionContents(XData, Contents));
if (Contents.empty())
return;
Offset = Offset + RF.UnwindInfoOffset;
if (Offset > Contents.size())
return;
const auto UI = reinterpret_cast<const UnwindInfo*>(Contents.data() + Offset);
printUnwindInfo(Ctx, XData, Offset, *UI);
}
void Dumper::printData(const Context &Ctx) {
for (const auto &Section : Ctx.COFF.sections()) {
StringRef Name;
Section.getName(Name);
if (Name != ".pdata" && !Name.startswith(".pdata$"))
continue;
const coff_section *PData = Ctx.COFF.getCOFFSection(Section);
ArrayRef<uint8_t> Contents;
error(Ctx.COFF.getSectionContents(PData, Contents));
if (Contents.empty())
continue;
const RuntimeFunction *Entries =
reinterpret_cast<const RuntimeFunction *>(Contents.data());
const size_t Count = Contents.size() / sizeof(RuntimeFunction);
ArrayRef<RuntimeFunction> RuntimeFunctions(Entries, Count);
size_t Index = 0;
for (const auto &RF : RuntimeFunctions) {
printRuntimeFunction(Ctx, Ctx.COFF.getCOFFSection(Section),
Index * sizeof(RuntimeFunction), RF);
++Index;
}
}
}
}
}

View File

@ -1,63 +0,0 @@
//===- Win64EHDumper.h - Win64 EH Printing ----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_READOBJ_WIN64EHDUMPER_H
#define LLVM_TOOLS_LLVM_READOBJ_WIN64EHDUMPER_H
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/Win64EH.h"
namespace llvm {
namespace object {
class COFFObjectFile;
class SymbolRef;
struct coff_section;
}
namespace Win64EH {
class Dumper {
ScopedPrinter &SW;
raw_ostream &OS;
public:
typedef std::error_code (*SymbolResolver)(const object::coff_section *,
uint64_t, object::SymbolRef &,
void *);
struct Context {
const object::COFFObjectFile &COFF;
SymbolResolver ResolveSymbol;
void *UserData;
Context(const object::COFFObjectFile &COFF, SymbolResolver Resolver,
void *UserData)
: COFF(COFF), ResolveSymbol(Resolver), UserData(UserData) {}
};
private:
void printRuntimeFunctionEntry(const Context &Ctx,
const object::coff_section *Section,
uint64_t SectionOffset,
const RuntimeFunction &RF);
void printUnwindCode(const UnwindInfo& UI, ArrayRef<UnwindCode> UC);
void printUnwindInfo(const Context &Ctx, const object::coff_section *Section,
off_t Offset, const UnwindInfo &UI);
void printRuntimeFunction(const Context &Ctx,
const object::coff_section *Section,
uint64_t SectionOffset, const RuntimeFunction &RF);
public:
Dumper(ScopedPrinter &SW) : SW(SW), OS(SW.getOStream()) {}
void printData(const Context &Ctx);
};
}
}
#endif

View File

@ -1,82 +0,0 @@
//===-- WindowsResourceDumper.cpp - Windows Resource printer --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Windows resource (.res) dumper for llvm-readobj.
//
//===----------------------------------------------------------------------===//
#include "WindowsResourceDumper.h"
#include "Error.h"
#include "llvm/Object/WindowsResource.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/ScopedPrinter.h"
namespace llvm {
namespace object {
namespace WindowsRes {
std::string stripUTF16(const ArrayRef<UTF16> &UTF16Str) {
std::string Result;
Result.reserve(UTF16Str.size());
for (UTF16 Ch : UTF16Str) {
// UTF16Str will have swapped byte order in case of big-endian machines.
// Swap it back in such a case.
uint16_t ChValue = support::endian::byte_swap(Ch, support::little);
if (ChValue <= 0xFF)
Result += ChValue;
else
Result += '?';
}
return Result;
}
Error Dumper::printData() {
auto EntryPtrOrErr = WinRes->getHeadEntry();
if (!EntryPtrOrErr)
return EntryPtrOrErr.takeError();
auto EntryPtr = *EntryPtrOrErr;
bool IsEnd = false;
while (!IsEnd) {
printEntry(EntryPtr);
if (auto Err = EntryPtr.moveNext(IsEnd))
return Err;
}
return Error::success();
}
void Dumper::printEntry(const ResourceEntryRef &Ref) {
if (Ref.checkTypeString()) {
auto NarrowStr = stripUTF16(Ref.getTypeString());
SW.printString("Resource type (string)", NarrowStr);
} else
SW.printNumber("Resource type (int)", Ref.getTypeID());
if (Ref.checkNameString()) {
auto NarrowStr = stripUTF16(Ref.getNameString());
SW.printString("Resource name (string)", NarrowStr);
} else
SW.printNumber("Resource name (int)", Ref.getNameID());
SW.printNumber("Data version", Ref.getDataVersion());
SW.printHex("Memory flags", Ref.getMemoryFlags());
SW.printNumber("Language ID", Ref.getLanguage());
SW.printNumber("Version (major)", Ref.getMajorVersion());
SW.printNumber("Version (minor)", Ref.getMinorVersion());
SW.printNumber("Characteristics", Ref.getCharacteristics());
SW.printNumber("Data size", (uint64_t)Ref.getData().size());
SW.printBinary("Data:", Ref.getData());
SW.startLine() << "\n";
}
} // namespace WindowsRes
} // namespace object
} // namespace llvm

View File

@ -1,37 +0,0 @@
//===- WindowsResourceDumper.h - Windows Resource printer -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_READOBJ_WINDOWSRESOURCEDUMPER_H
#define LLVM_TOOLS_LLVM_READOBJ_WINDOWSRESOURCEDUMPER_H
#include "llvm/Object/WindowsResource.h"
#include "llvm/Support/ScopedPrinter.h"
namespace llvm {
namespace object {
namespace WindowsRes {
class Dumper {
public:
Dumper(WindowsResource *Res, ScopedPrinter &SW) : SW(SW), WinRes(Res) {}
Error printData();
private:
ScopedPrinter &SW;
WindowsResource *WinRes;
void printEntry(const ResourceEntryRef &Ref);
};
} // namespace WindowsRes
} // namespace object
} // namespace llvm
#endif

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More