This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH i386] Allow sibcalls in no-PLT PIC
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: "H.J. Lu" <hjl dot tools at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Rich Felker <dalias at libc dot org>, Uros Bizjak <ubizjak at gmail dot com>
- Date: Mon, 18 May 2015 21:24:47 +0300 (MSK)
- Subject: Re: [PATCH i386] Allow sibcalls in no-PLT PIC
- Authentication-results: sourceware.org; auth=none
- References: <1430757479-14241-1-git-send-email-amonakov at ispras dot ru> <1430757479-14241-5-git-send-email-amonakov at ispras dot ru> <alpine dot LNX dot 2 dot 11 dot 1505151927170 dot 22867 at monopod dot intra dot ispras dot ru> <CAMe9rOq+gfTcCoY4AKefkZgysHr_XXOaCtOFWDro8OeT+mBUWQ at mail dot gmail dot com> <20150515194824 dot GB14415 at kam dot mff dot cuni dot cz>
On Fri, 15 May 2015, Jan Hubicka wrote:
> > >> With -fno-plt, we don't have to reject even direct calls as sibcall
> > >> candidates.
> > >>
> > >> This patch depends on '-fplt' flag that is introduced in another patch.
> > >>
> > >> This patch requires that with -fno-plt all sibcall candidates go through
> > >> prepare_call_address that transforms the call to a GOT lookup.
> > >>
> > >> OK?
> > >> * config/i386/i386.c (ix86_function_ok_for_sibcall): Check flag_plt.
> > >>
> > >> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> > >> index f29e053..b734350 100644
> > >> --- a/gcc/config/i386/i386.c
> > >> +++ b/gcc/config/i386/i386.c
> > >> @@ -5448,12 +5448,13 @@ ix86_function_ok_for_sibcall (tree decl, tree exp)
> > >> /* If we are generating position-independent code, we cannot sibcall
> > >> optimize any indirect call, or a direct call to a global function,
> > >> as the PLT requires %ebx be live. (Darwin does not have a PLT.) */
> > >> if (!TARGET_MACHO
> > >> && !TARGET_64BIT
> > >> && flag_pic
> > >> + && flag_plt
> > >> && (decl && !targetm.binds_local_p (decl)))
> > >> return false;
> > >>
> > >> /* If we need to align the outgoing stack, then sibcalling would
> > >> unalign the stack, which may break the called function. */
> > >> if (ix86_minimum_incoming_stack_boundary (true)
> > >>
> > I think it should be done via psABI change similar to
> > https://groups.google.com/forum/#!topic/x86-64-abi/n8GYMpqvBxI
> > which I have implemented on users/hjl/relax branch in binutils.
> OK, I am trying to understand how relax branch works and what difference it makes.
> As I underestand it, the main purpose is to be able to make relaxed call of
> call function
> that will, in 64bit mode, either result to RIP relative call with extra NOP just
> before the instruction if FUNCTION binds within the DSO or to indirect call through
> GOT bypassing the PLT. This saves overhead of PLT and increase every such call
> by extra NOP for no-LTO builds and even in LTO when the symbol is defined but
> interposable. This is actually really nice trick.
> Now this is about 32bit mode where explicit GOT pointer register is needed
> (how this work with large code model on x86-64?). It is needed by PLT, but I suppose
> to implement the same relaxation for 32bit it would need to use EBX to lookup the
> GOT pointer, too, so the check above would still be valid.
> The patches makes sense to be given that we support -fno-plt now.
After this message the discussion diverged in the direction of H.J.Lu's
proposed relaxation scheme involving new type of relocations.
I'm not clear if my patch is actually approved. I'd like to point out that it
doesn't clash with H.J.Lu's work. It improves codegen by allowing sibcalls in