GCC, changing base address?

Programming, for all ages and all languages.
Post Reply
User avatar
Artlav
Member
Member
Posts: 178
Joined: Fri Aug 21, 2009 5:54 am
Location: Moscow, Russia
Contact:

GCC, changing base address?

Post by Artlav »

Hello.
The problem is, how can i change base address at which gcc generates the executable?

It is set to generate it at 0x0, i need it to work if it's loaded at 0x1000.

I tried linker options, like -Wl,--section-start=.text=0x1000, that produced a mess.
I tried putting .org 0x1000,0 at start of crt0.S. That kinda worked, but the first 0x1000 bytes are filled with zeros, which is unacceptable (what if base is 0x80000000?).

What is the proper way of doing it?

Changing it in the toolchain sources is not an option, since i want to be able to build with base of 0x0 as well.
There is probably a simple linker option for that, but LD is too well documented to even hope of finding it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GCC, changing base address?

Post by Combuster »

Use a linker script, just as you would with building an ELF kernel. There are several examples of that on the wiki.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply