aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-objdump
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-05-29 02:49:00 -0700
committerStephen Hines <srhines@google.com>2014-05-29 02:49:00 -0700
commitdce4a407a24b04eebc6a376f8e62b41aaa7b071f (patch)
treedcebc53f2b182f145a2e659393bf9a0472cedf23 /tools/llvm-objdump
parent220b921aed042f9e520c26cffd8282a94c66c3d5 (diff)
downloadexternal_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.zip
external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.tar.gz
external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.tar.bz2
Update LLVM for 3.5 rebase (r209712).
Change-Id: I149556c940fb7dc92d075273c87ff584f400941f
Diffstat (limited to 'tools/llvm-objdump')
-rw-r--r--tools/llvm-objdump/MachODump.cpp12
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp87
2 files changed, 62 insertions, 37 deletions
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index 89b038f..3ca582f 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
@@ -64,7 +65,7 @@ static const Target *GetTarget(const MachOObjectFile *MachOObj) {
errs() << "llvm-objdump: error: unable to get target for '" << TripleName
<< "', see --version and --triple.\n";
- return 0;
+ return nullptr;
}
struct SymbolSorter {
@@ -225,8 +226,9 @@ static void DisassembleInputMachO2(StringRef Filename,
TheTarget->createMCAsmInfo(*MRI, TripleName));
std::unique_ptr<const MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, "", ""));
+ MCContext Ctx(AsmInfo.get(), MRI.get(), nullptr);
std::unique_ptr<const MCDisassembler> DisAsm(
- TheTarget->createMCDisassembler(*STI));
+ TheTarget->createMCDisassembler(*STI, Ctx));
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
AsmPrinterVariant, *AsmInfo, *InstrInfo, *MRI, *STI));
@@ -419,9 +421,9 @@ static void DisassembleInputMachO2(StringRef Filename,
DILineInfo dli =
diContext->getLineInfoForAddress(SectAddress + Index);
// Print valid line info if it changed.
- if (dli != lastLine && dli.getLine() != 0)
- outs() << "\t## " << dli.getFileName() << ':'
- << dli.getLine() << ':' << dli.getColumn();
+ if (dli != lastLine && dli.Line != 0)
+ outs() << "\t## " << dli.FileName << ':' << dli.Line << ':'
+ << dli.Column;
lastLine = dli;
}
outs() << "\n";
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 729fcba..a4fc6d0 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -157,7 +157,7 @@ bool llvm::error(error_code EC) {
return true;
}
-static const Target *getTarget(const ObjectFile *Obj = NULL) {
+static const Target *getTarget(const ObjectFile *Obj = nullptr) {
// Figure out the target triple.
llvm::Triple TheTriple("unknown-unknown-unknown");
if (TripleName.empty()) {
@@ -167,6 +167,12 @@ static const Target *getTarget(const ObjectFile *Obj = NULL) {
// the best we can do here is indicate that it is mach-o.
if (Obj->isMachO())
TheTriple.setObjectFormat(Triple::MachO);
+
+ if (Obj->isCOFF()) {
+ const auto COFFObj = dyn_cast<COFFObjectFile>(Obj);
+ if (COFFObj->getArch() == Triple::thumb)
+ TheTriple.setTriple("thumbv7-windows");
+ }
}
} else
TheTriple.setTriple(Triple::normalize(TripleName));
@@ -177,7 +183,7 @@ static const Target *getTarget(const ObjectFile *Obj = NULL) {
Error);
if (!TheTarget) {
errs() << ToolName << ": " << Error;
- return 0;
+ return nullptr;
}
// Update the triple name and return the found target.
@@ -309,24 +315,25 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
return;
}
- std::unique_ptr<MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI));
+ std::unique_ptr<const MCObjectFileInfo> MOFI(new MCObjectFileInfo);
+ MCContext Ctx(AsmInfo.get(), MRI.get(), MOFI.get());
+
+ std::unique_ptr<MCDisassembler> DisAsm(
+ TheTarget->createMCDisassembler(*STI, Ctx));
+
if (!DisAsm) {
errs() << "error: no disassembler for target " << TripleName << "\n";
return;
}
- std::unique_ptr<const MCObjectFileInfo> MOFI;
- std::unique_ptr<MCContext> Ctx;
if (Symbolize) {
- MOFI.reset(new MCObjectFileInfo);
- Ctx.reset(new MCContext(AsmInfo.get(), MRI.get(), MOFI.get()));
std::unique_ptr<MCRelocationInfo> RelInfo(
- TheTarget->createMCRelocationInfo(TripleName, *Ctx.get()));
+ TheTarget->createMCRelocationInfo(TripleName, Ctx));
if (RelInfo) {
std::unique_ptr<MCSymbolizer> Symzer(
- MCObjectSymbolizer::createObjectSymbolizer(*Ctx.get(),
- std::move(RelInfo), Obj));
+ MCObjectSymbolizer::createObjectSymbolizer(Ctx, std::move(RelInfo),
+ Obj));
if (Symzer)
DisAsm->setSymbolizer(std::move(Symzer));
}
@@ -664,16 +671,33 @@ static void PrintSectionContents(const ObjectFile *Obj) {
static void PrintCOFFSymbolTable(const COFFObjectFile *coff) {
const coff_file_header *header;
- if (error(coff->getHeader(header))) return;
- int aux_count = 0;
- const coff_symbol *symbol = 0;
- for (int i = 0, e = header->NumberOfSymbols; i != e; ++i) {
- if (aux_count--) {
- // Figure out which type of aux this is.
- if (symbol->isSectionDefinition()) { // Section definition.
+ if (error(coff->getHeader(header)))
+ return;
+
+ for (unsigned SI = 0, SE = header->NumberOfSymbols; SI != SE; ++SI) {
+ const coff_symbol *Symbol;
+ StringRef Name;
+ if (error(coff->getSymbol(SI, Symbol)))
+ return;
+
+ if (error(coff->getSymbolName(Symbol, Name)))
+ return;
+
+ outs() << "[" << format("%2d", SI) << "]"
+ << "(sec " << format("%2d", int(Symbol->SectionNumber)) << ")"
+ << "(fl 0x00)" // Flag bits, which COFF doesn't have.
+ << "(ty " << format("%3x", unsigned(Symbol->Type)) << ")"
+ << "(scl " << format("%3x", unsigned(Symbol->StorageClass)) << ") "
+ << "(nx " << unsigned(Symbol->NumberOfAuxSymbols) << ") "
+ << "0x" << format("%08x", unsigned(Symbol->Value)) << " "
+ << Name << "\n";
+
+ for (unsigned AI = 0, AE = Symbol->NumberOfAuxSymbols; AI < AE; ++AI, ++SI) {
+ if (Symbol->isSectionDefinition()) {
const coff_aux_section_definition *asd;
- if (error(coff->getAuxSymbol<coff_aux_section_definition>(i, asd)))
+ if (error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd)))
return;
+
outs() << "AUX "
<< format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
, unsigned(asd->Length)
@@ -683,21 +707,20 @@ static void PrintCOFFSymbolTable(const COFFObjectFile *coff) {
<< format("assoc %d comdat %d\n"
, unsigned(asd->Number)
, unsigned(asd->Selection));
- } else
+ } else if (Symbol->isFileRecord()) {
+ const coff_aux_file *AF;
+ if (error(coff->getAuxSymbol<coff_aux_file>(SI + 1, AF)))
+ return;
+
+ StringRef Name(AF->FileName,
+ Symbol->NumberOfAuxSymbols * COFF::SymbolSize);
+ outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n';
+
+ SI = SI + Symbol->NumberOfAuxSymbols;
+ break;
+ } else {
outs() << "AUX Unknown\n";
- } else {
- StringRef name;
- if (error(coff->getSymbol(i, symbol))) return;
- if (error(coff->getSymbolName(symbol, name))) return;
- outs() << "[" << format("%2d", i) << "]"
- << "(sec " << format("%2d", int(symbol->SectionNumber)) << ")"
- << "(fl 0x00)" // Flag bits, which COFF doesn't have.
- << "(ty " << format("%3x", unsigned(symbol->Type)) << ")"
- << "(scl " << format("%3x", unsigned(symbol->StorageClass)) << ") "
- << "(nx " << unsigned(symbol->NumberOfAuxSymbols) << ") "
- << "0x" << format("%08x", unsigned(symbol->Value)) << " "
- << name << "\n";
- aux_count = symbol->NumberOfAuxSymbols;
+ }
}
}
}