This is an archive of the discontinued LLVM Phabricator instance.

objdump: Better handling of Mach-O universal binaries
ClosedPublic

Authored by kastiglione on Jun 27 2018, 9:11 PM.

Details

Summary

With Mach-O, there is a flag requirement discrepancy between working with
universal binaries and thin binaries. Many flags that don't require the -macho
flag (for example -private-headers and -disassemble) fail to work on
universal binaries unless -macho is given. When this happens, the error
message is unhelpful, stating:

The file was not recognized as a valid object file.

Which can lead to confusion.

This change allows generic flags to be used on universal binaries with and
without the -macho flag. This means flags that can be used for thin files can
be used consistently with fat files too.

To do this, the universal binary support within ParseInputMachO() is extracted
into a new function. This new function is called directly from DumpInput()
when the input binary is universal. Additionally the -arch flag validation in
ParseInputMachO() was extracted to be reused.

Diff Detail

Event Timeline

kastiglione created this revision.Jun 27 2018, 9:11 PM
compnerd added inline comments.Jul 5 2018, 3:15 PM
tools/llvm-objdump/MachODump.cpp
2009

Yes, I know you just moved the code, but please either remove or keep braces on both sides.

Make if/else bracing consistent

kastiglione marked an inline comment as done.Jul 5 2018, 10:22 PM

Oops, fix last diff update

compnerd accepted this revision.Jul 20 2018, 9:44 AM
compnerd added inline comments.
tools/llvm-objdump/MachODump.cpp
1961

This leaves the old behavior in place, but I think it would be nicer if the arch flag was validated earlier.

This revision is now accepted and ready to land.Jul 20 2018, 9:44 AM
kastiglione added inline comments.Jul 20 2018, 3:39 PM
tools/llvm-objdump/MachODump.cpp
1961

Did you have something specific in mind? By the caller, before calling this function? Or something else…

This revision was automatically updated to reflect the committed changes.