public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* How to create an image file with a specific size from a linked absolute code
@ 2011-05-16  6:39 ali hagigat
  2011-05-17 15:11 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: ali hagigat @ 2011-05-16  6:39 UTC (permalink / raw)
  To: binutils

I am using two assembly files and a linker script like what follows:

asm2.s:

#comment1
.comm dovom, 10
.byte 12,15,28
aval:
movl %edx, 32(%edi)

asm3.s:

.section .text
.comm dovom, 10
aval:
movl $26, %eax

asm2.ld:
SECTIONS
{
	section5 0 :
	{
		*(.data);
		*(.bss);
	} = 0xffffffff

	.text 0x400000 :
	{
		*(.text);
		BYTE(0x57);
		BYTE(0x58);
		BYTE(0x59);
	} = 0xffffffff
}

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.
I wonder if anybody knows how to do.
Thank you.

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

* Re: How to create an image file with a specific size from a linked absolute code
  2011-05-16  6:39 How to create an image file with a specific size from a linked absolute code ali hagigat
@ 2011-05-17 15:11 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2011-05-17 15:11 UTC (permalink / raw)
  To: ali hagigat; +Cc: binutils

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


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

end of thread, other threads:[~2011-05-17 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-16  6:39 How to create an image file with a specific size from a linked absolute code ali hagigat
2011-05-17 15:11 ` Nick Clifton

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).