public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Delete bogus use of flag_zero_initialized_in_bss
@ 2010-03-16  8:58 Duncan Sands
  2010-03-16  9:06 ` Eric Botcazou
  0 siblings, 1 reply; 15+ messages in thread
From: Duncan Sands @ 2010-03-16  8:58 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 728 bytes --]

The Ada front-end seems to think that clearing flag_zero_initialized_in_bss
means that global variables without an explicit initializer will be considered
to be uninitialized rather than zero initialized by the rest of the compiler.
But that is not the effect of this flag at all.  Rather than specifying whether
the global will be zero initialized or not, it specifies by what method it will
be zero initialized: whether by placing in the BSS section or by outputting an
explicit block of zeros.

I can understand that the Ada front-end would like a way of telling the
optimizers that globals in Ada are not automatically zero initialized -
in theory it would open up some optimization opportunities.  But this is
not the way.

[-- Attachment #2: bss.diff --]
[-- Type: text/x-diff, Size: 949 bytes --]

Index: mainline/gcc/ada/gcc-interface/misc.c
===================================================================
--- mainline.orig/gcc/ada/gcc-interface/misc.c	2010-03-15 21:51:40.607571847 +0100
+++ mainline/gcc/ada/gcc-interface/misc.c	2010-03-15 21:51:52.950077996 +0100
@@ -294,9 +294,6 @@
   save_argc = argc;
   save_argv = argv;
 
-  /* Uninitialized really means uninitialized in Ada.  */
-  flag_zero_initialized_in_bss = 0;
-
   return CL_Ada;
 }
 
Index: mainline/gcc/ChangeLog
===================================================================
--- mainline.orig/gcc/ChangeLog	2010-03-16 08:51:27.540175865 +0100
+++ mainline/gcc/ChangeLog	2010-03-16 09:06:11.920238870 +0100
@@ -1,3 +1,8 @@
+2010-03-16  Duncan Sands  <baldrick@free.fr>
+
+	* ada/gcc-interface/misc.c (gnat_init_options): Do not unconditionally
+        clear flag_zero_initialized_in_bss.
+
 2010-03-15  Martin Jambor  <mjambor@suse.cz>
 
 	PR tree/optimization/43141

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16  8:58 [Ada] Delete bogus use of flag_zero_initialized_in_bss Duncan Sands
@ 2010-03-16  9:06 ` Eric Botcazou
  2010-03-16  9:21   ` Duncan Sands
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Botcazou @ 2010-03-16  9:06 UTC (permalink / raw)
  To: Duncan Sands; +Cc: gcc-patches

> The Ada front-end seems to think that clearing flag_zero_initialized_in_bss
> means that global variables without an explicit initializer will be
> considered to be uninitialized rather than zero initialized by the rest of
> the compiler.

No, it doesn't, you misunderstood.

> Rather than specifying whether the global will be zero initialized or not,
> it specifies by what method it will be zero initialized: whether by placing
> in the BSS section or by outputting an explicit block of zeros.

Yes, that's precisely why the flag needs to be cleared: uninitialized really 
means uninitialized in Ada so the BSS section isn't guaranteed to be zero-ed 
at startup for a pure Ada program.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16  9:06 ` Eric Botcazou
@ 2010-03-16  9:21   ` Duncan Sands
  2010-03-16  9:34     ` Arnaud Charlet
  2010-03-16 16:08     ` Eric Botcazou
  0 siblings, 2 replies; 15+ messages in thread
From: Duncan Sands @ 2010-03-16  9:21 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

Hi Eric,

>> The Ada front-end seems to think that clearing flag_zero_initialized_in_bss
>> means that global variables without an explicit initializer will be
>> considered to be uninitialized rather than zero initialized by the rest of
>> the compiler.
>
> No, it doesn't, you misunderstood.
>
>> Rather than specifying whether the global will be zero initialized or not,
>> it specifies by what method it will be zero initialized: whether by placing
>> in the BSS section or by outputting an explicit block of zeros.
>
> Yes, that's precisely why the flag needs to be cleared: uninitialized really
> means uninitialized in Ada so the BSS section isn't guaranteed to be zero-ed
> at startup for a pure Ada program.

on most systems (such as linux) it is the O/S that takes care of ensuring the
BSS section is filled with zeros, so I don't see how being an Ada program is
relevant.

Ciao,

Duncan.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16  9:21   ` Duncan Sands
@ 2010-03-16  9:34     ` Arnaud Charlet
  2010-03-16  9:37       ` Duncan Sands
  2010-03-16 16:08     ` Eric Botcazou
  1 sibling, 1 reply; 15+ messages in thread
From: Arnaud Charlet @ 2010-03-16  9:34 UTC (permalink / raw)
  To: Duncan Sands; +Cc: Eric Botcazou, gcc-patches

>> Yes, that's precisely why the flag needs to be cleared: uninitialized really
>> means uninitialized in Ada so the BSS section isn't guaranteed to be zero-ed
>> at startup for a pure Ada program.
>
> on most systems (such as linux) it is the O/S that takes care of ensuring the
> BSS section is filled with zeros, so I don't see how being an Ada program is
> relevant.

Not all systems behave this way, and not all systems are Linux systems, in
particular embedded systems. The patch is indeed not OK.

BTW for the future, you forgot to include a proper ChangeLog for your
patch.

Arno

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16  9:34     ` Arnaud Charlet
@ 2010-03-16  9:37       ` Duncan Sands
  2010-03-16 10:20         ` Arnaud Charlet
  0 siblings, 1 reply; 15+ messages in thread
From: Duncan Sands @ 2010-03-16  9:37 UTC (permalink / raw)
  To: gcc-patches

Hi Arnaud,

>>> Yes, that's precisely why the flag needs to be cleared: uninitialized really
>>> means uninitialized in Ada so the BSS section isn't guaranteed to be zero-ed
>>> at startup for a pure Ada program.
>>
>> on most systems (such as linux) it is the O/S that takes care of ensuring the
>> BSS section is filled with zeros, so I don't see how being an Ada program is
>> relevant.
>
> Not all systems behave this way, and not all systems are Linux systems, in
> particular embedded systems. The patch is indeed not OK.

shouldn't you only clear this flag on such systems then?  On all other systems
you are creating fatter executables by filling object files with zeros.

> BTW for the future, you forgot to include a proper ChangeLog for your
> patch.

It did have a changelog entry (see below).  Were you referring to some other
changelog?

Index: mainline/gcc/ChangeLog
===================================================================
--- mainline.orig/gcc/ChangeLog	2010-03-16 08:51:27.540175865 +0100
+++ mainline/gcc/ChangeLog	2010-03-16 09:06:11.920238870 +0100
@@ -1,3 +1,8 @@
+2010-03-16  Duncan Sands  <baldrick@free.fr>
+
+	* ada/gcc-interface/misc.c (gnat_init_options): Do not unconditionally
+        clear flag_zero_initialized_in_bss.
+
  2010-03-15  Martin Jambor  <mjambor@suse.cz>

  	PR tree/optimization/43141

Ciao,

Duncan.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16  9:37       ` Duncan Sands
@ 2010-03-16 10:20         ` Arnaud Charlet
  0 siblings, 0 replies; 15+ messages in thread
From: Arnaud Charlet @ 2010-03-16 10:20 UTC (permalink / raw)
  To: Duncan Sands; +Cc: gcc-patches

>> BTW for the future, you forgot to include a proper ChangeLog for your
>> patch.
>
> It did have a changelog entry (see below).  Were you referring to some other
> changelog?

I was expecting the changelog inlined in your email which is the standard
submission format.

Also, you updated the wrong changelog: it should be under gcc/ada and refer to
gcc-interface/misc.c.

For these two reasons I missed it :-)

Arno

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16  9:21   ` Duncan Sands
  2010-03-16  9:34     ` Arnaud Charlet
@ 2010-03-16 16:08     ` Eric Botcazou
  2010-03-16 17:00       ` Duncan Sands
  1 sibling, 1 reply; 15+ messages in thread
From: Eric Botcazou @ 2010-03-16 16:08 UTC (permalink / raw)
  To: Duncan Sands; +Cc: gcc-patches

> on most systems (such as linux) it is the O/S that takes care of ensuring
> the BSS section is filled with zeros, so I don't see how being an Ada
> program is relevant.

Being an Ada program is relevant because there is no requirement in Ada to 
zero global uninitialized variables like in C/C++.  Hence you cannot count
on it to indirectly zero global variables that are zero-initialized.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16 16:08     ` Eric Botcazou
@ 2010-03-16 17:00       ` Duncan Sands
  2010-03-16 22:26         ` Eric Botcazou
  0 siblings, 1 reply; 15+ messages in thread
From: Duncan Sands @ 2010-03-16 17:00 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

Hi Eric,

>> on most systems (such as linux) it is the O/S that takes care of ensuring
>> the BSS section is filled with zeros, so I don't see how being an Ada
>> program is relevant.
>
> Being an Ada program is relevant because there is no requirement in Ada to
> zero global uninitialized variables like in C/C++.  Hence you cannot count
> on it to indirectly zero global variables that are zero-initialized.

thanks for replying, but I still didn't get it.  By clearing
flag_zero_initialized_in_bss you obtain the following effect:

- globals without an explicit initial value are placed in the BSS section.
- globals explicitly initialized to zero are not placed in the BSS section.

On a linux system, the program loader will fill the BSS section with zeros.
So in both cases the global will be zero initialized.  What then is the point
of clearing flag_zero_initialized_in_bss?

Ciao,

Duncan.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16 17:00       ` Duncan Sands
@ 2010-03-16 22:26         ` Eric Botcazou
  2010-03-18 14:06           ` Duncan Sands
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Botcazou @ 2010-03-16 22:26 UTC (permalink / raw)
  To: Duncan Sands; +Cc: gcc-patches

> On a linux system, the program loader will fill the BSS section with zeros.
> So in both cases the global will be zero initialized.  What then is the
> point of clearing flag_zero_initialized_in_bss?

Not all Ada programs are meant to run on a linux system.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-16 22:26         ` Eric Botcazou
@ 2010-03-18 14:06           ` Duncan Sands
  2010-03-18 15:26             ` Eric Botcazou
  0 siblings, 1 reply; 15+ messages in thread
From: Duncan Sands @ 2010-03-18 14:06 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

Hi Eric,

>> On a linux system, the program loader will fill the BSS section with zeros.
>> So in both cases the global will be zero initialized.  What then is the
>> point of clearing flag_zero_initialized_in_bss?
>
> Not all Ada programs are meant to run on a linux system.

if I understand right you agree that clearing this flag is pointless on
linux (and probably many other) systems, but that it is simpler to clear
it everywhere rather than only on those systems that need it?

Ciao,

Duncan.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-18 14:06           ` Duncan Sands
@ 2010-03-18 15:26             ` Eric Botcazou
  2010-04-15 13:10               ` Florian Weimer
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Botcazou @ 2010-03-18 15:26 UTC (permalink / raw)
  To: Duncan Sands; +Cc: gcc-patches

> if I understand right you agree that clearing this flag is pointless on
> linux (and probably many other) systems, but that it is simpler to clear
> it everywhere rather than only on those systems that need it?

Even on Linux you may need to clear it if you have a pure Ada program and a 
custom linker script.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-03-18 15:26             ` Eric Botcazou
@ 2010-04-15 13:10               ` Florian Weimer
  2010-04-15 16:59                 ` Eric Botcazou
  0 siblings, 1 reply; 15+ messages in thread
From: Florian Weimer @ 2010-04-15 13:10 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: Duncan Sands, gcc-patches

* Eric Botcazou:

>> if I understand right you agree that clearing this flag is pointless on
>> linux (and probably many other) systems, but that it is simpler to clear
>> it everywhere rather than only on those systems that need it?
>
> Even on Linux you may need to clear it if you have a pure Ada program and a 
> custom linker script.

Are you sure?  Where would that non-zero data come from?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-04-15 13:10               ` Florian Weimer
@ 2010-04-15 16:59                 ` Eric Botcazou
  2010-04-15 17:13                   ` Florian Weimer
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Botcazou @ 2010-04-15 16:59 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Duncan Sands, gcc-patches

> Where would that non-zero data come from?

What guarantees you that you get zeros for a random SHF_NOBITS section?

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-04-15 16:59                 ` Eric Botcazou
@ 2010-04-15 17:13                   ` Florian Weimer
  2010-04-15 17:40                     ` Eric Botcazou
  0 siblings, 1 reply; 15+ messages in thread
From: Florian Weimer @ 2010-04-15 17:13 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: Duncan Sands, gcc-patches

* Eric Botcazou:

>> Where would that non-zero data come from?
>
> What guarantees you that you get zeros for a random SHF_NOBITS section?

Do you mean SHT_NOBITS?

The kernel provides cleared memory for security reasons, upon request
from the dynamic linker.  I doubt there is code to special-case .bss
in this regard.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Ada] Delete bogus use of flag_zero_initialized_in_bss
  2010-04-15 17:13                   ` Florian Weimer
@ 2010-04-15 17:40                     ` Eric Botcazou
  0 siblings, 0 replies; 15+ messages in thread
From: Eric Botcazou @ 2010-04-15 17:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Duncan Sands, gcc-patches

> Do you mean SHT_NOBITS?

Yes, sorry, SHT_ for type.

> The kernel provides cleared memory for security reasons, upon request
> from the dynamic linker.  I doubt there is code to special-case .bss
> in this regard.

Every kernel version for every architecture?

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-04-15 17:13 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-16  8:58 [Ada] Delete bogus use of flag_zero_initialized_in_bss Duncan Sands
2010-03-16  9:06 ` Eric Botcazou
2010-03-16  9:21   ` Duncan Sands
2010-03-16  9:34     ` Arnaud Charlet
2010-03-16  9:37       ` Duncan Sands
2010-03-16 10:20         ` Arnaud Charlet
2010-03-16 16:08     ` Eric Botcazou
2010-03-16 17:00       ` Duncan Sands
2010-03-16 22:26         ` Eric Botcazou
2010-03-18 14:06           ` Duncan Sands
2010-03-18 15:26             ` Eric Botcazou
2010-04-15 13:10               ` Florian Weimer
2010-04-15 16:59                 ` Eric Botcazou
2010-04-15 17:13                   ` Florian Weimer
2010-04-15 17:40                     ` Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).