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

2018-02-08 Thread Jeff Law
On 02/06/2018 01:44 PM, Jakub Jelinek wrote:
> 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  
> 
>   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.
OK.
jeff


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

2018-02-06 Thread Jakub Jelinek
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  

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.h2018-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.c2018-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