From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86235 invoked by alias); 10 May 2015 16:37:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 86223 invoked by uid 89); 10 May 2015 16:37:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: atrey.karlin.mff.cuni.cz Received: from atrey.karlin.mff.cuni.cz (HELO atrey.karlin.mff.cuni.cz) (195.113.26.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 May 2015 16:37:56 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 4018) id 9577881FA7; Sun, 10 May 2015 18:37:54 +0200 (CEST) Date: Sun, 10 May 2015 16:37:00 -0000 From: Jan Hubicka To: Alexander Monakov Cc: gcc-patches@gcc.gnu.org, Rich Felker Subject: Re: [PATCH i386] PR65753: allow PIC tail calls via function pointers Message-ID: <20150510163753.GF9659@atrey.karlin.mff.cuni.cz> References: <1430757479-14241-1-git-send-email-amonakov@ispras.ru> <1430757479-14241-2-git-send-email-amonakov@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1430757479-14241-2-git-send-email-amonakov@ispras.ru> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00854.txt.bz2 > In the i386 backend, tailcalls are incorrectly disallowed in PIC mode for > calls via function pointers on the basis that indirect calls, like direct > calls, would go via PLT and thus require %ebx to point to GOT -- but that is > not true. Quoting Rich Felker who reported the bug, > > "For PLT slots in the non-PIE main executable, %ebx is not required at all. > PLT slots in PIE or shared libraries need %ebx, but a function pointer can > never evaluate to such a PLT slot; it always evaluates to the nominal address > of the function which is the same in all DSOs and therefore fundamentally > cannot depend on the address of the GOT in the calling DSO" > > As far as I can see it's simply a mistake that was there from day 1 (comment 4 > in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65753 points to original patch). > > Bootstrapped and regtested on 32-bit x86, OK for trunk? > (the comment before the condition will need to be adjusted too, i.e. > s/optimize any indirect call, or a direct call/optimize any direct call/ ) > > PR target/65753 > * config/i386/i386.c (ix86_function_ok_for_sibcall): Allow PIC sibcalls > via function pointers. > > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c > index 3263656..f29e053 100644 > --- a/gcc/config/i386/i386.c > +++ b/gcc/config/i386/i386.c > @@ -5448,13 +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 > - && (!decl || !targetm.binds_local_p (decl))) > + && (decl && !targetm.binds_local_p (decl))) You probably need to update comment here. I wonder what happens when we optimize indirect call to direct call to global function at RTL level? I suppose we are safe here, because at RTL level we explicitly represent if we refer to PLT entry or the functionaddress itself and we never optimize one to the other? Patch is OK if you make sure that this works and update the comment. Honza > 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) > < PREFERRED_STACK_BOUNDARY)