#include "ObjDumper.h"
#include "StreamWriter.h"
#include "llvm/Object/Archive.h"
+#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
#include <string>
#include <system_error>
-
using namespace llvm;
using namespace llvm::object;
cl::desc("Alias for --relocations"),
cl::aliasopt(Relocations));
+ // -dyn-relocations
+ cl::opt<bool> DynRelocs("dyn-relocations",
+ cl::desc("Display the dynamic relocation entries in the file"));
+
// -symbols, -t
cl::opt<bool> Symbols("symbols",
cl::desc("Display the symbol table"));
cl::opt<bool> ProgramHeaders("program-headers",
cl::desc("Display ELF program headers"));
+ // -hash-table
+ cl::opt<bool> HashTable("hash-table",
+ cl::desc("Display ELF hash table"));
+
// -expand-relocs
cl::opt<bool> ExpandRelocs("expand-relocs",
cl::desc("Expand each shown relocation to multiple lines"));
MipsPLTGOT("mips-plt-got",
cl::desc("Display the MIPS GOT and PLT GOT sections"));
+ // -mips-abi-flags
+ cl::opt<bool> MipsABIFlags("mips-abi-flags",
+ cl::desc("Display the MIPS.abiflags section"));
+
+ // -mips-reginfo
+ cl::opt<bool> MipsReginfo("mips-reginfo",
+ cl::desc("Display the MIPS .reginfo section"));
+
// -coff-imports
cl::opt<bool>
COFFImports("coff-imports", cl::desc("Display the PE/COFF import table"));
cl::opt<bool>
COFFBaseRelocs("coff-basereloc",
cl::desc("Display the PE/COFF .reloc section"));
-} // namespace opts
-static int ReturnValue = EXIT_SUCCESS;
+ // -macho-data-in-code
+ cl::opt<bool>
+ MachODataInCode("macho-data-in-code",
+ cl::desc("Display MachO Data in Code command"));
+
+ // -macho-segment
+ cl::opt<bool>
+ MachOSegment("macho-segment",
+ cl::desc("Display MachO Segment command"));
+
+ // -macho-version-min
+ cl::opt<bool>
+ MachOVersionMin("macho-version-min",
+ cl::desc("Display MachO version min command"));
+
+ // -macho-dysymtab
+ cl::opt<bool>
+ MachODysymtab("macho-dysymtab",
+ cl::desc("Display MachO Dysymtab command"));
+
+ // -stackmap
+ cl::opt<bool>
+ PrintStackMap("stackmap",
+ cl::desc("Display contents of stackmap section"));
+
+} // namespace opts
namespace llvm {
-bool error(std::error_code EC) {
+void reportError(Twine Msg) {
+ outs() << "\nError reading file: " << Msg << ".\n";
+ outs().flush();
+ exit(1);
+}
+
+void error(std::error_code EC) {
if (!EC)
- return false;
+ return;
- ReturnValue = EXIT_FAILURE;
- outs() << "\nError reading file: " << EC.message() << ".\n";
- outs().flush();
- return true;
+ reportError(EC.message());
}
bool relocAddressLess(RelocationRef a, RelocationRef b) {
- uint64_t a_addr, b_addr;
- if (error(a.getOffset(a_addr))) exit(ReturnValue);
- if (error(b.getOffset(b_addr))) exit(ReturnValue);
- return a_addr < b_addr;
+ return a.getOffset() < b.getOffset();
}
} // namespace llvm
if (Input == "-")
Input = "<stdin>";
- errs() << Input << ": " << EC.message() << "\n";
- errs().flush();
- ReturnValue = EXIT_FAILURE;
+ reportError(Twine(Input) + ": " + EC.message());
}
static void reportError(StringRef Input, StringRef Message) {
if (Input == "-")
Input = "<stdin>";
- errs() << Input << ": " << Message << "\n";
- ReturnValue = EXIT_FAILURE;
+ reportError(Twine(Input) + ": " + Message);
}
static bool isMipsArch(unsigned Arch) {
return readobj_error::unsupported_obj_file_format;
}
-static StringRef getLoadName(const ObjectFile *Obj) {
- if (auto *ELF = dyn_cast<ELF32LEObjectFile>(Obj))
- return ELF->getLoadName();
- if (auto *ELF = dyn_cast<ELF64LEObjectFile>(Obj))
- return ELF->getLoadName();
- if (auto *ELF = dyn_cast<ELF32BEObjectFile>(Obj))
- return ELF->getLoadName();
- if (auto *ELF = dyn_cast<ELF64BEObjectFile>(Obj))
- return ELF->getLoadName();
- llvm_unreachable("Not ELF");
-}
-
/// @brief Dumps the specified object file.
static void dumpObject(const ObjectFile *Obj) {
StreamWriter Writer(outs());
<< Triple::getArchTypeName((llvm::Triple::ArchType)Obj->getArch())
<< "\n";
outs() << "AddressSize: " << (8*Obj->getBytesInAddress()) << "bit\n";
- if (Obj->isELF())
- outs() << "LoadName: " << getLoadName(Obj) << "\n";
+ Dumper->printLoadName();
if (opts::FileHeaders)
Dumper->printFileHeaders();
Dumper->printSections();
if (opts::Relocations)
Dumper->printRelocations();
+ if (opts::DynRelocs)
+ Dumper->printDynamicRelocations();
if (opts::Symbols)
Dumper->printSymbols();
if (opts::DynamicSymbols)
Dumper->printNeededLibraries();
if (opts::ProgramHeaders)
Dumper->printProgramHeaders();
+ if (opts::HashTable)
+ Dumper->printHashTable();
if (Obj->getArch() == llvm::Triple::arm && Obj->isELF())
if (opts::ARMAttributes)
Dumper->printAttributes();
- if (isMipsArch(Obj->getArch()) && Obj->isELF())
+ if (isMipsArch(Obj->getArch()) && Obj->isELF()) {
if (opts::MipsPLTGOT)
Dumper->printMipsPLTGOT();
- if (opts::COFFImports)
- Dumper->printCOFFImports();
- if (opts::COFFExports)
- Dumper->printCOFFExports();
- if (opts::COFFDirectives)
- Dumper->printCOFFDirectives();
- if (opts::COFFBaseRelocs)
- Dumper->printCOFFBaseReloc();
+ if (opts::MipsABIFlags)
+ Dumper->printMipsABIFlags();
+ if (opts::MipsReginfo)
+ Dumper->printMipsReginfo();
+ }
+ if (Obj->isCOFF()) {
+ if (opts::COFFImports)
+ Dumper->printCOFFImports();
+ if (opts::COFFExports)
+ Dumper->printCOFFExports();
+ if (opts::COFFDirectives)
+ Dumper->printCOFFDirectives();
+ if (opts::COFFBaseRelocs)
+ Dumper->printCOFFBaseReloc();
+ }
+ if (Obj->isMachO()) {
+ if (opts::MachODataInCode)
+ Dumper->printMachODataInCode();
+ if (opts::MachOSegment)
+ Dumper->printMachOSegment();
+ if (opts::MachOVersionMin)
+ Dumper->printMachOVersionMin();
+ if (opts::MachODysymtab)
+ Dumper->printMachODysymtab();
+ }
+ if (opts::PrintStackMap)
+ Dumper->printStackMap();
}
-
/// @brief Dumps each object file in \a Arc;
static void dumpArchive(const Archive *Arc) {
- for (Archive::child_iterator ArcI = Arc->child_begin(),
- ArcE = Arc->child_end();
- ArcI != ArcE; ++ArcI) {
- ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcI->getAsBinary();
+ for (const auto &Child : Arc->children()) {
+ ErrorOr<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
// Ignore non-object files.
if (EC != object_error::invalid_file_type)
dumpMachOUniversalBinary(UBinary);
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
dumpObject(Obj);
+ else if (COFFImportFile *Import = dyn_cast<COFFImportFile>(&Binary))
+ dumpCOFFImportFile(Import);
else
reportError(File, readobj_error::unrecognized_file_format);
}
-
int main(int argc, const char *argv[]) {
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y;
- // Initialize targets.
- llvm::InitializeAllTargetInfos();
-
// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
dumpInput);
- return ReturnValue;
+ return 0;
}