Hello world,
the attached patch fixes a 8/9 regression where _def_init, an internal
Fortran variable containing only zeros, was placed into the .rodata
section. This led to a large increase in executable size.
There should be no impact on other languages because the change to
varasm.c is guarded by lang_GNU_Fortran ().
Regarding the test case: I did find one other test which checks
for .bss, so I suppose this is safe.
Regression-tested with a full test (--enable-languages=all and
make -j64 -k check) on POWER9.
I would like to apply it to both affected branches.
OK for the general and the Fortran part?
Regards
Thomas
2019-04-13 Thomas Koenig <[email protected]>
PR fortran/84487
* trans-decl.c (gfc_get_symbol_decl): Mark _def_init as
artificial.
2019-04-13 Thomas Koenig <[email protected]>
PR fortran/84487
* varasm.c (bss_initializer_p): If we are compiling Fortran, the
decl is artifical and it has a size larger than 255, it can be
put into BSS.
2019-04-13 Thomas Koenig <[email protected]>
PR fortran/84487
* gfortran.dg/def_init_1.f90: New test.
Index: fortran/trans-decl.c
===================================================================
--- fortran/trans-decl.c (Revision 270182)
+++ fortran/trans-decl.c (Arbeitskopie)
@@ -1865,7 +1865,10 @@ gfc_get_symbol_decl (gfc_symbol * sym)
if (sym->attr.vtab
|| (sym->name[0] == '_' && gfc_str_startswith (sym->name, "__def_init")))
- TREE_READONLY (decl) = 1;
+ {
+ TREE_READONLY (decl) = 1;
+ DECL_ARTIFICIAL (decl) = 1;
+ }
return decl;
}
Index: varasm.c
===================================================================
--- varasm.c (Revision 270182)
+++ varasm.c (Arbeitskopie)
@@ -1007,9 +1007,13 @@ decode_reg_name (const char *name)
bool
bss_initializer_p (const_tree decl, bool named)
{
- /* Do not put non-common constants into the .bss section, they belong in
- a readonly section, except when NAMED is true. */
- return ((!TREE_READONLY (decl) || DECL_COMMON (decl) || named)
+ /* Do not put non-common constants into the .bss section, they
+ belong in a readonly section, except when NAMED is true or when
+ we are dealing with an artificial declaration, in the Fortran
+ compiler only, above a certain size. */
+ return ((!TREE_READONLY (decl) || DECL_COMMON (decl) || named
+ || (lang_GNU_Fortran () && DECL_ARTIFICIAL (decl)
+ && (tree_to_uhwi (DECL_SIZE_UNIT (decl)) > 255 )))
&& (DECL_INITIAL (decl) == NULL
/* In LTO we have no errors in program; error_mark_node is used
to mark offlined constructors. */
! { dg-do compile }
! PR 84487 - check that def_init, if it is large,
! is put into .bss.
module TYPES_MODULE
implicit none
type archive_type
character(2**18) :: root_name
end type archive_type
end module TYPES_MODULE
! { dg-final { scan-assembler "\.bss" } }