This is the mail archive of the binutils@sourceware.org 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, start address of "subsection" and alignment


Hi Mike,

> SECTIONS {
>     .data : {
>         __foo = .;
 
> But this doesn't actually work because of the alignment. That is, `__foo`
> gets its value pre-alignment. This is what -print-map says about .data:

>                 0x0000000000201028                __foo = .
>  *(.foo)
>  *fill*         0x0000000000201028       0x18 
>  .foo           0x0000000000201040        0x8 /tmp/ccEGZYAm.o

> but that doesn't seem very satisfactory. ALIGNOF doesn't allow to get
> the alignment requirement from some input. Am I missing something or
> is it not possible to do this "generically"?

You could add an alignment attribute to the declaration of the .data section
so that it starts on a 32-byte boundary.

  SECTIONS {
    .data : ALIGN(32) {

Although this still requires that you know the alignment requirements in advance.
You could try the ALIGN_WITH_INPUT attribute instead.  I am not exactly sure what
this is supposed to do, but it might work:

  SECTIONS {
     .data : ALIGN_WITH_INPUT {

Alternatively you could sort the entries in the section by alignment.  This will
put the largest alignment entries first, which I think will also bring the start
of the section to the largest alignment boundary needed.

  SECTIONS {
    .data : {
      __foo = . ;
      SORT_BY_ALIGNMENT (*(.foo))

Cheers
  Nick


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