public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC PATCH] Implementing ifunc target hook
@ 2012-12-26 12:15 Alexander Ivchenko
  2012-12-26 17:06 ` Joseph S. Myers
  2012-12-27 22:59 ` Maxim Kuvyrkov
  0 siblings, 2 replies; 16+ messages in thread
From: Alexander Ivchenko @ 2012-12-26 12:15 UTC (permalink / raw)
  To: gcc-patches, Joseph S. Myers, H.J. Lu, pavel.v.chupin,
	Sergey Ostanevich, Maxim Kuvyrkov

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

Hi,

Currently Android dynamic loader does not support indirect functions
(And I don't think that
it will someday). But there is no way for us to specify that for gcc,
and for example, tests like
gcc.dg/attr-ifunc-* are failing on android right now.
The attached patch is indended to add the target hook for indicating
the support of ifunc on target.


Thank you,
Alexander

[-- Attachment #2: disable_ifunc_for_android2.patch --]
[-- Type: application/octet-stream, Size: 6685 bytes --]

diff --git a/ChangeLog b/ChangeLog
index fc8f60b..61b733d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-12-26  Alexander Ivchenko  <alexander.ivchenko@intel.com>
+
+	* gcc/doc/tm.texi.in (TARGET_HAS_IFUNC): New target hook.
+	* gcc/doc/tm.texi: Regenerate
+	* gcc/defaults.h (TARGET_HAS_IFUNC): Defining it by default
+	as HAVE_GNU_INDIRECT_FUNCTION.
+	* gcc/config/linux-android.h (TARGET_HAS_IFUNC): Disable
+	support of indirect functions in android.
+	* gcc/config/i386/i386.c (ix86_get_function_versions_dispatcher):
+	Using TARGET_HAS_IFUNC hook instead of HAVE_GNU_INDIRECT_FUNCTION.
+	* gcc/varasm.c (do_assemble_alias): Likewise.
+
 2012-12-20  Matthias Klose  <doko@ubuntu.com>
 
 	* Makefile.def (install-target-libgfortran): Depend on
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index b466a4f..2af52bf 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -29146,7 +29146,7 @@ make_name (tree decl, const char *suffix, bool make_unique)
   return global_var_name;
 }
 
-#if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
+#if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
 
 /* Make a dispatcher declaration for the multi-versioned function DECL.
    Calls to DECL function will be replaced with calls to the dispatcher
@@ -29213,7 +29213,7 @@ ix86_get_function_versions_dispatcher (void *decl)
 
   tree dispatch_decl = NULL;
 
-#if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
+#if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
   struct cgraph_function_version_info *it_v = NULL;
   struct cgraph_node *dispatcher_node = NULL;
   struct cgraph_function_version_info *dispatcher_version_info = NULL;
@@ -29263,24 +29263,33 @@ ix86_get_function_versions_dispatcher (void *decl)
 
   default_node = default_version_info->this_node;
 
-#if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
-  /* Right now, the dispatching is done via ifunc.  */
-  dispatch_decl = make_dispatcher_decl (default_node->symbol.decl);
-
-  dispatcher_node = cgraph_get_create_node (dispatch_decl);
-  gcc_assert (dispatcher_node != NULL);
-  dispatcher_node->dispatcher_function = 1;
-  dispatcher_version_info
-    = insert_new_cgraph_node_version (dispatcher_node);
-  dispatcher_version_info->next = default_version_info;
-  dispatcher_node->local.finalized = 1;
-
-  /* Set the dispatcher for all the versions.  */
-  it_v = default_version_info;
-  while (it_v->next != NULL)
+#if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
+  if (TARGET_HAS_IFUNC)
+    {
+      /* Right now, the dispatching is done via ifunc.  */
+      dispatch_decl = make_dispatcher_decl (default_node->symbol.decl);
+
+      dispatcher_node = cgraph_get_create_node (dispatch_decl);
+      gcc_assert (dispatcher_node != NULL);
+      dispatcher_node->dispatcher_function = 1;
+      dispatcher_version_info
+	= insert_new_cgraph_node_version (dispatcher_node);
+      dispatcher_version_info->next = default_version_info;
+      dispatcher_node->local.finalized = 1;
+
+      /* Set the dispatcher for all the versions.  */
+      it_v = default_version_info;
+      while (it_v->next != NULL)
+	{
+	  it_v->dispatcher_resolver = dispatch_decl;
+	  it_v = it_v->next;
+	}
+    }
+  else
     {
-      it_v->dispatcher_resolver = dispatch_decl;
-      it_v = it_v->next;
+      error_at (DECL_SOURCE_LOCATION (default_node->symbol.decl),
+		"multiversioning needs ifunc which is not supported "
+		"on this target");
     }
 #else
   error_at (DECL_SOURCE_LOCATION (default_node->symbol.decl),
diff --git a/gcc/config/linux-android.h b/gcc/config/linux-android.h
index e74e261..f6f44f1 100644
--- a/gcc/config/linux-android.h
+++ b/gcc/config/linux-android.h
@@ -58,3 +58,6 @@
 
 #define ANDROID_ENDFILE_SPEC \
   "%{shared: crtend_so%O%s;: crtend_android%O%s}"
+
+#undef TARGET_HAS_IFUNC
+#define TARGET_HAS_IFUNC (!TARGET_ANDROID)
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 76909ab..2180a47 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -111,6 +111,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #endif
 #endif
 
+#ifndef TARGET_HAS_IFUNC
+#define TARGET_HAS_IFUNC HAVE_GNU_INDIRECT_FUNCTION
+#endif
+
 #ifndef IFUNC_ASM_TYPE
 #define IFUNC_ASM_TYPE "gnu_indirect_function"
 #endif
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 75aa867..1c8bc51 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -5847,6 +5847,12 @@ If @code{ASM_OUTPUT_DEF} is not available, the hook's default definition
 is @code{NULL}, which disables the use of section anchors altogether.
 @end deftypefn
 
+@defmac TARGET_HAS_IFUNC
+When this macro is nonzero, GCC will assume that target supports GNU indirect
+functions.  The support includes the assembler, linker and dynamic linker. The
+default value of this hook is defined as for the host machine.
+@end defmac
+
 @deftypefn {Target Hook} bool TARGET_USE_ANCHORS_FOR_SYMBOL_P (const_rtx @var{x})
 Return true if GCC should attempt to use anchors to access @code{SYMBOL_REF}
 @var{x}.  You can assume @samp{SYMBOL_REF_HAS_BLOCK_INFO_P (@var{x})} and
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 95fab18..e1646b8 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -5751,6 +5751,12 @@ If @code{ASM_OUTPUT_DEF} is not available, the hook's default definition
 is @code{NULL}, which disables the use of section anchors altogether.
 @end deftypefn
 
+@defmac TARGET_HAS_IFUNC
+When this macro is nonzero, GCC will assume that target supports GNU indirect
+functions.  The support includes the assembler, linker and dynamic linker. The
+default value of this hook is defined as for the host machine.
+@end defmac
+
 @hook TARGET_USE_ANCHORS_FOR_SYMBOL_P
 Return true if GCC should attempt to use anchors to access @code{SYMBOL_REF}
 @var{x}.  You can assume @samp{SYMBOL_REF_HAS_BLOCK_INFO_P (@var{x})} and
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 7d083fd..14be8fb 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -5489,10 +5489,14 @@ do_assemble_alias (tree decl, tree target)
     }
   if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
     {
-#if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
-      ASM_OUTPUT_TYPE_DIRECTIVE
-	(asm_out_file, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
-	 IFUNC_ASM_TYPE);
+#if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
+      if (TARGET_HAS_IFUNC)
+	ASM_OUTPUT_TYPE_DIRECTIVE
+	  (asm_out_file, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
+	   IFUNC_ASM_TYPE);
+      else
+	error_at (DECL_SOURCE_LOCATION (decl),
+		  "ifunc is not supported on this target");
 #else
       error_at (DECL_SOURCE_LOCATION (decl),
 		"ifunc is not supported in this configuration");

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-04-02 14:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-26 12:15 [RFC PATCH] Implementing ifunc target hook Alexander Ivchenko
2012-12-26 17:06 ` Joseph S. Myers
2012-12-27 22:59 ` Maxim Kuvyrkov
2012-12-28 12:30   ` Alexander Ivchenko
2013-01-02 23:08     ` Maxim Kuvyrkov
2013-01-09 11:24       ` Alexander Ivchenko
2013-01-10 23:24         ` Maxim Kuvyrkov
2013-01-14 15:55           ` Alexander Ivchenko
2013-01-15  4:13             ` Maxim Kuvyrkov
2013-03-26 15:15               ` Alexander Ivchenko
2013-03-26 20:59                 ` Maxim Kuvyrkov
2013-03-27  9:56                   ` Kirill Yukhin
2013-04-02 13:49                     ` Jakub Jelinek
2013-04-02 14:54                       ` Alexander Ivchenko
2013-04-02 15:04                         ` Jakub Jelinek
2013-04-02 15:06                           ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).