+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):
--- /dev/null
+/* 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;
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)