Detailed description of -pic -PIC and -relocatable using ppc tools

Frank Haverkamp f.haverkamp@web.de
Tue Feb 4 14:34:00 GMT 2003


Hi,

I am using the gnu tools gcc, as, ld, ... to write embedded powerpc programs. I am doing experiments
with code relocation and therefore looking for a description of options like -relocatable, -pic, ... more
detailed than the manual page itself.

During my experiments I already found out much. I am using -relocatable and I get a .got2 and .fixup 
section which I modifiy when loading my program to a different location in memory. Due to assembler
code studies, I think that I understand the way gcc uses to find the global offset table (.got2 and .fixup)
to get the correct address of the variables. But there are still questions left and I would be glad if
somebody can point me to some sources of documentation regarding this topic.

One open issue, I observe, is the following:

I declared 

static void *ptr = my_func;

and printed later in my program which I have already moved to a different memory location
(adopting .got2 and .fixup sections):

void foo()
{
    printf("ptr at %p is %p my_func is\n", &ptr, ptr, my_func);
}

I am getting a result like this:

ptr at 0x03200042 is 0xfff00222 my_func is 0x03200222

which puzzels me since the code retrieved the location of the ptr correctly but does not do the
relocation of the ptr itself. I am wondering if that is intentionally made like this, or if I missed
to modifiy additional tables needed for correct relocation. Before I start diving even more into
dissassembly I am trying to get help here. Maybe somebody can give me a hint or a pointer 
to more detailed documentation.

Thanks a lot!

Frank

--
Frank Haverkamp
f.haverkamp@web.de
______________________________________________________________________________
Werden Sie kreativ! Jetzt HTML-Mails nicht nur schreiben - nein -
GESTALTEN, bei WEB.DE FreeMail! http://freemail.web.de/features/?mc=021141



More information about the Gcc mailing list