This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem creating PIC executable


Stefano Bonifazi <stefboombastic@gmail.com> writes:

>  I am reposting the previous problem, as after some investigation the
> problem is more clear:there is some error creating a PIC EXECUTABLE!
> Even when creating the simplest code:
> int main() {}
>
> compiling with "gcc -fPIC" and then linking with "gcc -Wl,-pie"
> produces non PIC code:
>
> checking all the linked object files (also those added by gcc) with
> "readelf -d myobjectfile | fgrep TEXT" all seem to be PIC as nothing
> is produced by the previous command.
> Oddly giving the command "readelf -d mypie_executable | fgrep TEXT" to
> my final 'PIC' output executable I get: "0x00000016 (TEXTREL) 0x0"
> Then if I try to load the file with QEMU-USER I get: "error while
> loading shared libraries: R_PPC_REL24 relocation at 0xb31f95a0 for
> symbol `__libc_start_main' out of range" !!!
>
> If I link with "-shared" all is fine and the library is PIC.. Also if
> I create a normal executable, or a normal executable relocated at
> linker time with "-Wl,-Ttext-segment=myaddress" all is fine..
> I think the linker goes crazy as I want a PIC executable not a library!
>
> I am creating the binaries using Debian 6 kernel 2.6.32.5 powerpc
> running in a qemu VM, with gcc 4.4.5-8, binutils 2.20.1 eglibc
> 2.11.2-10

This sounds like you are linking with startup files which were not
compiled with -fPIC.

If you use -v on your link line, you will see the complete set of object
files being used to create your executable.  Look at those executables
and make sure they are compiled with -fPIC.

Note that in some cases the gcc driver will use different startup files
if you use -fPIC on the link line, so make sure you are doing that.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]