This patch constifies the objects involved in describing the host-side offloading information. Probably won't make much difference in executable layout because of relocations, but at least allows them to be put into .rel.rodata, and makes it clear the objects aren't modified.

ok for trunk?

nathan
2015-07-15  Nathan Sidwell  <nat...@codesourcery.com>

	gcc/
	* config/nvptx/mkoffload.c (process): Constify host data.
	* config/i386/intelmic-mkoffload.c (generate_target_descr_file):
	Constify host data.
	(generate_host_descr_file): Likewise.

	libgomp/
	* target.c (struct_offload_image_descr): Constify host_table.
	(gomp_offload_image_to_device): Likewise.
	(GOMP_offload_register, GOMP_offload_unregister): Likewise.

	libgcc/
	* offloadstuff.c: Constify host data.

Index: gcc/config/nvptx/mkoffload.c
===================================================================
--- gcc/config/nvptx/mkoffload.c	(revision 225851)
+++ gcc/config/nvptx/mkoffload.c	(working copy)
@@ -870,12 +870,13 @@ process (FILE *in, FILE *out)
   fprintf (out, "#ifdef __cplusplus\n"
 	   "extern \"C\" {\n"
 	   "#endif\n");
-  fprintf (out, "extern void GOMP_offload_register (void *, int, void *);\n");
+  fprintf (out, "extern void GOMP_offload_register"
+	   " (const void *, int, void *);\n");
   fprintf (out, "#ifdef __cplusplus\n"
 	   "}\n"
 	   "#endif\n");
 
-  fprintf (out, "extern void *__OFFLOAD_TABLE__[];\n\n");
+  fprintf (out, "extern const void *conat __OFFLOAD_TABLE__[];\n\n");
   fprintf (out, "static __attribute__((constructor)) void init (void)\n{\n");
   fprintf (out, "  GOMP_offload_register (__OFFLOAD_TABLE__, %d,\n",
 	   GOMP_DEVICE_NVIDIA_PTX);
Index: gcc/config/i386/intelmic-mkoffload.c
===================================================================
--- gcc/config/i386/intelmic-mkoffload.c	(revision 225851)
+++ gcc/config/i386/intelmic-mkoffload.c	(working copy)
@@ -252,7 +252,7 @@ generate_target_descr_file (const char *
 	   "__attribute__ ((__used__, visibility (\"hidden\"),\n"
 	   "section (\".gnu.offload_vars\"))) = { };\n\n"
 
-	   "void *__OFFLOAD_TARGET_TABLE__[]\n"
+	   "void const *const __OFFLOAD_TARGET_TABLE__[]\n"
 	   "__attribute__ ((__used__, visibility (\"hidden\"))) = {\n"
 	   "  &__offload_func_table, &__offload_funcs_end,\n"
 	   "  &__offload_var_table, &__offload_vars_end\n"
@@ -338,7 +338,7 @@ generate_host_descr_file (const char *ho
     fatal_error (input_location, "cannot open '%s'", src_filename);
 
   fprintf (src_file,
-	   "extern void *__OFFLOAD_TABLE__;\n"
+	   "extern const void *const __OFFLOAD_TABLE__[];\n"
 	   "extern void *__offload_image_intelmic_start;\n"
 	   "extern void *__offload_image_intelmic_end;\n\n"
 
@@ -350,11 +350,11 @@ generate_host_descr_file (const char *ho
 	   "#ifdef __cplusplus\n"
 	   "extern \"C\"\n"
 	   "#endif\n"
-	   "void GOMP_offload_register (void *, int, void *);\n"
+	   "void GOMP_offload_register (const void *, int, void *);\n"
 	   "#ifdef __cplusplus\n"
 	   "extern \"C\"\n"
 	   "#endif\n"
-	   "void GOMP_offload_unregister (void *, int, void *);\n\n"
+	   "void GOMP_offload_unregister (const void *, int, void *);\n\n"
 
 	   "__attribute__((constructor))\n"
 	   "static void\n"
Index: libgomp/target.c
===================================================================
--- libgomp/target.c	(revision 225851)
+++ libgomp/target.c	(working copy)
@@ -57,7 +57,7 @@ static gomp_mutex_t register_lock;
    pointer to target data.  */
 struct offload_image_descr {
   enum offload_target_type type;
-  void *host_table;
+  const void *host_table;
   void *target_data;
 };
 
@@ -642,7 +642,7 @@ gomp_update (struct gomp_device_descr *d
 
 static void
 gomp_offload_image_to_device (struct gomp_device_descr *devicep,
-			      void *host_table, void *target_data,
+			      const void *host_table, void *target_data,
 			      bool is_register_lock)
 {
   void **host_func_table = ((void ***) host_table)[0];
@@ -730,7 +730,8 @@ gomp_offload_image_to_device (struct gom
    the target, and TARGET_DATA needed by target plugin.  */
 
 void
-GOMP_offload_register (void *host_table, enum offload_target_type target_type,
+GOMP_offload_register (const void *host_table,
+		       enum offload_target_type target_type,
 		       void *target_data)
 {
   int i;
@@ -764,7 +765,8 @@ GOMP_offload_register (void *host_table,
    the target, and TARGET_DATA needed by target plugin.  */
 
 void
-GOMP_offload_unregister (void *host_table, enum offload_target_type target_type,
+GOMP_offload_unregister (const void *host_table,
+			 enum offload_target_type target_type,
 			 void *target_data)
 {
   void **host_func_table = ((void ***) host_table)[0];
Index: libgcc/offloadstuff.c
===================================================================
--- libgcc/offloadstuff.c	(revision 225851)
+++ libgcc/offloadstuff.c	(working copy)
@@ -46,10 +46,10 @@ see the files COPYING3 and COPYING.RUNTI
 #ifdef CRT_BEGIN
 
 #if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
-void *__offload_func_table[0]
+const void *const __offload_func_table[0]
   __attribute__ ((__used__, visibility ("hidden"),
 		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
-void *__offload_var_table[0]
+const void *const __offload_var_table[0]
   __attribute__ ((__used__, visibility ("hidden"),
 		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
 #endif
@@ -57,17 +57,17 @@ void *__offload_var_table[0]
 #elif defined CRT_END
 
 #if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
-void *__offload_funcs_end[0]
+const void *const __offload_funcs_end[0]
   __attribute__ ((__used__, visibility ("hidden"),
 		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
-void *__offload_vars_end[0]
+const void *const __offload_vars_end[0]
   __attribute__ ((__used__, visibility ("hidden"),
 		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
 
-extern void *__offload_func_table[];
-extern void *__offload_var_table[];
+extern const void *const __offload_func_table[];
+extern const void *const __offload_var_table[];
 
-void *__OFFLOAD_TABLE__[]
+const void *const __OFFLOAD_TABLE__[]
   __attribute__ ((__visibility__ ("hidden"))) =
 {
   &__offload_func_table, &__offload_funcs_end,

Reply via email to