From: Jan Beulich Date: Fri, 1 Jul 2016 14:23:24 +0000 (+0000) Subject: check initializer to be zero in .bss-like sections X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=059541fd113a360000b08753e355898cdeeaa431;p=gcc.git 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 * varasm.c (get_variable_section): Validate initializer in named .bss-like sections. gcc/testsuite/ 2016-07-01 Jan Beulich * gcc.dg/bss.c: New. From-SVN: r237913 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3295534da35..4020a4e37d4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-07-01 Jan Beulich + + * varasm.c (get_variable_section): Validate initializer in + named .bss-like sections. + 2016-07-01 Kelvin Nilsen * config/rs6000/altivec.md (*altivec_vpermr__internal): diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1eca9b2bcdf..382c172c778 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-07-01 Jan Beulich + + * gcc.dg/bss.c: New. + 2016-07-01 Peter Bergner PR target/71698 diff --git a/gcc/testsuite/gcc.dg/bss.c b/gcc/testsuite/gcc.dg/bss.c new file mode 100644 index 00000000000..af8d0c634fe --- /dev/null +++ b/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-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; diff --git a/gcc/varasm.c b/gcc/varasm.c index de8bcd6f20c..6a8fb81e41f 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -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)