This is the mail archive of the
mailing list for the binutils project.
Re: GNU ld and file offset alignment
- From: Alan Modra <amodra at gmail dot com>
- To: Martim Carbone <martimcarbone at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 28 Jun 2017 14:16:28 +0930
- Subject: Re: GNU ld and file offset alignment
- Authentication-results: sourceware.org; auth=none
- References: <CAO6oTxiZOU3cFAfPoardRrjSDAWN87g_PpEEVX2yTBtFj_eH8Q@mail.gmail.com>
On Tue, Jun 27, 2017 at 11:32:49AM -0700, Martim Carbone wrote:
> I have a question regarding GNU ld and I was hoping you could help me.
> When ld writes a section to an ELF executable, how does the
> section alignment specified in the linker script influence the choice
> of file offset for this section, assuming '-n' is being used?
> Say, if I set the section address alignment to 0x1000, will ld also
> page-align it on disk? My experiments suggest that that is the case
> but I wanted to be sure that this is not accidental.
GNU ld will set the file offset of a PT_LOAD segment using at least
the maximum alignment of sections within the segment, such that
p_offset == p_vaddr % alignment. That will result in section
sh_offset being aligned as you suspect.
Australia Development Lab, IBM