This is the mail archive of the
mailing list for the binutils project.
Re: linking question
Nick Clifton <firstname.lastname@example.org> writes:
> Hi Nick
> > I'm trying to link a symbol into my program and am having trouble.
> > The following code is from my crt0.S and the symbol _start is
> > declared. When my program is linked, ld does NOT place _start at the
> > specified location in the linker script.
> What location does it assign to the symbol ?
_start is assigned at 0x400, the right location in the linker script.
The code for start however DOES NOT reside at this address.
> What command line are you using to invoke the linker ?
> Symbols defined in linker scripts can be overrideen by definitions in
> incoming object files. So if you have _start in your crt0.o file then
> its definition (and location) will override the definition in the
> linker script.
> My suggestion - remove the definition of _start from the linker
> script, and just accept the position assigned to it by the linker when
> the link is performed. If, for some reason, you have to start
> executing code from a fixed address, (presumably 0x400 from your
> example), then insist that crt0.o is the first object file on the
> linker's command line.
This is what i'm doing now. I link crt0.o as the first obj file. I
have to put '.section .text' in to get the code linked in at 0x400.
* put any hardware init code here
So I guess specifying a symbol in the linker script and then in an
object file, doesn't mean that the symbol (with code) from the object
file wil be linked into the location specified in the linker script.
Thanks for all your help.
BTW: Are you in Cambridge, USA or UK? I'm in Cambridge USA.