[forwarded from http://bugs.debian.org/524176] Matthias gcc-4.5 with -flto doesn't work with -fPIC properly. Simple testcase: int entry(int a) { return bar(a)+1; } int bar(int a) { return a+4; } $ gcc-4.5 foo1.c -flto -fPIC -DPIC -c $ gcc-4.5 foo2.c -flto -fPIC -DPIC -c $ gcc-4.5 foo1.o foo2.o -flto -shared /usr/bin/ld: /tmp/ccmA7RCK.lto.o: relocation R_X86_64_PC32 against symbol `bar' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: ld returned 1 exit status This works however: $ gcc-4.5 foo1.o foo2.o -flto -shared -fPIC Now -fPIC is something libtool automatically adds, and I it doesn't add it at linktime (perhaps other build systems don't either). Could gcc's -flto see that all .o files involved in the link are -fPIC... and make the resulting file -fPIC too? Or at least it should see the -shared in the linker line, and automatically use -fPIC when -flto is used.
Subject: Re: New: -flto doesn't remember -fPIC This is done on purpose. The -fpic is needed on the link line too. This is a bug in libtool. Sent from my iPhone On Apr 5, 2010, at 6:47 PM, "debian-gcc at lists dot debian dot org" <gcc-bugzilla@gcc.gnu.org > wrote: > [forwarded from http://bugs.debian.org/524176] > > Matthias > > gcc-4.5 with -flto doesn't work with -fPIC properly. > > Simple testcase: > int entry(int a) > { > return bar(a)+1; > } > > int bar(int a) > { > return a+4; > } > > $ gcc-4.5 foo1.c -flto -fPIC -DPIC -c > $ gcc-4.5 foo2.c -flto -fPIC -DPIC -c > $ gcc-4.5 foo1.o foo2.o -flto -shared > /usr/bin/ld: /tmp/ccmA7RCK.lto.o: relocation R_X86_64_PC32 against > symbol `bar' > can not be used when making a shared object; recompile with -fPIC > /usr/bin/ld: final link failed: Bad value > collect2: ld returned 1 exit status > > This works however: > $ gcc-4.5 foo1.o foo2.o -flto -shared -fPIC > > Now -fPIC is something libtool automatically adds, and I it doesn't > add it at > linktime (perhaps other build systems don't either). > Could gcc's -flto see that all .o files involved in the link are - > fPIC... and > make the resulting file -fPIC too? > Or at least it should see the -shared in the linker line, and > automatically use > -fPIC when -flto is used. > > > -- > Summary: -flto doesn't remember -fPIC > Product: gcc > Version: 4.5.0 > Status: UNCONFIRMED > Severity: normal > Priority: P3 > Component: lto > AssignedTo: unassigned at gcc dot gnu dot org > ReportedBy: debian-gcc at lists dot debian dot org > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43659 >
GCC has code to do exactly this. Somebody needs to debug why it doesn't work.
The issue seems to still exist in 4.5.1. Does it have something to do with bug #40546? On Gentoo, at least following packages are affected: app-arch/bzip2-1.0.6-r1, dev-libs/libebml-1.0.0, media-libs/jpeg-6b-r9, media-libs/openjpeg-1.3-r3, media-sound/gsm-1.0.13, net-libs/libsrtp-1.4.4-r1
This was fixed on mainline by patch of mine http://gcc.gnu.org/ml/gcc-patches/2011-01/msg00210.html perhaps it can be backported.
(In reply to Jan Hubicka from comment #4) > This was fixed on mainline by patch of mine > http://gcc.gnu.org/ml/gcc-patches/2011-01/msg00210.html > perhaps it can be backported. Any of the branches this might have been backported to are now closed; closing this bug as FIXED then.