This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

-fzero-initialized-in-bss again


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]