This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFC] Aligning segments in gold
- From: Ian Lance Taylor <iant at google dot com>
- To: Cary Coutant <ccoutant at google dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Fri, 9 Jan 2015 14:41:22 -0800
- Subject: Re: [RFC] Aligning segments in gold
- Authentication-results: sourceware.org; auth=none
- References: <CAHACq4r+uun3awgdM3VBybWF9+eC66C12mcMS2CyHm0k43bBPg at mail dot gmail dot com>
On Fri, Jan 9, 2015 at 2:29 PM, Cary Coutant <ccoutant@google.com> wrote:
>
> In Layout::set_segment_offsets, we have this code:
>
> // Skip the address forward one page, maintaining the same
> // position within the page. This lets us store both segments
> // overlapping on a single page in the file, but the loader will
> // put them on different pages in memory. We will revisit this
> // decision once we know the size of the segment.
>
> addr = align_address(addr, (*p)->maximum_alignment());
> aligned_addr = addr;
>
> if (load_seg == *p)
> {
> // ...
> }
> else
> {
> if ((addr & (abi_pagesize - 1)) != 0)
> addr = addr + abi_pagesize;
>
> off = orig_off + ((addr - orig_addr) & (abi_pagesize - 1));
> }
>
> Usually, this works fine -- we'll set addr = addr + abi_pagesize, then
> adjust off so that we share a page in the file. But what happens when
> (*p)->maximum_alignment() returns a large value like 4096? We end up
> aligning addr first to a page boundary, and that's all. If -z relro
> adjustment results in more padding such that we *could* have
> overlapped the segments in the file, we lose the opportunity and end
> up wasting a page. If we subsequently run the output through strip,
> strip will "fix" that for us, the p_offset fields won't match, and GDB
> will complain that the unstripped binary doesn't match the core file.
>
> I'm thinking we don't need to align to (*p)->maximum_alignment() at
> all here, unless it's larger than abi_pagesize. Each output section in
> the segment will be aligned appropriately without that, and we don't
> need the segment's starting address to match that alignment, since the
> loader always preserves the offset modulo page size when relocating
> segments. Indeed, with relro adjustment, the starting address of the
> segment rarely matches the alignment of its most strictly-aligned
> section.
(*p)->maximum_alignment is going to feed into the p_align field. It
sounds like you are saying that it's OK if a phdr is not aligned
according to what its p_align field says. Is that right?
Other than that, what you say makes sense to me.
Ian