end of binary

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
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

end of binary

Post 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.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: end of binary

Post 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.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: end of binary

Post 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.
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

Re: end of binary

Post 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
Post Reply