This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Allow (again) const variables with zero (or no) initializers in .bss* named sections (PR middle-end/84237)


Hi!

The last year's bss_initializer_p change apparently broke xen.  While it is
reasonable not to put const variables into .bss* sections by default,
refusing to put them when the user asks for it through using section
attribute seems unnecessary.  If users screws up, he can get section flag
conflicts diagnosed, if not, such as in this case when there is a separate
.bss.page_aligned.const section, it should work as before.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-02-06  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/84237
	* output.h (bss_initializer_p): Add NAMED argument, defaulted to false.
	* varasm.c (bss_initializer_p): Add NAMED argument, if true, ignore
	TREE_READONLY bit.
	(get_variable_section): For decls in named .bss* sections pass true as
	second argument to bss_initializer_p.

	* gcc.dg/pr84237.c: New test.

--- gcc/output.h.jj	2018-01-03 10:19:55.412533998 +0100
+++ gcc/output.h	2018-02-06 15:32:28.122737867 +0100
@@ -552,7 +552,7 @@ extern void output_file_directive (FILE
 extern unsigned int default_section_type_flags (tree, const char *, int);
 
 extern bool have_global_bss_p (void);
-extern bool bss_initializer_p (const_tree);
+extern bool bss_initializer_p (const_tree, bool = false);
 
 extern void default_no_named_section (const char *, unsigned int, tree);
 extern void default_elf_asm_named_section (const char *, unsigned int, tree);
--- gcc/varasm.c.jj	2018-01-18 21:11:58.664207128 +0100
+++ gcc/varasm.c	2018-02-06 15:34:16.270569690 +0100
@@ -983,11 +983,11 @@ decode_reg_name (const char *name)
 /* Return true if DECL's initializer is suitable for a BSS section.  */
 
 bool
-bss_initializer_p (const_tree decl)
+bss_initializer_p (const_tree decl, bool named)
 {
   /* Do not put non-common constants into the .bss section, they belong in
-     a readonly section.  */
-  return ((!TREE_READONLY (decl) || DECL_COMMON (decl))
+     a readonly section, except when NAMED is true.  */
+  return ((!TREE_READONLY (decl) || DECL_COMMON (decl) || named)
 	  && (DECL_INITIAL (decl) == NULL
 	      /* In LTO we have no errors in program; error_mark_node is used
 	         to mark offlined constructors.  */
@@ -1165,7 +1165,8 @@ get_variable_section (tree decl, bool pr
     {
       section *sect = get_named_section (decl, NULL, reloc);
 
-      if ((sect->common.flags & SECTION_BSS) && !bss_initializer_p (decl))
+      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",
--- gcc/testsuite/gcc.dg/pr84237.c.jj	2018-02-06 15:52:00.574944214 +0100
+++ gcc/testsuite/gcc.dg/pr84237.c	2018-02-06 15:51:40.638971424 +0100
@@ -0,0 +1,5 @@
+/* PR middle-end/84237 */
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "" } */
+
+const char __attribute__((__section__(".bss.page_aligned.const"), __aligned__(4096))) zero_page[4096];

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]