How to pad a section to an aligned size in the linker script file

R. Diez rdiezmail-binutils@yahoo.de
Thu Jul 14 14:56:00 GMT 2011


Hi there:

I have some PowerPC assembly code in crt0.asm that zeroes sections .bss and .sbss before calling main(). I copied that piece of code from somewhere else, and it can only fill 32-bit aligned sizes, as it writes 32-bit words at a time. At the beginning, it just divides the size by 4, so it may miss up to 3 bytes at the end.

I have seen in the map file that the size of my .bss/.sbss section is not always a multiple of 4. I then tried to add 32 bits worth of padding at the end with LONG(0), so that the important content always get zeroed. That portion in the linker script file looks like this:

    .sbss :
    {
      *(.sbss)
      *(.sbss.*)
      LONG(0)  
    } >ram

    .bss :
    {
      *(.bss)
      *(.bss.*)
      LONG(0)
    } >ram

However, I'm getting these linker warnings:

powerpc-unknown-eabi/bin/ld: warning: section `.sbss' type changed to PROGBITS
powerpc-unknown-eabi/bin/ld: warning: section `.bss' type changed to PROGBITS

As far as I can see, there are 2 ways to solve this:

1) Instead of LONG(0), use some directive to reserve the space, but not fill it. I haven't found which directive could do that though.

2) Convince the linker that the section size should grow if necessary to be a multiple of 4. I haven't found a way to achieve that yet.

Can anybody help?

Please copy me on the answer, as I'm not subscribed to this list.

Thanks in advance,
  R. Diez



More information about the Binutils mailing list