[ld] section address : ALIGN(align) and the maximum of input section alignments

Alan Modra amodra@gmail.com
Tue Mar 3 22:39:00 GMT 2020


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



More information about the Binutils mailing list