From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78044 invoked by alias); 4 May 2015 16:38:44 -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 77931 invoked by uid 89); 4 May 2015 16:38:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: smtp.ispras.ru Received: from smtp.ispras.ru (HELO smtp.ispras.ru) (83.149.199.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 May 2015 16:38:43 +0000 Received: from condor.intra.ispras.ru (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 516CF214F0; Mon, 4 May 2015 19:38:41 +0300 (MSK) Received: by condor.intra.ispras.ru (Postfix, from userid 23246) id 4DD1A1227575; Mon, 4 May 2015 19:38:41 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov , Rich Felker Subject: [PATCH] Expand PIC calls without PLT with -fno-plt Date: Mon, 04 May 2015 16:38:00 -0000 Message-Id: <1430757479-14241-6-git-send-email-amonakov@ispras.ru> In-Reply-To: <1430757479-14241-1-git-send-email-amonakov@ispras.ru> References: <1430757479-14241-1-git-send-email-amonakov@ispras.ru> X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00231.txt.bz2 This patch introduces option -fno-plt that allows to expand calls that would go via PLT to load the address of the function immediately at call site (which introduces a GOT load). Cover letter explains the motivation for this patch. New option documentation for invoke.texi is missing from the patch; if this is accepted I'll be happy to send a v2 with documentation added. * calls.c (prepare_call_address): Transform PLT call to GOT lookup and indirect call by forcing address into a pseudo with -fno-plt. * common.opt (flag_plt): New option. diff --git a/gcc/calls.c b/gcc/calls.c index 970415d..0c3b9aa 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -222,12 +222,18 @@ prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value, /* If we are using registers for parameters, force the function address into a register now. */ funexp = ((reg_parm_seen && targetm.small_register_classes_for_mode_p (FUNCTION_MODE)) ? force_not_mem (memory_address (FUNCTION_MODE, funexp)) : memory_address (FUNCTION_MODE, funexp)); + else if (flag_pic && !flag_plt && fndecl_or_type + && TREE_CODE (fndecl_or_type) == FUNCTION_DECL + && !targetm.binds_local_p (fndecl_or_type)) + { + funexp = force_reg (Pmode, funexp); + } else if (! sibcallp) { #ifndef NO_FUNCTION_CSE if (optimize && ! flag_no_function_cse) funexp = force_reg (Pmode, funexp); #endif diff --git a/gcc/common.opt b/gcc/common.opt index b49ac46..cd8b256 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1773,12 +1773,16 @@ Common Report Var(flag_pic,1) Negative(fpie) Generate position-independent code if possible (small mode) fpie Common Report Var(flag_pie,1) Negative(fPIC) Generate position-independent code for executables if possible (small mode) +fplt +Common Report Var(flag_plt) Init(1) +Use PLT for PIC calls (-fno-plt: load the address from GOT at call site) + fplugin= Common Joined RejectNegative Var(common_deferred_options) Defer Specify a plugin to load fplugin-arg- Common Joined RejectNegative Var(common_deferred_options) Defer