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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

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

Post 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
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

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

Post 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 = .;
	}
}
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

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

Post 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);
	}
}
Post Reply