1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

For llvm-objdump, add the option -private-header (without the trailing ’s’)

to only print the first private header.

Which for Mach-O files only prints the Mach header and not the subsequent load
commands.  Which is used by scripts to match what the darwin otool(1) with the
-h flag does without the -l flag.

For non-Mach-O files it has the same functionality as -private-headers (with
the trailing ’s’).

rdar://24158331

llvm-svn: 257548
This commit is contained in:
Kevin Enderby 2016-01-13 00:25:36 +00:00
parent 225d44d8a7
commit 3f9a07c662
4 changed files with 52 additions and 11 deletions

View File

@ -0,0 +1,6 @@
// RUN: llvm-objdump -private-header %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
CHECK: Mach header
CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
CHECK: MH_MAGIC_64 X86_64 ALL 0x00 OBJECT 3 496 SUBSECTIONS_VIA_SYMBOLS
CHECK-NOT: Load command

View File

@ -1196,7 +1196,11 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
PrintSymbolTable(MachOOF);
if (UnwindInfo)
printMachOUnwindInfo(MachOOF);
if (PrivateHeaders)
if (PrivateHeaders) {
printMachOFileHeader(MachOOF);
printMachOLoadCommands(MachOOF);
}
if (FirstPrivateHeader)
printMachOFileHeader(MachOOF);
if (ObjcMetaData)
printObjcMetaData(MachOOF, !NonVerbose);
@ -8646,31 +8650,40 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t filetype,
}
}
static void getAndPrintMachHeader(const MachOObjectFile *Obj,
uint32_t &filetype, uint32_t &cputype,
bool verbose) {
static void PrintMachHeader(const MachOObjectFile *Obj, bool verbose) {
if (Obj->is64Bit()) {
MachO::mach_header_64 H_64;
H_64 = Obj->getHeader64();
PrintMachHeader(H_64.magic, H_64.cputype, H_64.cpusubtype, H_64.filetype,
H_64.ncmds, H_64.sizeofcmds, H_64.flags, verbose);
filetype = H_64.filetype;
cputype = H_64.cputype;
} else {
MachO::mach_header H;
H = Obj->getHeader();
PrintMachHeader(H.magic, H.cputype, H.cpusubtype, H.filetype, H.ncmds,
H.sizeofcmds, H.flags, verbose);
filetype = H.filetype;
cputype = H.cputype;
}
}
void llvm::printMachOFileHeader(const object::ObjectFile *Obj) {
const MachOObjectFile *file = dyn_cast<const MachOObjectFile>(Obj);
PrintMachHeader(file, !NonVerbose);
}
void llvm::printMachOLoadCommands(const object::ObjectFile *Obj) {
const MachOObjectFile *file = dyn_cast<const MachOObjectFile>(Obj);
uint32_t filetype = 0;
uint32_t cputype = 0;
getAndPrintMachHeader(file, filetype, cputype, !NonVerbose);
if (file->is64Bit()) {
MachO::mach_header_64 H_64;
H_64 = file->getHeader64();
filetype = H_64.filetype;
cputype = H_64.cputype;
} else {
MachO::mach_header H;
H = file->getHeader();
filetype = H.filetype;
cputype = H.cputype;
}
PrintLoadCommands(file, filetype, cputype, !NonVerbose);
}

View File

@ -165,6 +165,11 @@ cl::opt<bool>
llvm::PrivateHeaders("private-headers",
cl::desc("Display format specific file headers"));
cl::opt<bool>
llvm::FirstPrivateHeader("private-header",
cl::desc("Display only the first format specific file "
"header"));
static cl::alias
PrivateHeadersShort("p", cl::desc("Alias for --private-headers"),
cl::aliasopt(PrivateHeaders));
@ -1495,7 +1500,19 @@ static void printFaultMaps(const ObjectFile *Obj) {
outs() << FMP;
}
static void printPrivateFileHeader(const ObjectFile *o) {
static void printPrivateFileHeaders(const ObjectFile *o) {
if (o->isELF())
printELFFileHeader(o);
else if (o->isCOFF())
printCOFFFileHeader(o);
else if (o->isMachO()) {
printMachOFileHeader(o);
printMachOLoadCommands(o);
} else
report_fatal_error("Invalid/Unsupported object file format");
}
static void printFirstPrivateFileHeader(const ObjectFile *o) {
if (o->isELF())
printELFFileHeader(o);
else if (o->isCOFF())
@ -1527,7 +1544,9 @@ static void DumpObject(const ObjectFile *o) {
if (UnwindInfo)
PrintUnwindInfo(o);
if (PrivateHeaders)
printPrivateFileHeader(o);
printPrivateFileHeaders(o);
if (FirstPrivateHeader)
printFirstPrivateFileHeader(o);
if (ExportsTrie)
printExportsTrie(o);
if (Rebase)
@ -1618,6 +1637,7 @@ int main(int argc, char **argv) {
&& !SymbolTable
&& !UnwindInfo
&& !PrivateHeaders
&& !FirstPrivateHeader
&& !ExportsTrie
&& !Rebase
&& !Bind

View File

@ -31,6 +31,7 @@ extern cl::opt<bool> Disassemble;
extern cl::opt<bool> DisassembleAll;
extern cl::opt<bool> NoShowRawInsn;
extern cl::opt<bool> PrivateHeaders;
extern cl::opt<bool> FirstPrivateHeader;
extern cl::opt<bool> ExportsTrie;
extern cl::opt<bool> Rebase;
extern cl::opt<bool> Bind;
@ -70,6 +71,7 @@ void printELFFileHeader(const object::ObjectFile *o);
void printCOFFFileHeader(const object::ObjectFile *o);
void printCOFFSymbolTable(const object::COFFObjectFile *o);
void printMachOFileHeader(const object::ObjectFile *o);
void printMachOLoadCommands(const object::ObjectFile *o);
void printExportsTrie(const object::ObjectFile *o);
void printRebaseTable(const object::ObjectFile *o);
void printBindTable(const object::ObjectFile *o);