Hi,

if you compile the following Ada package:

package Bss1 is

  I : Integer := 0 with Linker_Section => ".bss";

end Bss1;

you get the error:

bss1.ads:3:3: error: only zero initializers are allowed in section '.bss'

which is quite paradoxical.  The reason is that the default setting in Ada is 
-fno-zero-initialized-in-bss instead of -fzero-initialized-in-bss.

Tested on x86-64/Linux, OK for the mainline?


2024-11-22  Eric Botcazou  <ebotca...@adacore.com>

        * doc/invoke.texi (-fno-zero-initialized-in-bss): Adjust for Ada.
        * arasm.cc (get_variable_section): Adjust the error message for an
        initialized variable in .bss to -fno-zero-initialized-in-bss.


2024-11-22  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/specs/bss1.ads: New test.

-- 
Eric Botcazou
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 0951901f50a..abf3650e0a1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13037,7 +13037,7 @@ rely on variables going to the data section---e.g., so that the
 resulting executable can find the beginning of that section and/or make
 assumptions based on that.
 
-The default is @option{-fzero-initialized-in-bss}.
+The default is @option{-fzero-initialized-in-bss} except in Ada.
 
 @opindex fthread-jumps
 @item -fthread-jumps
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index acc4b4a0419..dd67dd441c0 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -1264,9 +1264,14 @@ get_variable_section (tree decl, bool prefer_noswitch_p)
       if ((sect->common.flags & SECTION_BSS)
 	  && !bss_initializer_p (decl, true))
 	{
-	  error_at (DECL_SOURCE_LOCATION (decl),
-		    "only zero initializers are allowed in section %qs",
-		    sect->named.name);
+	  if (flag_zero_initialized_in_bss)
+	    error_at (DECL_SOURCE_LOCATION (decl),
+		      "only zero initializers are allowed in section %qs",
+		      sect->named.name);
+	  else
+	    error_at (DECL_SOURCE_LOCATION (decl),
+		      "no initializers are allowed in section %qs",
+		      sect->named.name);
 	  DECL_INITIAL (decl) = error_mark_node;
 	}
       return sect;
package Bss1 is

  I : Integer := 0 with Linker_Section => ".bss"; -- { dg-error "no initializers" }

end Bss1;

Reply via email to