Page 1 of 1

end of binary

Posted: Wed Jan 19, 2011 7:34 pm
by MDM
Hello, I was wondering if there is a way I can specify a label to be at the end of a binary after linking. I haven't been able to find anything directly associated with ld, but I thought perhaps there was a trick I was overlooking or some such thing. Thanks for the help.

Re: end of binary

Posted: Wed Jan 19, 2011 7:45 pm
by b.zaar
You can use a linker script with LD. This is the one I've been using for a kernel.

Code: Select all

SECTIONS {
	.text 0xc0100000 :{
		_kstart = .;
		_text = .;
		*(.text);
		_etext = .;
	}
	.data ALIGN(0x1000):{
		_data = .;
		*(.data);
		_edata = .;
	}
	.bss ALIGN(0x1000):{
		_bss = .;
		*(COMMON);
		*(.bss);
		_ebss = .;
	}
	_kend = .;
}
You then define any labels like _kstart & _kend as external and you can use the values as memory references.

Re: end of binary

Posted: Wed Jan 19, 2011 8:15 pm
by TylerH
Do you use a linker script? You should. The solution to your problem can be solved using LD's "." variable. At any point in the script, "." has the value of the current virtual address. This is useful for many reasons, one being that you can assign its value to variables.

Re: end of binary

Posted: Wed Jan 19, 2011 8:38 pm
by MDM
Okay, got switched over to the script system and got everything up and running. Thanks guys, was very helpful :D

- Now in kernel space