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