it an indirect call. */
if (flag_pic
&& GET_CODE (addr) == SYMBOL_REF
- && !SYMBOL_REF_LOCAL_P (addr))
+ && ix86_call_use_plt_p (addr))
{
if (flag_plt
&& (SYMBOL_REF_DECL (addr) == NULL_TREE
extern void ix86_expand_sse_unpack (rtx, rtx, bool, bool);
extern bool ix86_expand_int_addcc (rtx[]);
extern rtx_insn *ix86_expand_call (rtx, rtx, rtx, rtx, rtx, bool);
+extern bool ix86_call_use_plt_p (rtx);
extern void ix86_split_call_vzeroupper (rtx, rtx);
extern void x86_initialize_trampoline (rtx, rtx, rtx);
extern rtx ix86_zero_extend_to_Pmode (rtx);
assemble_name (file, name);
}
if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
- && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
+ && code == 'P' && ix86_call_use_plt_p (x))
fputs ("@PLT", file);
break;
return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
}
+/* Return true if the function is called via PLT. */
+
+bool
+ix86_call_use_plt_p (rtx call_op)
+{
+ if (SYMBOL_REF_LOCAL_P (call_op))
+ {
+ if (SYMBOL_REF_DECL (call_op))
+ {
+ /* NB: All ifunc functions must be called via PLT. */
+ cgraph_node *node
+ = cgraph_node::get (SYMBOL_REF_DECL (call_op));
+ if (node && node->ifunc_resolver)
+ return true;
+ }
+ return false;
+ }
+ return true;
+}
+
/* Return true if the function being called was marked with attribute
"noplt" or using -fno-plt and we are compiling for non-PIC. We need
to handle the non-PIC case in the backend because there is no easy
#define TARGET_GET_MULTILIB_ABI_NAME \
ix86_get_multilib_abi_name
+#undef TARGET_IFUNC_REF_LOCAL_OK
+#define TARGET_IFUNC_REF_LOCAL_OK hook_bool_void_true
+
static bool ix86_libc_has_fast_function (int fcode ATTRIBUTE_UNUSED)
{
#ifdef OPTION_GLIBC
The default value of this hook is based on target's libc.
@end deftypefn
+@deftypefn {Target Hook} bool TARGET_IFUNC_REF_LOCAL_OK (void)
+Return true if it is OK to reference indirect function resolvers
+locally. The default is to return false.
+@end deftypefn
+
@deftypefn {Target Hook} {unsigned int} TARGET_ATOMIC_ALIGN_FOR_MODE (machine_mode @var{mode})
If defined, this function returns an appropriate alignment in bits for an
atomic object of machine_mode @var{mode}. If 0 is returned then the
@hook TARGET_HAS_IFUNC_P
+@hook TARGET_IFUNC_REF_LOCAL_OK
+
@hook TARGET_ATOMIC_ALIGN_FOR_MODE
@hook TARGET_ATOMIC_ASSIGN_EXPAND_FENV
bool, (void),
default_has_ifunc_p)
+/* True if it is OK to reference indirect function resolvers locally. */
+DEFHOOK
+(ifunc_ref_local_ok,
+ "Return true if it is OK to reference indirect function resolvers\n\
+locally. The default is to return false.",
+ bool, (void),
+ hook_bool_void_false)
+
/* True if it is OK to do sibling call optimization for the specified
call expression EXP. DECL will be the called function, or NULL if
this is an indirect call. */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O2 -fpic" } */
+
+static void
+my_foo (void)
+{
+}
+
+static void (*resolve_foo (void)) (void)
+{
+ return my_foo;
+}
+
+extern void foo (void) __attribute__((ifunc("resolve_foo"), visibility("hidden")));
+
+void *
+bar(void)
+{
+ return foo;
+}
+
+/* { dg-final { scan-assembler {leal[ \t]foo@GOTOFF\(%[^,]*\),[ \t]%eax} { target ia32 } } } */
+/* { dg-final { scan-assembler {leaq[ \t]foo\(%rip\),[ \t]%rax} { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-not "foo@GOT\\\(" { target ia32 } } } */
+/* { dg-final { scan-assembler-not "foo@GOTPCREL\\\(" { target { ! ia32 } } } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O2 -fpic" } */
+
+static void
+my_foo (void)
+{
+}
+
+static void (*resolve_foo (void)) (void)
+{
+ return my_foo;
+}
+
+static void foo (void) __attribute__((ifunc("resolve_foo")));
+
+void *
+bar(void)
+{
+ return foo;
+}
+
+/* { dg-final { scan-assembler {leal[ \t]foo@GOTOFF\(%[^,]*\),[ \t]%eax} { target ia32 } } } */
+/* { dg-final { scan-assembler {leaq[ \t]foo\(%rip\),[ \t]%rax} { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-not "foo@GOT\\\(" { target ia32 } } } */
+/* { dg-final { scan-assembler-not "foo@GOTPCREL\\\(" { target { ! ia32 } } } } */
FIXME: We can resolve the weakref case more curefuly by looking at the
weakref alias. */
if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))
- || (TREE_CODE (exp) == FUNCTION_DECL
+ || (!targetm.ifunc_ref_local_ok ()
+ && TREE_CODE (exp) == FUNCTION_DECL
&& cgraph_node::get (exp)
&& cgraph_node::get (exp)->ifunc_resolver))
return false;