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.

gcc/
2016-07-01  Jan Beulich  <jbeulich@suse.com>

	* varasm.c (get_variable_section): Validate initializer in
	named .bss-like sections.

gcc/testsuite/
2016-07-01  Jan Beulich  <jbeulich@suse.com>

	* gcc.dg/bss.c: New.

From-SVN: r237913
This commit is contained in:
Jan Beulich 2016-07-01 14:23:24 +00:00 committed by Jan Beulich
parent 51433308bb
commit 059541fd11
4 changed files with 29 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2016-07-01 Jan Beulich <jbeulich@suse.com>
* varasm.c (get_variable_section): Validate initializer in
named .bss-like sections.
2016-07-01 Kelvin Nilsen <kelvin@gcc.gnu.org>
* config/rs6000/altivec.md (*altivec_vpermr_<mode>_internal):

View file

@ -1,3 +1,7 @@
2016-07-01 Jan Beulich <jbeulich@suse.com>
* gcc.dg/bss.c: New.
2016-07-01 Peter Bergner <bergner@vnet.ibm.com>
PR target/71698

View file

@ -0,0 +1,8 @@
/* Test non-zero initializers in .bss-like sections get properly refused. */
/* { dg-do compile } */
/* { dg-require-named-sections "" } */
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;

View file

@ -1150,7 +1150,18 @@ get_variable_section (tree decl, bool prefer_noswitch_p)
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)