]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add crtoffloadtableS.o and use it [PR117851]
authorJakub Jelinek <jakub@redhat.com>
Sat, 30 Nov 2024 10:19:12 +0000 (11:19 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Jan 2025 09:00:43 +0000 (10:00 +0100)
Unlike crtoffload{begin,end}.o which just define some symbols at the start/end
of the various .gnu.offload* sections, crtoffloadtable.o contains
const void *const __OFFLOAD_TABLE__[]
  __attribute__ ((__visibility__ ("hidden"))) =
{
  &__offload_func_table, &__offload_funcs_end,
  &__offload_var_table, &__offload_vars_end,
  &__offload_ind_func_table, &__offload_ind_funcs_end,
};
The problem is that linking this into PIEs or shared libraries doesn't
work when it is compiled without -fpic/-fpie - __OFFLOAD_TABLE__ for non-PIC
code is put into .rodata section, but it really needs relocations, so for
PIC it should go into .data.rel.ro/.data.rel.ro.local.
As I think we don't want .data.rel.ro section in non-PIE binaries, this patch
follows the path of e.g. crtbegin.o vs. crtbeginS.o and adds crtoffloadtableS.o
next to crtoffloadtable.o, where crtoffloadtableS.o is compiled with -fpic.

2024-11-30  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/117851
gcc/
* lto-wrapper.cc (find_crtoffloadtable): Add PIE_OR_SHARED argument,
search for crtoffloadtableS.o rather than crtoffloadtable.o if
true.
(run_gcc): Add pie_or_shared variable.  If OPT_pie or OPT_shared or
OPT_static_pie is seen, set pie_or_shared to true, if OPT_no_pie is
seen, set pie_or_shared to false.  Pass it to find_crtoffloadtable.
libgcc/
* configure.ac (extra_parts): Add crtoffloadtableS.o.
* Makefile.in (crtoffloadtableS$(objext)): New goal.
* configure: Regenerated.

(cherry picked from commit f089ef880e385e2193237b1f53ec81dac4141680)

gcc/lto-wrapper.cc
libgcc/Makefile.in
libgcc/configure
libgcc/configure.ac

index 02579951569daed28ad8a8fc1d3458d9b757b3ff..c7bad4b61c255d0224e61b02d447d9cb3580f5b3 100644 (file)
@@ -1083,13 +1083,16 @@ copy_file (const char *dest, const char *src)
    the copy to the linker.  */
 
 static void
-find_crtoffloadtable (int save_temps, const char *dumppfx)
+find_crtoffloadtable (int save_temps, bool pie_or_shared, const char *dumppfx)
 {
   char **paths = NULL;
   const char *library_path = getenv ("LIBRARY_PATH");
   if (!library_path)
     return;
-  unsigned n_paths = parse_env_var (library_path, &paths, "/crtoffloadtable.o");
+  unsigned n_paths = parse_env_var (library_path, &paths,
+                                   pie_or_shared
+                                   ? "/crtoffloadtableS.o"
+                                   : "/crtoffloadtable.o");
 
   unsigned i;
   for (i = 0; i < n_paths; i++)
@@ -1108,7 +1111,8 @@ find_crtoffloadtable (int save_temps, const char *dumppfx)
       }
   if (i == n_paths)
     fatal_error (input_location,
-                "installation error, cannot find %<crtoffloadtable.o%>");
+                "installation error, cannot find %<crtoffloadtable%s.o%>",
+                pie_or_shared ? "S" : "");
 
   free_array_of_ptrs ((void **) paths, n_paths);
 }
@@ -1423,6 +1427,11 @@ run_gcc (unsigned argc, char *argv[])
   char **lto_argv, **ltoobj_argv;
   bool linker_output_rel = false;
   bool skip_debug = false;
+#ifdef ENABLE_DEFAULT_PIE
+  bool pie_or_shared = true;
+#else
+  bool pie_or_shared = false;
+#endif
   const char *incoming_dumppfx = dumppfx = NULL;
   static char current_dir[] = { '.', DIR_SEPARATOR, '\0' };
 
@@ -1590,6 +1599,16 @@ run_gcc (unsigned argc, char *argv[])
          diagnostic_color_init (global_dc, option->value);
          break;
 
+       case OPT_pie:
+       case OPT_shared:
+       case OPT_static_pie:
+         pie_or_shared = true;
+         break;
+
+       case OPT_no_pie:
+         pie_or_shared = false;
+         break;
+
        default:
          break;
        }
@@ -1798,7 +1817,7 @@ cont1:
 
       if (offload_names)
        {
-         find_crtoffloadtable (save_temps, dumppfx);
+         find_crtoffloadtable (save_temps, pie_or_shared, dumppfx);
          for (i = 0; offload_names[i]; i++)
            printf ("%s\n", offload_names[i]);
          free_array_of_ptrs ((void **) offload_names, i);
index 0e46e9ef76863aaee3984a489997ee7b42a22030..5d0195bdfe90a0026783e279f6ce2733982ed7e6 100644 (file)
@@ -1060,6 +1060,9 @@ crtoffloadend$(objext): $(srcdir)/offloadstuff.c
 
 crtoffloadtable$(objext): $(srcdir)/offloadstuff.c
        $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_TABLE
+
+crtoffloadtableS$(objext): $(srcdir)/offloadstuff.c
+       $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $< -DCRT_TABLE
 endif
 
 ifeq ($(enable_vtable_verify),yes)
index cff1eff962566abcf8e2e1d228f3614b92e9dbd1..23cc5753bac4211eaa27dbd6c94fa252381cd78f 100755 (executable)
@@ -5326,7 +5326,8 @@ fi
 
 
 if test x"$enable_offload_targets" != x; then
-  extra_parts="${extra_parts} crtoffloadbegin.o crtoffloadend.o crtoffloadtable.o"
+  extra_parts="${extra_parts} crtoffloadbegin.o crtoffloadend.o"
+  extra_parts="${extra_parts} crtoffloadtable.o crtoffloadtableS.o"
 fi
 
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
index 4e8c036990f040989951f7d73e5e178d7b837a5f..bbe34cb7fb16bd916cbd02a51726ba81f43dabcb 100644 (file)
@@ -506,7 +506,8 @@ AC_SUBST(accel_dir_suffix)
 AC_SUBST(real_host_noncanonical)
 
 if test x"$enable_offload_targets" != x; then
-  extra_parts="${extra_parts} crtoffloadbegin.o crtoffloadend.o crtoffloadtable.o"
+  extra_parts="${extra_parts} crtoffloadbegin.o crtoffloadend.o"
+  extra_parts="${extra_parts} crtoffloadtable.o crtoffloadtableS.o"
 fi
 
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.