public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* -fzero-initialized-in-bss again
@ 2004-04-30 21:31 Eric Botcazou
  2004-04-30 21:39 ` Ian Lance Taylor
       [not found] ` <jmad0txhey.fsf@desire.geoffk.org>
  0 siblings, 2 replies; 20+ messages in thread
From: Eric Botcazou @ 2004-04-30 21:31 UTC (permalink / raw)
  To: gcc

Hi,

We recently (after the 3.4.0 release, unfortunately) discovered that the 
default option -fzero-initialized-in-bss has an annoying side-effect for the 
Ada compiler: it may prevent the user from overriding an object in a library 
(e.g. the runtime) by a local, slightly modified copy of the object.

Let's take an example: a user wants to modify a parameter of the runtime, by 
locally tweaking s-parame.ads like so

@@ -73,7 +73,7 @@
    --  The special value of minus one indicates that the secondary
    --  stack is to be allocated from the heap instead.

-   Sec_Stack_Ratio : constant Ratio := Dynamic;
+   Sec_Stack_Ratio : constant Ratio := 10;
    --  This constant defines the handling of the secondary stack

    Sec_Stack_Dynamic : constant Boolean := Sec_Stack_Ratio = Dynamic;


When building the executable, gnatmake will locally recompile s-parame.adb 
and try link it into the executable.  But that will fail with the error 
message:

/cardiff.a/gnatmail-5_34/build-cardiff/install/lib/gcc/i686-pc-linux-gnu/3.4.1/a
dalib/libgnat.a(s-parame.o)(.data+0x0): multiple definition of 
`system__parameters__unspecified_size'
./s-parame.o(.data+0x0): first defined here


Here's what happens: the change from 'Dynamic' to '10' for Sec_Stack_Ratio 
causes the comparison that initializes Sec_Stack_Dynamic to become false, 
hence Sec_Stack_Dynamic is effectively initialized to 0.  Given that the 
option -fzero-initialized-in-bss is enabled by default, the symbol 
system__parameters__sec_stack_dynamic is moved from .data to the 
uninitialized data section.  Now -fcommon is also on by default so the Ada 
compiler puts uninitialized symbols in the .common section.  We eventually 
end up with system__parameters__sec_stack_dynamic in the .common section.

So the local object has system__parameters__sec_stack_dynamic in .common 
while the runtime has it in .data.  Therefore the linker imports s-parame.o 
from libgnat.a, thus leading to conflicts for other symbols.


A simple solution is to turn -fzero-initialized-in-bss off by default.  This 
was discussed back in July just before the 3.3.1 release, in light of other 
problems with the FreeBSD kernel and GNU Emacs on Solaris.  We feel that 
this Ada issue adds to the pile of drawbacks with having it enabled by 
default.

Would it be feasible to do it, starting with the 3.4.1 release?

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: -fzero-initialized-in-bss again
@ 2004-04-30 21:46 Richard Kenner
  2004-04-30 21:52 ` Ian Lance Taylor
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Kenner @ 2004-04-30 21:46 UTC (permalink / raw)
  To: ian; +Cc: gcc

    Whether something like -fzero-initialized-in-bss is correct really
    depends on language rules.  It sounds like the Ada compiler should
    turn it off by default.  Or else the Ada compiler should default to
    -fno-common; that is also a language rules issue.

I think Eric was a bit misleading here.  Although the problem occured
with an Ada program, it is not language-specific and can occur in 
any language.

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: -fzero-initialized-in-bss again
@ 2004-04-30 22:22 Richard Kenner
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Kenner @ 2004-04-30 22:22 UTC (permalink / raw)
  To: ian; +Cc: gcc

    Is the problem that -fzero-initialized-in-bss is causing a zero
    initialized variable to become a common variable?  A BSS variable
    should not be a common variable.  That would be wrong.

That's my understanding, but I could be misunderstanding.

^ permalink raw reply	[flat|nested] 20+ messages in thread
[parent not found: <10404302228.AA06573@vlsi1.ultra.nyu.edu>]
* Re: -fzero-initialized-in-bss again
@ 2004-05-01 12:13 Richard Kenner
  2004-05-01 13:11 ` Eric Botcazou
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Kenner @ 2004-05-01 12:13 UTC (permalink / raw)
  To: ebotcazou; +Cc: gcc

    If that's the only intent, let's follow Geoff's suggestion and simply
    delete the line from ada/utils.c (or at least make -fno-common the
    default).  AFAIK the problem .common is aimed at solving in C doesn't
    exist in Ada.

If the goal is to treat a variable the same in Ada as it would have been in
C, then deleting that line certainly won't do that!

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: -fzero-initialized-in-bss again
@ 2004-05-01 15:29 Richard Kenner
  2004-05-01 16:18 ` Eric Botcazou
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Richard Kenner @ 2004-05-01 15:29 UTC (permalink / raw)
  To: ebotcazou; +Cc: gcc

    Let me rephrase: if the only purpose of this line is to mimic what the
    C compiler does with common variables and the Ada compiler doesn't
    need common variables, let's delete the line.

    So the question that would be good to answer is: does the Ada compiler
    need common variables?

I have non clue what a "common variable" might mean.

What we are discussing is what object file section each variable
should go into.  And what I'm saying is that this shouldn't depend on
whether a variable was written in C or Ada: it should only be a function
of language-independent attributes.

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: -fzero-initialized-in-bss again
@ 2004-05-03 18:00 Richard Kenner
  2004-05-03 21:29 ` Gabriel Dos Reis
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Kenner @ 2004-05-03 18:00 UTC (permalink / raw)
  To: geoffk; +Cc: gcc

    > What we are discussing is what object file section each variable
    > should go into.  And what I'm saying is that this shouldn't depend on
    > whether a variable was written in C or Ada: it should only be a function
    > of language-independent attributes.

    This statement really doesn't make sense to me.  It's like saying that
    what section a variable goes into should be the same between C and
    C++; if it was true, then we should be able to delete thousands of
    lines from the C++ frontend that are concerned with section and
    linkage selection.

Not really.  What I was trying to say is that the goal is to make Ada and C
as compatible as possible in terms of data layout.  One of the reasons for
this has to do with the desire to use standard tools in an embedded
environment and most of these are designed for C.  Obviously, if there's
something about a variable in C++ that can't be expressed in C, it isn't
meaningful to do the same thing as for C.  But if there *is* a simple analogy
with C, the most user-friendly thing to do is to do exactly what C would do
with that variable.

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

end of thread, other threads:[~2004-05-03 21:29 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-30 21:31 -fzero-initialized-in-bss again Eric Botcazou
2004-04-30 21:39 ` Ian Lance Taylor
     [not found] ` <jmad0txhey.fsf@desire.geoffk.org>
2004-05-01  7:33   ` Eric Botcazou
2004-04-30 21:46 Richard Kenner
2004-04-30 21:52 ` Ian Lance Taylor
2004-04-30 23:06   ` Richard Henderson
2004-05-01 14:54     ` Eric Botcazou
2004-05-01 17:46       ` Richard Henderson
2004-05-01  8:03   ` Eric Botcazou
2004-04-30 22:22 Richard Kenner
     [not found] <10404302228.AA06573@vlsi1.ultra.nyu.edu>
2004-05-01  8:20 ` Eric Botcazou
2004-05-01 12:13 Richard Kenner
2004-05-01 13:11 ` Eric Botcazou
2004-05-01 15:29 Richard Kenner
2004-05-01 16:18 ` Eric Botcazou
2004-05-01 18:13   ` Richard Henderson
2004-05-03  2:40 ` Ian Lance Taylor
2004-05-03 17:56 ` Geoff Keating
2004-05-03 18:00 Richard Kenner
2004-05-03 21:29 ` Gabriel Dos Reis

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).