diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2019-11-10 12:07:56 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2019-11-10 12:07:56 +0000 |
commit | 4f584c5d974ebe627090a50a332d765fce4221c8 (patch) | |
tree | 06fb720f131611bd042472d61777980606934c2c | |
parent | 8c41c2ef849f4281b1d29fa81250f4aeeb8fb21a (diff) |
Put vtab into RO section, same for __def_init if it contains an initializer.
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.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@278018 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/fortran/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fortran/trans-decl.c | 15 |
2 files changed, 19 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index eda9f2a201e..1345536fd5b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -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-10-27 Paul Thomas <pault@gcc.gnu.org> Backport from mainline diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index ac2d9b09164..1e46b627f8f 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1885,9 +1885,18 @@ gfc_get_symbol_decl (gfc_symbol * sym) if (sym->attr.associate_var) GFC_DECL_ASSOCIATE_VAR_P (decl) = 1; - if (sym->attr.vtab - || (sym->name[0] == '_' && strncmp ("__def_init", sym->name, 10) == 0)) - 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 || strncmp ("__def_init", sym->name, 10) == 0) + { + DECL_ARTIFICIAL (decl) = 1; + if (sym->attr.vtab || sym->value) + TREE_READONLY (decl) = 1; + } return decl; } |