This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [Patch mach-o] don't set file offsets / write .zerofill sections
- From: Tristan Gingold <gingold at adacore dot com>
- To: Iain Sandoe <developer at sandoe-acoustics dot co dot uk>
- Cc: binutils Development <binutils at sourceware dot org>
- Date: Wed, 11 Jan 2012 16:09:05 +0100
- Subject: Re: [Patch mach-o] don't set file offsets / write .zerofill sections
- References: <21DB959E-79F5-4537-AABB-E5C571E3AE1E@sandoe-acoustics.co.uk>
On Jan 11, 2012, at 3:36 PM, Iain Sandoe wrote:
> zerofill sections don't occupy any disk space - and should not have offsets.
> which we currently compute, an oversight of mine not to change this when adding support for zerofill,
> corrected as below,
> OK?
Yes.
Thanks.
> Iain
>
> bfd:
>
> * mach-o.c (bfd_mach_o_build_seg_command): Separate computation of
> vmsize from filesize. Don't compute offsets or file sizes for
> zerofill sections.
>
>
> bfd/mach-o.c | 20 ++++++++++++++++----
> 1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/bfd/mach-o.c b/bfd/mach-o.c
> index 1234899..1a71216 100644
> --- a/bfd/mach-o.c
> +++ b/bfd/mach-o.c
> @@ -2023,6 +2023,7 @@ bfd_mach_o_build_seg_command (const char *segment,
>
> /* TODO: fix this up for non-MH_OBJECT cases. */
> seg->vmaddr = 0;
> + seg->vmsize = 0;
>
> seg->fileoff = mdata->filelen;
> seg->filesize = 0;
> @@ -2048,9 +2049,21 @@ bfd_mach_o_build_seg_command (const char *segment,
>
> bfd_mach_o_append_section_to_segment (seg, sec);
>
> - if (s->size == 0)
> - s->offset = 0;
> - else
> + s->offset = 0;
> + if (s->size > 0)
> + {
> + seg->vmsize = FILE_ALIGN (seg->vmsize, s->align);
> + seg->vmsize += s->size;
> + }
> +
> + /* Zerofill sections have zero file size & offset,
> + and are not written. */
> + if ((s->flags & BFD_MACH_O_SECTION_TYPE_MASK) == BFD_MACH_O_S_ZEROFILL
> + || (s->flags & BFD_MACH_O_SECTION_TYPE_MASK)
> + == BFD_MACH_O_S_GB_ZEROFILL)
> + continue;
> +
> + if (s->size > 0)
> {
> mdata->filelen = FILE_ALIGN (mdata->filelen, s->align);
> s->offset = mdata->filelen;
> @@ -2062,7 +2075,6 @@ bfd_mach_o_build_seg_command (const char *segment,
> }
>
> seg->filesize = mdata->filelen - seg->fileoff;
> - seg->vmsize = seg->filesize;
>
> return TRUE;
> }
>