[PATCH] [lld] MachO: calculating file offsets in final objects

Tim Northover t.p.northover at gmail.com
Mon Jun 23 06:13:49 PDT 2014


Hi,

I believe we were calculating file and vm offsets incorrectly in final
(non-relocatable) MachO files.

The most obvious failure was in vmaddr, where the constraint that
segments begin at a page was being ignored. lld itself detected this,
and failed to linke with an invalid format error.

However, even when this was addressed, the mechanisms for calculating
fileoffset and filesize turned out to be inadequate. For fileoffset,
the values weren't advancing at all between segments, with obviously
bad results. For filesize, we were taking a "best guess" based on the
segment's size. In reality I think this needs to be calculated based
on the sections in that segment: basically the last byte actually
filled with data (so ignore S_ZEROFILL), rounded up to page size.

The attached two patches should take care of these issues. Do they
look reasonable?

Cheers.

Tim.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-MachO-calculate-segment-offsets-in-final-MachO-files.patch
Type: application/octet-stream
Size: 4633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140623/98088a2a/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-MachO-align-segment-virtual-addresses-to-page-size.patch
Type: application/octet-stream
Size: 3217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140623/98088a2a/attachment-0001.obj>


More information about the llvm-commits mailing list