diff options
Diffstat (limited to 'contrib/llvm-project/llvm/tools/llvm-readobj/llvm-readobj.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/tools/llvm-readobj/llvm-readobj.cpp | 155 |
1 files changed, 91 insertions, 64 deletions
diff --git a/contrib/llvm-project/llvm/tools/llvm-readobj/llvm-readobj.cpp b/contrib/llvm-project/llvm/tools/llvm-readobj/llvm-readobj.cpp index fadeec1072d6..1bd5bb74bf29 100644 --- a/contrib/llvm-project/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/contrib/llvm-project/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -58,11 +58,6 @@ namespace opts { "--section-groups and --elf-hash-histogram.")); cl::alias AllShort("a", cl::desc("Alias for --all"), cl::aliasopt(All)); - // --dependent-libraries - cl::opt<bool> - DependentLibraries("dependent-libraries", - cl::desc("Display the dependent libraries section")); - // --headers -e cl::opt<bool> Headers("headers", @@ -236,11 +231,26 @@ namespace opts { "codeview-subsection-bytes", cl::desc("Dump raw contents of codeview debug sections and records")); - // --arch-specific - cl::opt<bool> ArchSpecificInfo("arch-specific", - cl::desc("Displays architecture-specific information, if there is any.")); - cl::alias ArchSpecifcInfoShort("A", cl::desc("Alias for --arch-specific"), - cl::aliasopt(ArchSpecificInfo), cl::NotHidden); + // --arm-attributes + cl::opt<bool> ARMAttributes("arm-attributes", + cl::desc("Display the ARM attributes section")); + + // --mips-plt-got + cl::opt<bool> + 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")); + + // --mips-options + cl::opt<bool> MipsOptions("mips-options", + cl::desc("Display the MIPS .MIPS.options section")); // --coff-imports cl::opt<bool> @@ -314,11 +324,6 @@ namespace opts { PrintStackMap("stackmap", cl::desc("Display contents of stackmap section")); - // --stack-sizes - cl::opt<bool> - PrintStackSizes("stack-sizes", - cl::desc("Display contents of all stack sizes sections")); - // --version-info, -V cl::opt<bool> VersionInfo("version-info", @@ -363,43 +368,63 @@ namespace opts { HelpResponse("\nPass @FILE as argument to read options from FILE.\n"); } // namespace opts -static StringRef ToolName; - namespace llvm { -LLVM_ATTRIBUTE_NORETURN static void error(Twine Msg) { - // Flush the standard output to print the error at a - // proper place. +LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { fouts().flush(); - WithColor::error(errs(), ToolName) << Msg << "\n"; + errs() << "\n"; + WithColor::error(errs()) << Msg << "\n"; exit(1); } -LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input) { - assert(Err); +void reportError(StringRef Input, Error Err) { if (Input == "-") Input = "<stdin>"; - handleAllErrors(createFileError(Input, std::move(Err)), - [&](const ErrorInfoBase &EI) { error(EI.message()); }); - llvm_unreachable("error() call should never return"); + error(createFileError(Input, std::move(Err))); } -void reportWarning(Error Err, StringRef Input) { - assert(Err); - if (Input == "-") - Input = "<stdin>"; - - // Flush the standard output to print the warning at a - // proper place. +void reportWarning(Twine Msg) { fouts().flush(); - handleAllErrors( - createFileError(Input, std::move(Err)), [&](const ErrorInfoBase &EI) { - WithColor::warning(errs(), ToolName) << EI.message() << "\n"; - }); + errs() << "\n"; + WithColor::warning(errs()) << Msg << "\n"; +} + +void warn(Error Err) { + handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) { + reportWarning(EI.message()); + }); +} + +void error(Error EC) { + if (!EC) + return; + handleAllErrors(std::move(EC), + [&](const ErrorInfoBase &EI) { reportError(EI.message()); }); +} + +void error(std::error_code EC) { + if (!EC) + return; + reportError(EC.message()); } } // namespace llvm +static void reportError(StringRef Input, std::error_code EC) { + reportError(Input, errorCodeToError(EC)); +} + +static bool isMipsArch(unsigned Arch) { + switch (Arch) { + case llvm::Triple::mips: + case llvm::Triple::mipsel: + case llvm::Triple::mips64: + case llvm::Triple::mips64el: + return true; + default: + return false; + } +} namespace { struct ReadObjTypeTableBuilder { ReadObjTypeTableBuilder() @@ -446,19 +471,19 @@ static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer, std::unique_ptr<ObjDumper> Dumper; if (std::error_code EC = createDumper(Obj, Writer, Dumper)) - reportError(errorCodeToError(EC), FileStr); + reportError(FileStr, EC); - if (opts::Output == opts::LLVM || opts::InputFilenames.size() > 1 || A) { - Writer.startLine() << "\n"; - Writer.printString("File", FileStr); - } + Writer.startLine() << "\n"; if (opts::Output == opts::LLVM) { + Writer.printString("File", FileStr); Writer.printString("Format", Obj->getFileFormatName()); Writer.printString("Arch", Triple::getArchTypeName( (llvm::Triple::ArchType)Obj->getArch())); Writer.printString("AddressSize", formatv("{0}bit", 8 * Obj->getBytesInAddress())); Dumper->printLoadName(); + } else if (opts::Output == opts::GNU && A) { + Writer.printString("File", FileStr); } if (opts::FileHeaders) @@ -492,12 +517,21 @@ static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer, if (opts::VersionInfo) Dumper->printVersionInfo(); if (Obj->isELF()) { - if (opts::DependentLibraries) - Dumper->printDependentLibs(); if (opts::ELFLinkerOptions) Dumper->printELFLinkerOptions(); - if (opts::ArchSpecificInfo) - Dumper->printArchSpecificInfo(); + 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) @@ -549,8 +583,6 @@ static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer, } if (opts::PrintStackMap) Dumper->printStackMap(); - if (opts::PrintStackSizes) - Dumper->printStackSizes(); } /// Dumps each object file in \a Arc; @@ -559,8 +591,9 @@ static void dumpArchive(const Archive *Arc, ScopedPrinter &Writer) { for (auto &Child : Arc->children(Err)) { Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary(); if (!ChildOrErr) { - if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) - reportError(std::move(E), Arc->getFileName()); + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) { + reportError(Arc->getFileName(), std::move(E)); + } continue; } if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get())) @@ -568,11 +601,10 @@ static void dumpArchive(const Archive *Arc, ScopedPrinter &Writer) { else if (COFFImportFile *Imp = dyn_cast<COFFImportFile>(&*ChildOrErr.get())) dumpCOFFImportFile(Imp, Writer); else - reportError(errorCodeToError(readobj_error::unrecognized_file_format), - Arc->getFileName()); + reportError(Arc->getFileName(), readobj_error::unrecognized_file_format); } if (Err) - reportError(std::move(Err), Arc->getFileName()); + reportError(Arc->getFileName(), std::move(Err)); } /// Dumps each object file in \a MachO Universal Binary; @@ -582,8 +614,9 @@ static void dumpMachOUniversalBinary(const MachOUniversalBinary *UBinary, Expected<std::unique_ptr<MachOObjectFile>> ObjOrErr = Obj.getAsObjectFile(); if (ObjOrErr) dumpObject(&*ObjOrErr.get(), Writer); - else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) - reportError(ObjOrErr.takeError(), UBinary->getFileName()); + else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) { + reportError(UBinary->getFileName(), ObjOrErr.takeError()); + } else if (Expected<std::unique_ptr<Archive>> AOrErr = Obj.getAsArchive()) dumpArchive(&*AOrErr.get(), Writer); } @@ -594,7 +627,7 @@ static void dumpWindowsResourceFile(WindowsResource *WinRes, ScopedPrinter &Printer) { WindowsRes::Dumper Dumper(WinRes, Printer); if (auto Err = Dumper.printData()) - reportError(std::move(Err), WinRes->getFileName()); + reportError(WinRes->getFileName(), std::move(Err)); } @@ -603,7 +636,7 @@ static void dumpInput(StringRef File, ScopedPrinter &Writer) { // Attempt to open the binary. Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File); if (!BinaryOrErr) - reportError(BinaryOrErr.takeError(), File); + reportError(File, BinaryOrErr.takeError()); Binary &Binary = *BinaryOrErr.get().getBinary(); if (Archive *Arc = dyn_cast<Archive>(&Binary)) @@ -618,8 +651,7 @@ static void dumpInput(StringRef File, ScopedPrinter &Writer) { else if (WindowsResource *WinRes = dyn_cast<WindowsResource>(&Binary)) dumpWindowsResourceFile(WinRes, Writer); else - reportError(errorCodeToError(readobj_error::unrecognized_file_format), - File); + reportError(File, readobj_error::unrecognized_file_format); CVTypes.Binaries.push_back(std::move(*BinaryOrErr)); } @@ -670,7 +702,6 @@ static void registerReadelfAliases() { int main(int argc, const char *argv[]) { InitLLVM X(argc, argv); - ToolName = argv[0]; // Register the target printer for --version. cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); @@ -696,10 +727,6 @@ int main(int argc, const char *argv[]) { opts::UnwindInfo = true; opts::SectionGroups = true; opts::HashHistogram = true; - if (opts::Output == opts::LLVM) { - opts::Addrsig = true; - opts::PrintStackSizes = true; - } } if (opts::Headers) { |
