This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linker Script question: section alignment


Hi Dave,

> I have a customer who is trying to align the entire .srodata output
> section on an 8 byte boundary within a MEMORY region.

I assume the customer has the latest release of binutils ?

> He has tried:
>
>     .srodata BLOCK(8): {
>     {
>        *(.srodata) *(.srodata.*) *(.gnu.linkonce.srd.*)
>     } >MYREGION;
>
> which fails with
>
> address 0x0 of a.out section .srodata is not within region MYREGION if
> .srodata is the first output section assigned to MYREGION, but not if
> it is the second or subsequent section (is this a bug?)

Not really.  The reason for the message is that the BLOCK directive
computes a value for . which is absolute, not relative to the region
containing the section.  Once a first section has been assigned to a
region, . is advanced to be within that region's boundaries.  So
subsequent assignments to the region (assuming that they follow on
immediately in the script) will be in scope and the BLOCK directive
will work.

> He has also tried:
> 
>     .srodata :
>     {
>         . = BLOCK(8);
>         *(.srodata) *(.srodata.*) *(.gnu.linkonce.srd.*)
>     } >MYREGION
> 
> which aligns the data within the section but not the section
> itself.

If the region itself is aligned, then what is the problem ?  ie why
can't your customer use:

  .srodata BLOCK(8) : {....} >MYREGION;

if it is not the first section to be assigned to MYREGION and

  .srodata : {....} >MYREGION;

if it is ?

If they are unsure as to whether previous sections assigned to the
regions will actually be present in the linker's input, and hence
cannot guarantee that they will be assigned to the output, then they
could try initialising . before using it in the the BLOCK expression.
ie something like this:

  MEMORY { MYREGION : ORIGIN = 0x100, LENGTH = 0x100 }
  SECTIONS
  {
     . = 0x100
     .srodata ALIGN(8) : { *(.srodata) } >MYREGION
     .otherdata ALIGN(8) : { *(.blah) } >MYREGION
  }

Cheers
        Nick


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]