Page 1 of 1

ld: How to padd output file to a specified size with zeros?

Posted: Wed Mar 18, 2009 2:50 pm
by sebihepp
Hi,

How can I tell my linker i586-elf-ld to fill the output file to a specified size with zeroes?
There's my linker script:

Code: Select all

ENTRY(start)
INPUT(bootloader.bin boot.bin)
OUTPUT(reserved.bin)
OUTPUT_FORMAT(binary)
MEMORY
{
	FLOPPY : ORIGIN = 0x10000, LENGTH = 1474560-512
}
SECTIONS
{
	.text :
	{
		*(.text)
		*(.data)
		*(.bss)
	} >FLOPPY =0x00
}
TIA
Sebihepp

Re: ld: How to padd output file to a specified size with zeros?

Posted: Wed Mar 18, 2009 2:54 pm
by skyking
My script for the boot sector might help (although I don't pad zeros):

Code: Select all

OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(start)

SECTIONS 
{
	. = 0x000000;
	.code				: 		ALIGN(0x200)
	{ 
		KEEP(*(.head)) 
		*(.text .text.*)
		*(.data .data.*)
		__code_end = .;
		. = ALIGN(2);
		FILL(0x55AA55AA);
		. = ALIGN(0x200);
	} 
	.bss				: 		ALIGN(0x200)
	{
		__bss_beg = .;
		KEEP(*(.bss .bss.*))
		__bss_end = .;
	}
}

Re: ld: How to padd output file to a specified size with zeros?

Posted: Thu Mar 19, 2009 5:21 am
by sebihepp
Thanks! Now it works.
Here's my linker script:

Code: Select all

ENTRY(start)
INPUT(bootloader.bin boot.bin)
OUTPUT(reserved.bin)
OUTPUT_FORMAT(binary)

SECTIONS
{
	.text :
	{
		*(.text)
		*(.data)
		*(.bss)
		FILL(0x00);
		. = ALIGN(1474560-512);
	}
}