Bug 43659 - -flto doesn't remember -fPIC
Summary: -flto doesn't remember -fPIC
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-06 01:47 UTC by Debian GCC Maintainers
Modified: 2024-08-14 13:19 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.0
Known to fail:
Last reconfirmed: 2011-01-08 19:54:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2010-04-06 01:47:15 UTC
[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.
Comment 1 pinskia@gmail.com 2010-04-06 03:01:46 UTC
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
>
Comment 2 Richard Biener 2010-04-06 08:57:56 UTC
GCC has code to do exactly this.  Somebody needs to debug why it doesn't work.
Comment 3 heri+gcc 2010-11-30 10:05:17 UTC
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
Comment 4 Jan Hubicka 2011-01-08 19:54:57 UTC
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.
Comment 5 Eric Gallager 2018-03-11 19:04:06 UTC
(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.