On Mon, Jun 4, 2012 at 4:39 PM, Steven Bosscher <stevenb....@gmail.com> wrote:
> On Mon, Jun 4, 2012 at 3:34 PM, Richard Guenther
> <richard.guent...@gmail.com> wrote:
>>> have_global_bss_p:
>>> cp/decl.c:      && !have_global_bss_p ())
>>> ada/gcc-interface/utils.c:      && !have_global_bss_p ())
>>>
>>> I don't even know what this is. Help welcome. :-)
>>
>> Looks like premature optimization to me, better done in 
>> varpool_finalize_decl?
>
> I thought so, too, but if you look at the code, then there are
> comments explaining what these uses of have_global_bss_p are for.
>
>
> The case in g++ depends on flag_conserve_space and that is a c-family
> specific flag. This is the only use, btw. Here's the code:
>
>  /* Tell the back end to use or not use .common as appropriate.  If we say
>     -fconserve-space, we want this to save .data space, at the expense of
>     wrong semantics.  If we say -fno-conserve-space, we want this to
>     produce errors about redefs; to do this we force variables into the
>     data segment.  */
>  if (flag_conserve_space
>      && TREE_CODE (decl) == VAR_DECL
>      && TREE_PUBLIC (decl)
>      && !DECL_THREAD_LOCAL_P (decl)
>      && !have_global_bss_p ())
>    DECL_COMMON (decl) = 1;
>
> Note the "at the expense of wrong semantics", egad! The
> -fconserve-space flag was introduced at r11952 by mrs. That revision
> was done on May 7, 1996, with commit comment: "86th Cygnus<->FSF quick
> merge". There is one test cases for this flag in testsuite/:
> g++.old-deja/g++.brendan/array1.C:
>
> Jason, is this flag something that we could deprecate for GCC 4.7 and remove?

The docs say the flag is not useful these days as BSS is widely available.

> The code for the case in Ada is this:
>
>  /* Ada doesn't feature Fortran-like COMMON variables so we shouldn't
>     try to fiddle with DECL_COMMON.  However, on platforms that don't
>     support global BSS sections, uninitialized global variables would
>     go in DATA instead, thus increasing the size of the executable.  */
>  if (!flag_no_common
>      && TREE_CODE (var_decl) == VAR_DECL
>      && TREE_PUBLIC (var_decl)
>      && !have_global_bss_p ())
>    DECL_COMMON (var_decl) = 1;
>
> That does look like premature optimization to me, but I don't really
> understand the comment, or the effect of this code. Eric, could you
> please have a look at this and help me out?

I suppose in any case have_global_bss_p () should be a target-hook
and/or moved to target.h.  And indeed it's implementation is

/* Return true if the target supports some form of global BSS,
   either through bss_noswitch_section, or by selecting a BSS
   section in TARGET_ASM_SELECT_SECTION.  */

bool
have_global_bss_p (void)
{
  return bss_noswitch_section || targetm.have_switchable_bss_sections;
}

OTOH, I suppose including target.h from the FEs is against what you
want to achieve, too.

Richard.

> Ciao!
> Steven

Reply via email to