From: Eric Botcazou Date: Sun, 24 Nov 2024 14:15:54 +0000 (+0100) Subject: Adjust error message for initialized variable in .bss X-Git-Tag: basepoints/gcc-16~3922 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=adb4f2329a6da903fffe33b48a03510c52d1a0b8;p=thirdparty%2Fgcc.git 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 --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;