Alan Modra <amo...@gmail.com> wrote on 2010/10/11 14:58:45: > > On Sun, Oct 10, 2010 at 11:20:06AM +0200, Joakim Tjernlund wrote: > > Now I have had a closer look at this and it looks much like -fpic > > on ppc32, you still use the GOT/TOC to load the address where the data is. > > No, with ppc64 -mcmodel=medium you use the GOT/TOC pointer plus an > offset to address local data.
I guess I have to look closer then. > > > I was looking for true %pc relative addressing of data. I guess this is > > really > > hard on PowerPC? > > Yes, PowerPC lacks pc-relative instructions. > > > I am not sure this is all it takes to make -fpic to work with -mrelocatable, > > any ideas? > > You might be lucky. With -mrelocatable, .got2 only contains > addresses. No other constants. So a simple run-time loader can > relocate the entire .got2 section, plus those locations specified in > .fixup. You'll have to make sure gcc does the same for .got, and your > run-time loader will need to be modified to handle .got (watch out for > the .got header!). yes, almost there. I have this reloc routine: #define GOT(NAME) NAME ## @got (r30) * Adjust got pointers, no need to check for 0, this code * already puts a few entries in the table. */ li r0,__got_entr...@sectoff@l la r3,GOT(_GOT_TABLE_) lwz r11,GOT(_GOT_TABLE_) mtctr r0 sub r11,r3,r11 addi r3,r3,-4 1: lwzu r0,4(r3) cmpwi r0,0 beq- 2f add r0,r0,r11 stw r0,0(r3) 2: bdnz 1b Linker script: .reloc : { _GOT_TABLE_ = .; *(.got) _GOT2_TABLE_ = .; *(.got2) _FIXUP_TABLE_ = .; *(.fixup) } The above depends on that the first entry in the got to which _GOT_TABLE_ points, has an entry to itself. Using -fPIC I could create such an entry but I cannot find a way to do it using -fpic. Any ideas? Jocke