This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [ld] section address : ALIGN(align) and the maximum of input section alignments
- From: Alan Modra <amodra at gmail dot com>
- To: Fangrui Song <i at maskray dot me>
- Cc: binutils <binutils at sourceware dot org>
- Date: Wed, 4 Mar 2020 09:09:01 +1030
- Subject: Re: [ld] section address : ALIGN(align) and the maximum of input section alignments
- References: <20200226052300.wazzfmivxta63vef@gmail.com> <20200226063003.4uvshiarho3wbkrl@google.com>
On Tue, Feb 25, 2020 at 10:30:03PM -0800, Fangrui Song wrote:
> > Why doesn't `.bss . : ALIGN(16)` respect the maximum of input section alignments (32)?
> >
> > (I have verified that .bss being SHT_NOBITS is unrelated.)
> >
> > The rule of sh_addr computation appears to be:
> >
> > * ADDR is unset, ALIGN is unset => max_input_alignment
> > * ADDR is unset, ALIGN is set => max(ALIGN, max_input_alignment)
> > * ADDR is set, ALIGN is unset => max_input_alignment
> > * ADDR is set, ALIGN is set => ALIGN
>
> When ADDR is set, ALIGN is used while max_input_alignment is ignored.
>
> ld/ldlang.c:5582
>
> if (os->addr_tree == NULL) {
> ...
> newdot = os->region->current;
> // maximum of ALIGN and input section alignments
> section_alignment = os->bfd_section->alignment_power;
> }
> else
> // ALIGN
> section_alignment = exp_get_power (os->section_alignment, "section alignment");
>
> Alan, is the `else` branch supposed to use `section_alignment = os->bfd_section->alignment_power;` as well?
No. When you specify the address of an output section that is the
address it should have. Except that specifying both an address and
alignment aligns the address given. Specifying both is somewhat
contradictory and it would probably have been better if we didn't
support ALIGN here.
--
Alan Modra
Australia Development Lab, IBM