[Milkymist-devel] [uClinux-dev] uClinux/FDPIC loader on LatticeMico32/Milkymist

Sébastien Bourdeauducq sebastien.bourdeauducq at lekernel.net
Wed Feb 3 05:06:57 PST 2010


Hi,

On Wednesday 03 February 2010 13:09:21 Jon Beniston wrote:
> If you compile code with -fPIC, then it should load all pointers via the
> GOT, so you only have 32-bit relocations in the .got and no relocations in
> the .text section.

Ok. Thanks for that tip :)

But it there is another problem. Take the following code for example:
struct relocfail {
        int toto;
        char *tata;
};

static char test[] = "azerty";

struct relocfail foobar = {
        32,
        test
};

int main(int argc, char *argv[])
{
        while(1) printf("hello world %d %s\n", foobar.toto, foobar.tata);
        return 0;
}

This is the assembly code for main() generated by GCC 4.2.1 (this is from 
lm32-linux-gcc -o reloc -fPIC test_reloc.c):
     138:	37 9c ff f0 	addi sp,sp,-16
     13c:	5b 9b 00 08 	sw (sp+8),fp
     140:	5b 9d 00 04 	sw (sp+4),ra
     144:	34 1b 00 10 	mvi fp,16
     148:	b7 7c d8 00 	add fp,fp,sp
     14c:	5b 61 00 00 	sw (fp+0),r1
     150:	5b 62 ff fc 	sw (fp+-4),r2
     154:	2b 41 00 10 	lw r1,16
     158:	28 22 00 00 	lw r2,(r1+0)
     15c:	2b 41 00 10 	lw r1,16
     160:	28 23 00 04 	lw r3,(r1+4)
     164:	2b 41 00 0c 	lw r1,12
     168:	f8 00 00 02 	calli 170 <__GI_printf>
     16c:	e3 ff ff fa 	bi 154 <main+0x1c>

So, r3 gets the value straight from what is in the memory at the address where 
the "tata" field of the structure is. Therefore I guess that GCC assumes that 
the pointer field of the structure was relocated. There is no information in 
the GOT for this:

00047534 <test>:
   47534:	61 7a 65 72
   47538:	74 79 00 00

0004753c <foobar>:
   4753c:	00 00 00 20
   47540:	00 04 75 34 <== unrelocated pointer value

Disassembly of section .got:

00047838 <_GLOBAL_OFFSET_TABLE_>:
	...
   47844:	00 00 6f 70
   47848:	00 04 75 3c
Disassembly of section .bss:
...

So, the FLAT linker would need to emit a 32-bit .data relocation concerning 
only the field "tata" of the structure? Am I right?

Thanks for your help,
Sébastien


More information about the Devel mailing list