diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-readobj/llvm-readobj.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-readobj/llvm-readobj.cpp | 149 |
1 files changed, 110 insertions, 39 deletions
diff --git a/contrib/llvm/tools/llvm-readobj/llvm-readobj.cpp b/contrib/llvm/tools/llvm-readobj/llvm-readobj.cpp index fa8fee2..c293919 100644 --- a/contrib/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/contrib/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -22,7 +22,7 @@ #include "llvm-readobj.h" #include "Error.h" #include "ObjDumper.h" -#include "StreamWriter.h" +#include "llvm/DebugInfo/CodeView/MemoryTypeTableBuilder.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFFImportFile.h" #include "llvm/Object/ELFObjectFile.h" @@ -35,6 +35,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" @@ -144,6 +145,11 @@ namespace opts { cl::opt<bool> CodeView("codeview", cl::desc("Display CodeView debug information")); + // -codeview-merged-types + cl::opt<bool> + CodeViewMergedTypes("codeview-merged-types", + cl::desc("Display the merged CodeView type stream")); + // -codeview-subsection-bytes cl::opt<bool> CodeViewSubsectionBytes( "codeview-subsection-bytes", @@ -168,6 +174,10 @@ namespace opts { cl::opt<bool> MipsReginfo("mips-reginfo", cl::desc("Display the MIPS .reginfo section")); + // -mips-options + cl::opt<bool> MipsOptions("mips-options", + cl::desc("Display the MIPS .MIPS.options section")); + // -coff-imports cl::opt<bool> COFFImports("coff-imports", cl::desc("Display the PE/COFF import table")); @@ -186,6 +196,11 @@ namespace opts { COFFBaseRelocs("coff-basereloc", cl::desc("Display the PE/COFF .reloc section")); + // -coff-debug-directory + cl::opt<bool> + COFFDebugDirectory("coff-debug-directory", + cl::desc("Display the PE/COFF debug directory")); + // -macho-data-in-code cl::opt<bool> MachODataInCode("macho-data-in-code", @@ -227,6 +242,22 @@ namespace opts { cl::desc("Display ELF version sections (if present)")); cl::alias VersionInfoShort("V", cl::desc("Alias for -version-info"), cl::aliasopt(VersionInfo)); + + cl::opt<bool> SectionGroups("elf-section-groups", + cl::desc("Display ELF section group contents")); + cl::alias SectionGroupsShort("g", cl::desc("Alias for -elf-sections-groups"), + cl::aliasopt(SectionGroups)); + cl::opt<bool> HashHistogram( + "elf-hash-histogram", + cl::desc("Display bucket list histogram for hash sections")); + cl::alias HashHistogramShort("I", cl::desc("Alias for -elf-hash-histogram"), + cl::aliasopt(HashHistogram)); + + cl::opt<OutputStyleTy> + Output("elf-output-style", cl::desc("Specify ELF dump style"), + cl::values(clEnumVal(LLVM, "LLVM default style"), + clEnumVal(GNU, "GNU readelf style"), clEnumValEnd), + cl::init(LLVM)); } // namespace opts namespace llvm { @@ -264,6 +295,17 @@ static void reportError(StringRef Input, StringRef Message) { reportError(Twine(Input) + ": " + Message); } +static void reportError(StringRef Input, Error Err) { + if (Input == "-") + Input = "<stdin>"; + std::string ErrMsg; + { + raw_string_ostream ErrStream(ErrMsg); + logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": "); + } + reportError(ErrMsg); +} + static bool isMipsArch(unsigned Arch) { switch (Arch) { case llvm::Triple::mips: @@ -276,8 +318,11 @@ static bool isMipsArch(unsigned Arch) { } } +static llvm::codeview::MemoryTypeTableBuilder CVTypes; + /// @brief Creates an format-specific object file dumper. -static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, +static std::error_code createDumper(const ObjectFile *Obj, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result) { if (!Obj) return readobj_error::unsupported_file_format; @@ -294,19 +339,20 @@ static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, /// @brief Dumps the specified object file. static void dumpObject(const ObjectFile *Obj) { - StreamWriter Writer(outs()); + ScopedPrinter Writer(outs()); std::unique_ptr<ObjDumper> Dumper; if (std::error_code EC = createDumper(Obj, Writer, Dumper)) reportError(Obj->getFileName(), EC); - outs() << '\n'; - outs() << "File: " << Obj->getFileName() << "\n"; - outs() << "Format: " << Obj->getFileFormatName() << "\n"; - outs() << "Arch: " - << Triple::getArchTypeName((llvm::Triple::ArchType)Obj->getArch()) - << "\n"; - outs() << "AddressSize: " << (8*Obj->getBytesInAddress()) << "bit\n"; - Dumper->printLoadName(); + if (opts::Output == opts::LLVM) { + outs() << '\n'; + outs() << "File: " << Obj->getFileName() << "\n"; + outs() << "Format: " << Obj->getFileFormatName() << "\n"; + outs() << "Arch: " << Triple::getArchTypeName( + (llvm::Triple::ArchType)Obj->getArch()) << "\n"; + outs() << "AddressSize: " << (8 * Obj->getBytesInAddress()) << "bit\n"; + Dumper->printLoadName(); + } if (opts::FileHeaders) Dumper->printFileHeaders(); @@ -334,16 +380,24 @@ static void dumpObject(const ObjectFile *Obj) { Dumper->printGnuHashTable(); if (opts::VersionInfo) Dumper->printVersionInfo(); - if (Obj->getArch() == llvm::Triple::arm && Obj->isELF()) - if (opts::ARMAttributes) - Dumper->printAttributes(); - if (isMipsArch(Obj->getArch()) && Obj->isELF()) { - if (opts::MipsPLTGOT) - Dumper->printMipsPLTGOT(); - if (opts::MipsABIFlags) - Dumper->printMipsABIFlags(); - if (opts::MipsReginfo) - Dumper->printMipsReginfo(); + if (Obj->isELF()) { + if (Obj->getArch() == llvm::Triple::arm) + if (opts::ARMAttributes) + Dumper->printAttributes(); + if (isMipsArch(Obj->getArch())) { + if (opts::MipsPLTGOT) + Dumper->printMipsPLTGOT(); + if (opts::MipsABIFlags) + Dumper->printMipsABIFlags(); + if (opts::MipsReginfo) + Dumper->printMipsReginfo(); + if (opts::MipsOptions) + Dumper->printMipsOptions(); + } + if (opts::SectionGroups) + Dumper->printGroupSections(); + if (opts::HashHistogram) + Dumper->printHashHistogram(); } if (Obj->isCOFF()) { if (opts::COFFImports) @@ -354,8 +408,12 @@ static void dumpObject(const ObjectFile *Obj) { Dumper->printCOFFDirectives(); if (opts::COFFBaseRelocs) Dumper->printCOFFBaseReloc(); + if (opts::COFFDebugDirectory) + Dumper->printCOFFDebugDirectory(); if (opts::CodeView) Dumper->printCodeViewDebugInfo(); + if (opts::CodeViewMergedTypes) + Dumper->mergeCodeViewTypes(CVTypes); } if (Obj->isMachO()) { if (opts::MachODataInCode) @@ -377,35 +435,43 @@ static void dumpObject(const ObjectFile *Obj) { /// @brief Dumps each object file in \a Arc; static void dumpArchive(const Archive *Arc) { - for (auto &ErrorOrChild : Arc->children()) { - if (std::error_code EC = ErrorOrChild.getError()) - reportError(Arc->getFileName(), EC.message()); - const auto &Child = *ErrorOrChild; - 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) - reportError(Arc->getFileName(), EC.message()); + Error Err; + for (auto &Child : Arc->children(Err)) { + Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary(); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) { + std::string Buf; + raw_string_ostream OS(Buf); + logAllUnhandledErrors(ChildOrErr.takeError(), OS, ""); + OS.flush(); + reportError(Arc->getFileName(), Buf); + } continue; } - if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get())) dumpObject(Obj); else reportError(Arc->getFileName(), readobj_error::unrecognized_file_format); } + if (Err) + reportError(Arc->getFileName(), std::move(Err)); } /// @brief Dumps each object file in \a MachO Universal Binary; static void dumpMachOUniversalBinary(const MachOUniversalBinary *UBinary) { for (const MachOUniversalBinary::ObjectForArch &Obj : UBinary->objects()) { - ErrorOr<std::unique_ptr<MachOObjectFile>> ObjOrErr = Obj.getAsObjectFile(); + Expected<std::unique_ptr<MachOObjectFile>> ObjOrErr = Obj.getAsObjectFile(); if (ObjOrErr) dumpObject(&*ObjOrErr.get()); - else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = Obj.getAsArchive()) + else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) { + std::string Buf; + raw_string_ostream OS(Buf); + logAllUnhandledErrors(ObjOrErr.takeError(), OS, ""); + OS.flush(); + reportError(UBinary->getFileName(), Buf); + } + else if (Expected<std::unique_ptr<Archive>> AOrErr = Obj.getAsArchive()) dumpArchive(&*AOrErr.get()); - else - reportError(UBinary->getFileName(), ObjOrErr.getError().message()); } } @@ -413,9 +479,9 @@ static void dumpMachOUniversalBinary(const MachOUniversalBinary *UBinary) { static void dumpInput(StringRef File) { // Attempt to open the binary. - ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(File); - if (std::error_code EC = BinaryOrErr.getError()) - reportError(File, EC); + Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File); + if (!BinaryOrErr) + reportError(File, errorToErrorCode(BinaryOrErr.takeError())); Binary &Binary = *BinaryOrErr.get().getBinary(); if (Archive *Arc = dyn_cast<Archive>(&Binary)) @@ -432,7 +498,7 @@ static void dumpInput(StringRef File) { } int main(int argc, const char *argv[]) { - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); PrettyStackTraceProgram X(argc, argv); llvm_shutdown_obj Y; @@ -448,5 +514,10 @@ int main(int argc, const char *argv[]) { std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), dumpInput); + if (opts::CodeViewMergedTypes) { + ScopedPrinter W(outs()); + dumpCodeViewMergedTypes(W, CVTypes); + } + return 0; } |