public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* How to pad a section to an aligned size in the linker script file
@ 2011-07-14 14:56 R. Diez
  2011-07-14 17:09 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: R. Diez @ 2011-07-14 14:56 UTC (permalink / raw)
  To: binutils

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to pad a section to an aligned size in the linker script file
  2011-07-14 14:56 How to pad a section to an aligned size in the linker script file R. Diez
@ 2011-07-14 17:09 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2011-07-14 17:09 UTC (permalink / raw)
  To: R. Diez; +Cc: binutils

On Thu, Jul 14, 2011 at 12:38:13PM +0100, R. Diez wrote:
> 1) Instead of LONG(0), use some directive to reserve the space, but not fill it.

. = ALIGN(4);

or if you want to be a little more fancy

. = ALIGN(. != 0 ? 4 : 1);

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-14 12:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-14 14:56 How to pad a section to an aligned size in the linker script file R. Diez
2011-07-14 17:09 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).