> 
> This won't work with LTO.  Note we have the issue in the middle-end as well
> since we promote variables we see are not written to to TREE_READONLY.
> This can be seen with (the somewhat artificial...):
> 
> int a[1024*1024] = { 0 };
> 
> int __attribute__((noinline)) foo() { return *(volatile int *)a; }
> 
> int main()
> {
>   return foo ();
> }
> 
> where without -flto a gets placed into .bss while with -flto it
> gets into .rodata.  So I believe we should add a DECL flag
> specifying whether for section placement we can "ignore"
> TREE_READONLY.  We'd initialize that with the original
> state of TREE_READONLY so that the R/O promotion doesn't
> change section placement.  Also the Fortran FE can then
> simply set this flag on variables that may live in .bss.
> 
> There are 14 unused bits in tree_decl_with_vis so a
> patch for the middle-end part could look like the attached
> (w/o solving the LTO issue yet).
> 
> Of course adding sth like a .robss section would be nice.

Yep, but I think what you propose works well in practice (I am not sure
if we are forced to put const delcared variables to readonly memory and
if we can't do this as binary size optimization always). The patch
looks fine to me.  Would be possible to place the flags into
varpool_node rather then TREE? It is a lot easier to manage flags
there.

Honza
> 
> Richard.
> 
> > Regards
> >
> >         Thomas
> >
> > 2019-04-13  Thomas Koenig  <tkoe...@gcc.gnu.org>
> >
> >          PR fortran/84487
> >          * trans-decl.c (gfc_get_symbol_decl): Mark _def_init as
> >          artificial.
> >
> > 2019-04-13  Thomas Koenig  <tkoe...@gcc.gnu.org>
> >
> >          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  <tkoe...@gcc.gnu.org>
> >
> >          PR fortran/84487
> >          * gfortran.dg/def_init_1.f90: New test.
> >
> >


Reply via email to