This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gomp4] Add tables generation


On 05/06/2014 05:32 PM, Ilya Verbin wrote:
On 05 Apr 17:22, Bernd Schmidt wrote:
Things seemed to work over here, but now I'm not certain whether the
__start_/__stop_ functionality is GNU ld specific? Maybe we should
just go back to the previous version of this patch which didn't try
to use this.

Bernd

This approach does not work with shared libraries.

The automatically inserted symbols have GLOBAL binding, therefore the
__start_/__stop_ from the executable overwrite the respective symbols in DSO.

Ok, I guess we should just go back to what we had previously. Here's what I intend to commit if there are no objections.


Bernd



Index: gcc/lto-wrapper.c
===================================================================
--- gcc/lto-wrapper.c	(revision 210170)
+++ gcc/lto-wrapper.c	(working copy)
@@ -66,7 +66,7 @@ static unsigned int nr;
 static char **input_names;
 static char **output_names;
 static char **offload_names;
-static const char *ompend;
+static const char *ompbegin, *ompend;
 static char *makefile;
 
 const char tool_name[] = "lto-wrapper";
@@ -554,30 +554,40 @@ copy_file (const char *dest, const char
     }
 }
 
-/* Find the crtompend.o file in LIBRARY_PATH, make a copy and store
-   the name of the copy in ompend.  */
+/* Find the omp_begin.o and omp_end.o files in LIBRARY_PATH, make copies
+   and store the names of the copies in ompbegin and ompend.  */
 
 static void
-find_ompend (void)
+find_ompbeginend (void)
 {
   char **paths;
   const char *library_path = getenv ("LIBRARY_PATH");
   if (library_path == NULL)
     return;
-  int n_paths = parse_env_var (library_path, &paths, "/crtompend.o");
+  int n_paths = parse_env_var (library_path, &paths, "/crtompbegin.o");
 
-  for (int i = 0; i < n_paths; i++)
+  int i;
+  for (i = 0; i < n_paths; i++)
     if (access_check (paths[i], R_OK) == 0)
       {
+	size_t len = strlen (paths[i]);
+	char *tmp = xstrdup (paths[i]);
+	strcpy (paths[i] + len - 7, "end.o");
+	if (access_check (paths[i], R_OK) != 0)
+	  fatal ("installation error, can't find crtompend.o");
 	/* The linker will delete the filenames we give it, so make
 	   copies.  */
-	const char *omptmp = make_temp_file (".o");
-	copy_file (omptmp, paths[i]);
-	ompend = omptmp;
+	const char *omptmp1 = make_temp_file (".o");
+	const char *omptmp2 = make_temp_file (".o");
+	copy_file (omptmp1, tmp);
+	ompbegin = omptmp1;
+	copy_file (omptmp2, paths[i]);
+	ompend = omptmp2;
+	free (tmp);
 	break;
       }
-  if (ompend == 0)
-    fatal ("installation error, can't find crtompend.o");
+  if (i == n_paths)
+    fatal ("installation error, can't find crtompbegin.o");
 
   free_array_of_ptrs ((void**) paths, n_paths);
 }
@@ -1073,7 +1083,7 @@ cont:
 	  compile_images_for_openmp_targets (argc, argv);
 	  if (offload_names)
 	    {
-	      find_ompend ();
+	      find_ompbeginend ();
 	      for (i = 0; offload_names[i]; i++)
 		{
 		  fputs (offload_names[i], stdout);
@@ -1082,6 +1092,11 @@ cont:
 	      free_array_of_ptrs ((void **)offload_names, i);
 	    }
 	}
+      if (ompbegin)
+	{
+	  fputs (ompbegin, stdout);
+	  putc ('\n', stdout);
+	}
 
       for (i = 0; i < nr; ++i)
 	{
Index: libgcc/Makefile.in
===================================================================
--- libgcc/Makefile.in	(revision 210170)
+++ libgcc/Makefile.in	(working copy)
@@ -975,6 +975,9 @@ crtbegin$(objext): $(srcdir)/crtstuff.c
 crtend$(objext): $(srcdir)/crtstuff.c
 	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
 
+crtompbegin$(objext): $(srcdir)/ompstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN
+
 crtompend$(objext): $(srcdir)/ompstuff.c
 	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
 
Index: libgcc/configure
===================================================================
--- libgcc/configure	(revision 210170)
+++ libgcc/configure	(working copy)
@@ -4397,7 +4397,7 @@ fi
 
 
 if test x$offload_targets != x; then
-  extra_parts="${extra_parts} crtompend.o"
+  extra_parts="${extra_parts} crtompbegin.o crtompend.o"
 fi
 
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
Index: libgcc/configure.ac
===================================================================
--- libgcc/configure.ac	(revision 210170)
+++ libgcc/configure.ac	(working copy)
@@ -336,7 +336,7 @@ AC_ARG_ENABLE(offload-targets,
 ], [enable_accelerator=no])
 AC_SUBST(enable_accelerator)
 if test x$offload_targets != x; then
-  extra_parts="${extra_parts} crtompend.o"
+  extra_parts="${extra_parts} crtompbegin.o crtompend.o"
 fi
 
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
Index: libgcc/ompstuff.c
===================================================================
--- libgcc/ompstuff.c	(revision 210170)
+++ libgcc/ompstuff.c	(working copy)
@@ -39,14 +39,35 @@ see the files COPYING3 and COPYING.RUNTI
 #include "tm.h"
 #include "libgcc_tm.h"
 
+#ifdef CRT_BEGIN
+
 #if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
-extern void __start___gnu_offload_funcs;
-extern void __stop___gnu_offload_funcs;
-extern void __start___gnu_offload_vars;
-extern void __stop___gnu_offload_vars;
+void *_omp_func_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (".offload_func_table_section"))) = { };
+void *_omp_var_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (".offload_var_table_section"))) = { };
+#endif
+
+#elif defined CRT_END
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_funcs_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (".offload_func_table_section"))) = { };
+void *_omp_vars_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (".offload_var_table_section"))) = { };
+extern void *_omp_func_table[];
+extern void *_omp_var_table[];
 void *__OPENMP_TARGET__[] __attribute__ ((__visibility__ ("hidden"))) =
 {
-  &__start___gnu_offload_funcs, &__stop___gnu_offload_funcs,
-  &__start___gnu_offload_vars, &__stop___gnu_offload_vars
+  &_omp_func_table, &_omp_funcs_end,
+  &_omp_var_table, &_omp_vars_end
 };
 #endif
+
+#else /* ! CRT_BEGIN && ! CRT_END */
+#error "One of CRT_BEGIN or CRT_END must be defined."
+#endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]