https://gcc.gnu.org/g:adb4f2329a6da903fffe33b48a03510c52d1a0b8
commit r15-5631-gadb4f2329a6da903fffe33b48a03510c52d1a0b8 Author: Eric Botcazou <ebotca...@adacore.com> Date: Sun Nov 24 15:15:54 2024 +0100 Adjust error message for initialized variable in .bss The current message does not make sense with -fno-zero-initialized-in-bss. gcc/ * doc/invoke.texi (-fno-zero-initialized-in-bss): Adjust for Ada. * varasm.cc (get_variable_section): Adjust the error message for an initialized variable in .bss to -fno-zero-initialized-in-bss. gcc/testsuite/ * gnat.dg/specs/bss1.ads: New test. Diff: --- gcc/doc/invoke.texi | 2 +- gcc/testsuite/gnat.dg/specs/bss1.ads | 5 +++++ gcc/varasm.cc | 11 ++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 44f0fd297b29..8141811b4531 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -13068,7 +13068,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/testsuite/gnat.dg/specs/bss1.ads b/gcc/testsuite/gnat.dg/specs/bss1.ads new file mode 100644 index 000000000000..56f180297cfe --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/bss1.ads @@ -0,0 +1,5 @@ +package Bss1 is + + I : Integer := 0 with Linker_Section => ".bss"; -- { dg-error "no initializers" } + +end Bss1; diff --git a/gcc/varasm.cc b/gcc/varasm.cc index acc4b4a04194..dd67dd441c0f 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;