Position independent m68k code
gene.smith at sea.siemens.com
Fri May 14 17:22:55 UTC 2004
Joel Sherrill wrote, On 5/14/2004 9:13 AM:
> geneSmith wrote:
>> This does not apply directly to rtems but I am using the m68k-rtems-*
>> toolchain but for running under an non-rtems system.
>> The non-rtems embedded system allows you to create a C program which
>> it can run. It requires that the C program be written in PC relative
>> (i.e., position independent) m68k code. m68k-rtems-gcc supports this,
>> as best I can tell, using the -fpic option.
>> When I use the -fpic option and link with m68k-rtems-ld I get section
>> .got and .got.plt. Does anyone on the rtems list know anything about
>> how I should use or possibly initialize these? (Most of what I can
>> find on Global Offset Table and Procedure Linkage Table applies to
>> runtime dynamic linking which the non-rtems system definitely does not
> I always come away from a discussion of sections a bit fuzzy headed.
> The definitive answer is always going to come from binutils.
> This post may clarify it some.
> In general, I follow the pattern in the generic linker scripts
> in $prefix/lib/ldscripts when dealing with sections.
Thanks Joel. I actually found something on the crossgcc list from 1999.
I ended up ignoring the .got.plt and just locating and correcting the
.got section. This show what I found (but with one small bug correction):
This describes almost exactly what I was looking for.
Thanks you Olivier Carmona!
A minor bug in O. Carmona's code. When used, a2 is
a positive offset. With original code it was negative. Made it positive
with 3 lines labeled new*: below.
/* Load the address relative to the PC */
/* Load the address given by the linker */
/* Then find the offset */
beq L1 /* Null Offset ? */
new1: move.l a2,d1
new2: neg.l d1
new3: move.l d1,a2
/* Add the offset to all of the Global Offset Table */
move.l #gotsize,d1 /* gostize : linker variable */
L0: subq.l #4,d1
blt.b L1 /* End of GOT ? */
movea.l (a5,d1.l),a3 /* Read the GOT */
adda.l a2,a3 /* Add the offset */
move.l a3,(a5,d1.l) /* Write back in the GOT */
More information about the users