mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-30 05:24:22 +00:00
[FaultMaps] Add a parser for the __llvm__faultmaps section.
Summary: The parser is exercised by llvm-objdump using -print-fault-maps. As is probably obvious, the code itself was "heavily inspired" by http://reviews.llvm.org/D10434. Reviewers: reames, atrick, JosephTremoulet Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10491 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240304 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -17,9 +17,11 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-objdump.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/CodeGen/FaultMaps.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCDisassembler.h"
|
||||
@ -153,6 +155,9 @@ cl::opt<bool>
|
||||
llvm::PrintImmHex("print-imm-hex",
|
||||
cl::desc("Use hex format for immediate values"));
|
||||
|
||||
cl::opt<bool> PrintFaultMaps("fault-map-section",
|
||||
cl::desc("Display contents of faultmap section"));
|
||||
|
||||
static StringRef ToolName;
|
||||
static int ReturnValue = EXIT_SUCCESS;
|
||||
|
||||
@ -1226,6 +1231,49 @@ void llvm::printWeakBindTable(const ObjectFile *o) {
|
||||
}
|
||||
}
|
||||
|
||||
static void printFaultMaps(const ObjectFile *Obj) {
|
||||
const char *FaultMapSectionName = nullptr;
|
||||
|
||||
if (isa<ELFObjectFileBase>(Obj)) {
|
||||
FaultMapSectionName = ".llvm_faultmaps";
|
||||
} else if (isa<MachOObjectFile>(Obj)) {
|
||||
FaultMapSectionName = "__llvm_faultmaps";
|
||||
} else {
|
||||
errs() << "This operation is only currently supported "
|
||||
"for ELF and Mach-O executable files.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<object::SectionRef> FaultMapSection;
|
||||
|
||||
for (auto Sec : Obj->sections()) {
|
||||
StringRef Name;
|
||||
Sec.getName(Name);
|
||||
if (Name == FaultMapSectionName) {
|
||||
FaultMapSection = Sec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outs() << "FaultMap table:\n";
|
||||
|
||||
if (!FaultMapSection.hasValue()) {
|
||||
outs() << "<not found>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
StringRef FaultMapContents;
|
||||
if (error(FaultMapSection.getValue().getContents(FaultMapContents))) {
|
||||
errs() << "Could not read the " << FaultMapContents << " section!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
FaultMapParser FMP(FaultMapContents.bytes_begin(),
|
||||
FaultMapContents.bytes_end());
|
||||
|
||||
outs() << FMP;
|
||||
}
|
||||
|
||||
static void printPrivateFileHeader(const ObjectFile *o) {
|
||||
if (o->isELF()) {
|
||||
printELFFileHeader(o);
|
||||
@ -1265,6 +1313,8 @@ static void DumpObject(const ObjectFile *o) {
|
||||
printLazyBindTable(o);
|
||||
if (WeakBind)
|
||||
printWeakBindTable(o);
|
||||
if (PrintFaultMaps)
|
||||
printFaultMaps(o);
|
||||
}
|
||||
|
||||
/// @brief Dump each object file in \a a;
|
||||
@ -1362,7 +1412,8 @@ int main(int argc, char **argv) {
|
||||
&& !(DylibsUsed && MachOOpt)
|
||||
&& !(DylibId && MachOOpt)
|
||||
&& !(ObjcMetaData && MachOOpt)
|
||||
&& !(DumpSections.size() != 0 && MachOOpt)) {
|
||||
&& !(DumpSections.size() != 0 && MachOOpt)
|
||||
&& !PrintFaultMaps) {
|
||||
cl::PrintHelpMessage();
|
||||
return 2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user