Problem creating PIC executable

Ian Lance Taylor iant@google.com
Tue Feb 22 04:15:00 GMT 2011


Stefano Bonifazi <stefboombastic@gmail.com> writes:

>> When linking with -fPIC I would normally expect the gcc driver to use
>> crtbeginS.o rather than crtbegin.o.  See if crtbegin.o in particular was
>> compiled without -fPIC.
>>
> readelf -d /usr/lib/gcc/powerpc-linux-gnu/4.4.5/crtbegin.o|fgrep TEXT
>
> does not output anything, and as far as I understood it means
> crtbegin.o is PIC

readelf -d just dumps the .dynamic section.  That is only meaningful for
an object file or a shared library.  It doesn't tell you anything about
a .o file.  The only way to tell whether a .o file was compiled with
-fPIC is to examine the relocations via readelf -r.

>>> the same command on the final executable gives:
>>>
>>>> 0x00000016 (TEXTREL)   0x0
>> It may help to see what relocations are in the text or data segments, to
>> see why the TEXTREL entry is being added.
> Outputs of
> "objdump --dynamic-reloc bin/ppc-test", "objdump --dynamic-syms
> bin/ppc-test", "objdump --syms bin/ppc-test",
> "objdump --full-contents bin/ppc-test" and several readelf dumps are here:
>
> <http://cid-9d0dd0f6c6e22fe8.office.live.com/browse.aspx/Pubblic/Developing/master-degree-project>http://cid-9d0dd0f6c6e22fe8.office.live.com/browse.aspx/Public/Developing/master-degree-project

I see a lot of R_PPC_ADDR16_HA/R_PPC_ADDR16_LO pairs in the dynamic
relocs.  If you use -fPIC you should not see those relocs, except
perhaps against some magic symbols which is not what is happening here.
So I suspect that those relocs are coming from crtbegin.o.  If you run
readelf -r on crtbegin.o, and you see those relocs, that will suggest
that crtbegin.o was not compiled with -fPIC.

Ian



More information about the Gcc-help mailing list