]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Put vtab into RO section, same for __def_init if it contains an initializer.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 10 Nov 2019 11:19:13 +0000 (11:19 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 10 Nov 2019 11:19:13 +0000 (11:19 +0000)
2019-11-10  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/92113
* trans-decl.c (gfc_get_symbol_decl): If __def_init actually
contains a value, put it into  the read-only section.

From-SVN: r278015

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c

index 307f8ba5a18c93d80984e4e45ae647f044502166..42430e46ef6986b429cd608914552c4cbb3ef588 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/92113
+       * trans-decl.c (gfc_get_symbol_decl): If __def_init actually
+       contains a value, put it into  the read-only section.
+
 2019-11-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
index d1a6172063ed637f9a9b82e1fde54f237cd054de..27613f761e3ccfbede2340302277f469db2bf47c 100644 (file)
@@ -1885,13 +1885,18 @@ gfc_get_symbol_decl (gfc_symbol * sym)
   if (sym->attr.associate_var)
     GFC_DECL_ASSOCIATE_VAR_P (decl) = 1;
 
-  /* We no longer mark __def_init as read-only so it does not take up
-     space in the read-only section and dan go into the BSS instead,
-     see PR 84487.  Marking this as artificial means that OpenMP will
-     treat this as predetermined shared.  */
-  if (sym->attr.vtab
-      || (sym->name[0] == '_' && gfc_str_startswith (sym->name, "__def_init")))
-    DECL_ARTIFICIAL (decl) = 1;
+  /* We only mark __def_init as read-only if it actually has an
+     initializer so it does not needlessly take up space in the
+     read-only section and can go into the BSS instead, see PR 84487.
+     Marking this as artificial means that OpenMP will treat this as
+     predetermined shared.  */
+
+  if (sym->attr.vtab || gfc_str_startswith (sym->name, "__def_init"))
+    {
+      DECL_ARTIFICIAL (decl) = 1;
+      if (sym->attr.vtab || sym->value)
+       TREE_READONLY (decl) = 1;
+    }
 
   return decl;
 }