how to tell ld not to pad the file?

Programming, for all ages and all languages.
Post Reply
User avatar
Luis
Member
Member
Posts: 39
Joined: Sat Feb 16, 2013 11:19 am

how to tell ld not to pad the file?

Post by Luis »

Hi,

I want to set different virtual memory addresses for different sections as you can see in the example code but as I do that the file gets padded with 0s between addresses. I've been trying to find a solution from barebones tutorial, linker script wiki, this forum and ld manual but I can't.

ld does: vaddress1 - 0x7C00, file_offset1: 0x7C00, vaddress2: 0x80000, file_offset2: 0x80000
I want: vaddress1 - 0x7C00, file_offset1: header_size, vaddress2: 0x80000, file_offset2: header_size+section1_size

There has to be a way to force ld to have different virtual addresses and file offsets.

Note: loader.o is assembled from fasm with a couple of org directives.

Code: Select all

start = 0x7C00;
ENTRY (start)
OUTPUT_FORMAT (elf64-x86-64)

SECTIONS
{
	.loader (0x7C00) : {
		*(.flat)
	}
	
	. = 0x80000;
	.kernel : {
		*(.text)
		*(.eh_frame)
	}
}
Cheers,
Luís
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: how to tell ld not to pad the file?

Post by Owen »

Sure there is. Read the Binutils manpages.

Hint: AT(x).
User avatar
Luis
Member
Member
Posts: 39
Joined: Sat Feb 16, 2013 11:19 am

Re: how to tell ld not to pad the file?

Post by Luis »

Sorry I still have no clue about what I am missing.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: how to tell ld not to pad the file?

Post by Nable »

User avatar
Luis
Member
Member
Posts: 39
Joined: Sat Feb 16, 2013 11:19 am

Re: how to tell ld not to pad the file?

Post by Luis »

Thanks!!! I guess I must be blind. I've been at that page and missed the AT. It works only if I change output format to binary. Elf format with AT still makes big files. Anyway that's ok bebause I don't really use elf to load kernel, I just use it sometimes to be able to objdump and see the sections as objdump doesn't work with binary format.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: how to tell ld not to pad the file?

Post by xenos »

You might also need a linker option such as -z max-page-size=0x1000 when linking your ELF kernel - see also here.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: how to tell ld not to pad the file?

Post by sortie »

Don't combine your bootloader and the actual x86_64 kernel into the same binary.
User avatar
Luis
Member
Member
Posts: 39
Joined: Sat Feb 16, 2013 11:19 am

Re: how to tell ld not to pad the file?

Post by Luis »

sortie wrote:Don't combine your bootloader and the actual x86_64 kernel into the same binary.
Too late already done. Is there a good reason why I shouldn't? It's working fine as it is.
Post Reply