This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Expand PIC calls without PLT with -fno-plt
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Rich Felker <dalias at libc dot org>
- Cc: Alexander Monakov <amonakov at ispras dot ru>, Jakub Jelinek <jakub at redhat dot com>, Jeff Law <law at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 6 May 2015 12:24:15 -0700
- Subject: Re: [PATCH] Expand PIC calls without PLT with -fno-plt
- Authentication-results: sourceware.org; auth=none
- References: <5547AF7C dot 9030500 at redhat dot com> <alpine dot LNX dot 2 dot 11 dot 1505061730460 dot 22867 at monopod dot intra dot ispras dot ru> <20150506154554 dot GZ1751 at tucnak dot redhat dot com> <alpine dot LNX dot 2 dot 11 dot 1505061939240 dot 22867 at monopod dot intra dot ispras dot ru> <20150506173521 dot GJ17573 at brightrain dot aerifal dot cx> <CAMe9rOqDZyY-UTb8xW4OM7ZbW7p_W5w7Vk7Pbh07vAechqj2Nw at mail dot gmail dot com> <20150506183735 dot GK17573 at brightrain dot aerifal dot cx> <CAMe9rOoxbn33SwXCmHcwYL87t4_JgxgHtT6HSECtFguyLQpxKw at mail dot gmail dot com> <20150506190128 dot GL17573 at brightrain dot aerifal dot cx> <CAMe9rOokRzVkeaaeXYwFhnPLjnfKw+QUiJC1nEgGM05fDy-zMQ at mail dot gmail dot com> <20150506191750 dot GM17573 at brightrain dot aerifal dot cx>
On Wed, May 6, 2015 at 12:17 PM, Rich Felker <email@example.com> wrote:
> On Wed, May 06, 2015 at 12:05:20PM -0700, H.J. Lu wrote:
>> >> -Bsymbolic will bind all references to local definitions in shared libraries,
>> >> with and without visibility, weak or non-weak. Compiler can use it
>> >> in binds_tls_local_p and we can generate much better codes in shared
>> >> libraries.
>> > Yes, I'm aware of what it does. But at compile-time the compiler can't
>> > know whether the referenced symbol will be defined in the same DSO
>> > unless this is visibility annotation telling it. Even when linking a
>> > shared library using -Bsymbolic, the library code can still make calls
>> > (or data references) to symbols in other DSOs.
>> Even without LTO, -fsymbolic -fPIC will generate better codes for
>> int glob_a = 1;
>> int foo ()
>> return glob_a;
> I see how this case is improved, but it depends on the dubious (and
> undocumented?) behavior of -Bsymbolic breaking copy relocations.
-Bsymbolic breaks copy relocations, independent of compiler.
However, we can pass -fsymbolic when building PIE to avoid
copy relocation. With -fsymbolic -fPIE -pie -flto, we can generate
direct reference for locally defined symbol.
>> int glob_a (void)
>> return -1;
>> int foo ()
>> return glob_a ();
> I don't see how this case is improved unless GCC is failing to
> consider strong definitions in the same TU as locally-binding. If this
> is the case, is there a reason for that behavior? IMO it's wrong.
glob_a is a strong definition. If you have another strong definition,
you will get a linker error.