[PATCH] llvm-objdump macho section extractor.

Kevin Enderby via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 13:53:48 PDT 2016


> On Aug 8, 2016, at 11:27 AM, Puyan Lotfi <puyan.lotfi.llvm at gmail.com> wrote:
> 
> Kevin
> 
> I have a new patch attached.
> 
> I am fine with only supporting LC_SEGMENT_64 or LC_SEGMENT_64  for the time being but I adding a message in case the extract code encounters a segment other than those types.

I’m not understanding why you consider it an error to have load commands other than an LC_SEGMENT_64 or LC_SEGMENT_64 used with Mach-O files used with your option.  Is this not expected work with something an x86_64 Mach-O compiled for a Mac OS X?  It would have other load commands for like LC_SYMTAB, LC_UUID, LC_FUNCTION_STARTS, etc.  Or is this option only to work in some GPU Mach-O files with only LC_SEGMENT_64 or LC_SEGMENT_64 load commands?

> 
> I have added some additional flags to narrow down which segment to dump.

> Also, I added a flag and some code to print the section to stderr in a hex format for testing

For test wouldn’t you just extract the sections using your option and test that it is the same as a file one you add to the test suite?

I don’t really understand the need for the code to dump the section to stderr.   There is already the option -section to dump Mach-O sections. Also seems odd that you use the ‘C’ printf style of coding here.  Maybe something more C++ like would fit better with the llvm code if you really want to keep this bit.

> and I've added a test case as well.

Seems like this could be a bit smaller and test the extracted file and use your -extract-macho-sections-dir option.  Without that it seems like the test will write into the location of the input file.

> 
> Let me known how this looks to you.
> 
> Thanks
> 
> PL
> 
> On Fri, Aug 5, 2016 at 4:22 PM, Kevin Enderby <enderby at apple.com <mailto:enderby at apple.com>> wrote:
> Hi Puyan,
> 
> Seems like the functionality would be easier to test if it didn’t write the output files to the same directory as the input file.  And of course you’ll want to add a test case as the llvm tradition with any changes.
> 
> Also I’m not an llvm style expert but you can likely shorten the logic and not use the a switch statement for your return value from ExtractLoadCommand().  Also it looks like it should get an error with any Mach-O file that has non LC_SEGMENT_64 or LC_SEGMENT_64 commands?  Is that correct and what you want.
> 
> You also might just want to return a bool for success of failure from ExtractSectionData() and your other routines.
> 
> Also it llvm seems to like the shortest bit if code so I don’t think you need the “int Res” and could just use an if statement.
> 
> Kev
> 
> > On Aug 5, 2016, at 4:06 PM, Puyan Lotfi <puyan.lotfi.llvm at gmail.com <mailto:puyan.lotfi.llvm at gmail.com>> wrote:
> >
> > Hi Kevin, All:
> >
> > I have a macho-extract tool kicking around locally that I threw together a while back that simply dumps each section in a MachO to disk, and I've decided it's probably high-time to upstream the functionality into llvm-objdump.
> >
> > Let me know if this looks good enough to check in, or otherwise feedback would be nice too.
> >
> > Thanks
> >
> > PL
> >
> >
> > <llvm-objdump-macho-extract.patch>
> 
> 
> <llvm-objdump-macho-extract2.patch>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160808/7e581781/attachment-0001.html>


More information about the llvm-commits mailing list