How to create an image file with a specific size from a linked absolute code

Nick Clifton nickc@redhat.com
Tue May 17 15:11:00 GMT 2011


Hi Ali,

[Note your asm2.s file needs a .data directive at the start in order to 
ensure that the .byte directive puts values into the data section and 
not the text section].

> It means that between between section5 and .text there is a huge gap!
> Then I compile with:
> ld asm2.o asm3.o -T asm2.ld -o asm2
> objcopy -O binary asm2 asm2.img
>
> I want my final image, means asm2.img, becomes 4 mega bytes and the
> space between section5 and .text gets filled by 0xff.

Are you sure that the space is filled with 0xff ?  In the test I ran it 
was filled with 0x00.

> I wonder if anybody knows how to do.

What exactly is it that you want to happen ?

The "binary" file format does not support gaps, so you are not going to 
be able to create a binary file without some padding between the two 
sections.  On the other hand if you are using a modern file system (eg 
ext3, but not NTFS) then the gap will not actually take up a large 
amount of disc space.  The file system detects the pages full of zeroes 
and just does not bother to store them:

   % ls -l asm asm.img
   -rwxrwx---. 1 nickc nickc    8656 May 17 16:06 asm*
   -rwxrwx---. 1 nickc nickc 4194316 May 17 16:06 asm.img*

   % du -s -k asm asm.img
   12      asm
   12      asm.img

Cheers
   Nick




More information about the Binutils mailing list