can we pad some section with some value

Nick Clifton nickc@redhat.com
Mon Jan 25 11:23:00 GMT 2010


Hi miloody,

> What can I ask linker to help me, if I need the whole binary padding
> to a fix length?
> ex:
>     suppose my binary is 11k. But I want the linker to pad the end of
> binary and make the whole size of final output file  to be 16k, like
> what alignment does.
> is there any command I can use?

What you need is a dummy section at the end of your linker script which 
is sized so that it will extend the binary to the required length.  For 
example:

   SECTIONS
   {
     .text : { *(.text); }
     .data : { *(.data); }

     here = . ; .fill : { LONG(0xff); . = 0x3ffc - here ; } =0xff
   }

Note - you need at least one entry in the .fill section in order to the 
linker to decide that it actually has some contents, and so give it the 
PROGBITS type rather than the NOBITS type.

The value 0x3ffc in the above example is computed as: "16k - 4 bytes", 
the four bytes being for the LONG value.

Cheers
   Nick



More information about the Binutils mailing list