diff options
author | dim <dim@FreeBSD.org> | 2012-08-15 19:34:23 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-08-15 19:34:23 +0000 |
commit | 721c201bd55ffb73cb2ba8d39e0570fa38c44e15 (patch) | |
tree | eacfc83d988e4b9d11114387ae7dc41243f2a363 /tools/llvm-objdump/llvm-objdump.cpp | |
parent | 2b2816e083a455f7a656ae88b0fd059d1688bb36 (diff) | |
download | FreeBSD-src-721c201bd55ffb73cb2ba8d39e0570fa38c44e15.zip FreeBSD-src-721c201bd55ffb73cb2ba8d39e0570fa38c44e15.tar.gz |
Vendor import of llvm trunk r161861:
http://llvm.org/svn/llvm-project/llvm/trunk@161861
Diffstat (limited to 'tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | tools/llvm-objdump/llvm-objdump.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 5a6f94a..b431c76 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -104,29 +104,27 @@ static bool error(error_code ec) { return true; } -static const Target *GetTarget(const ObjectFile *Obj = NULL) { +static const Target *getTarget(const ObjectFile *Obj = NULL) { // Figure out the target triple. - llvm::Triple TT("unknown-unknown-unknown"); + llvm::Triple TheTriple("unknown-unknown-unknown"); if (TripleName.empty()) { if (Obj) - TT.setArch(Triple::ArchType(Obj->getArch())); + TheTriple.setArch(Triple::ArchType(Obj->getArch())); } else - TT.setTriple(Triple::normalize(TripleName)); - - if (!ArchName.empty()) - TT.setArchName(ArchName); - - TripleName = TT.str(); + TheTriple.setTriple(Triple::normalize(TripleName)); // Get the target specific parser. std::string Error; - const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error); - if (TheTarget) - return TheTarget; + const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple, + Error); + if (!TheTarget) { + errs() << ToolName << ": " << Error; + return 0; + } - errs() << ToolName << ": error: unable to get target for '" << TripleName - << "', see --version and --triple.\n"; - return 0; + // Update the triple name and return the found target. + TripleName = TheTriple.getTriple(); + return TheTarget; } void llvm::StringRefMemoryObject::anchor() { } @@ -165,11 +163,11 @@ static bool RelocAddressLess(RelocationRef a, RelocationRef b) { } static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { - const Target *TheTarget = GetTarget(Obj); - if (!TheTarget) { - // GetTarget prints out stuff. + const Target *TheTarget = getTarget(Obj); + // getTarget() will have already issued a diagnostic if necessary, so + // just bail here if it failed. + if (!TheTarget) return; - } error_code ec; for (section_iterator i = Obj->begin_sections(), @@ -208,7 +206,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (InlineRelocs) { for (relocation_iterator ri = i->begin_relocations(), re = i->end_relocations(); - ri != re; ri.increment(ec)) { + ri != re; ri.increment(ec)) { if (error(ec)) break; Rels.push_back(*ri); } @@ -465,9 +463,8 @@ static void PrintCOFFSymbolTable(const COFFObjectFile *coff) { << format("assoc %d comdat %d\n" , unsigned(asd->Number) , unsigned(asd->Selection)); - } else { + } else outs() << "AUX Unknown\n"; - } } else { StringRef name; if (error(coff->getSymbol(i, symbol))) return; @@ -611,13 +608,12 @@ static void DumpInput(StringRef file) { return; } - if (Archive *a = dyn_cast<Archive>(binary.get())) { + if (Archive *a = dyn_cast<Archive>(binary.get())) DumpArchive(a); - } else if (ObjectFile *o = dyn_cast<ObjectFile>(binary.get())) { + else if (ObjectFile *o = dyn_cast<ObjectFile>(binary.get())) DumpObject(o); - } else { + else errs() << ToolName << ": '" << file << "': " << "Unrecognized file type.\n"; - } } int main(int argc, char **argv) { @@ -632,6 +628,9 @@ int main(int argc, char **argv) { llvm::InitializeAllAsmParsers(); llvm::InitializeAllDisassemblers(); + // Register the target printer for --version. + cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); + cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n"); TripleName = Triple::normalize(TripleName); |