Just like gas, which has recently learned to reject such initializers, gcc shouldn't accept such either. --- The only question really is whether the new test case should be limited to certain targets - I haven't been able to figure out possible valid qualifiers to use here.
gcc/ 2015-12-10 Jan Beulich <jbeul...@suse.com> * varasm.c (get_variable_section): Validate initializer in named .bss-like sections. gcc/testsuite/ 2015-12-10 Jan Beulich <jbeul...@suse.com> * gcc.dg/bss.c: New. --- 2015-12-09/gcc/testsuite/gcc.dg/bss.c +++ 2015-12-09/gcc/testsuite/gcc.dg/bss.c @@ -0,0 +1,8 @@ +/* Test non-zero initializers in .bss-like sections get properly refused. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int __attribute__((section(".bss.local"))) x = 1; /* { dg-error "" "zero init" } */ +int *__attribute__((section(".bss.local"))) px = &x; /* { dg-error "" "zero init" } */ +int __attribute__((section(".bss.local"))) y = 0; +int *__attribute__((section(".bss.local"))) py = (void*)0; --- 2015-12-09/gcc/varasm.c +++ 2015-12-09/gcc/varasm.c @@ -1150,7 +1150,18 @@ get_variable_section (tree decl, bool pr resolve_unique_section (decl, reloc, flag_data_sections); if (IN_NAMED_SECTION (decl)) - return get_named_section (decl, NULL, reloc); + { + section *sect = get_named_section (decl, NULL, reloc); + + if ((sect->common.flags & SECTION_BSS) && !bss_initializer_p (decl)) + { + error_at (DECL_SOURCE_LOCATION (decl), + "only zero initializers are allowed in section %qs", + sect->named.name); + DECL_INITIAL (decl) = error_mark_node; + } + return sect; + } if (ADDR_SPACE_GENERIC_P (as) && !DECL_THREAD_LOCAL_P (decl)
check initializer to be zero in .bss-like sections Just like gas, which has recently learned to reject such initializers, gcc shouldn't accept such either. --- The only question really is whether the new test case should be limited to certain targets - I haven't been able to figure out possible valid qualifiers to use here. gcc/ 2015-12-10 Jan Beulich <jbeul...@suse.com> * varasm.c (get_variable_section): Validate initializer in named .bss-like sections. gcc/testsuite/ 2015-12-10 Jan Beulich <jbeul...@suse.com> * gcc.dg/bss.c: New. --- 2015-12-09/gcc/testsuite/gcc.dg/bss.c +++ 2015-12-09/gcc/testsuite/gcc.dg/bss.c @@ -0,0 +1,8 @@ +/* Test non-zero initializers in .bss-like sections get properly refused. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int __attribute__((section(".bss.local"))) x = 1; /* { dg-error "" "zero init" } */ +int *__attribute__((section(".bss.local"))) px = &x; /* { dg-error "" "zero init" } */ +int __attribute__((section(".bss.local"))) y = 0; +int *__attribute__((section(".bss.local"))) py = (void*)0; --- 2015-12-09/gcc/varasm.c +++ 2015-12-09/gcc/varasm.c @@ -1150,7 +1150,18 @@ get_variable_section (tree decl, bool pr resolve_unique_section (decl, reloc, flag_data_sections); if (IN_NAMED_SECTION (decl)) - return get_named_section (decl, NULL, reloc); + { + section *sect = get_named_section (decl, NULL, reloc); + + if ((sect->common.flags & SECTION_BSS) && !bss_initializer_p (decl)) + { + error_at (DECL_SOURCE_LOCATION (decl), + "only zero initializers are allowed in section %qs", + sect->named.name); + DECL_INITIAL (decl) = error_mark_node; + } + return sect; + } if (ADDR_SPACE_GENERIC_P (as) && !DECL_THREAD_LOCAL_P (decl)