Commit 2ec399d8 by Joerg Sonnenberger Committed by Jeff Law

varasm.c (bss_initializer_p): Do not put constants into .bss

	* varasm.c (bss_initializer_p): Do not put constants into .bss
	(categorize_decl_for_section): Handle bss_initializer_p returning
	false when DECL_INITIAL is NULL.

	* gcc.target/i386/const-in-bss.c: New test.

From-SVN: r251602
parent db6bb1ec
2017-09-01 Joerg Sonnenberger <joerg@bec.de>
Jeff Law <law@redhat.com>
* varasm.c (bss_initializer_p): Do not put constants into .bss
(categorize_decl_for_section): Handle bss_initializer_p returning
false when DECL_INITIAL is NULL.
2017-09-01 Andreas Krebbel <krebbel@linux.vnet.ibm.com> 2017-09-01 Andreas Krebbel <krebbel@linux.vnet.ibm.com>
PR target/82012 PR target/82012
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
2017-09-01 Jeff Law <law@redhat.com> 2017-09-01 Jeff Law <law@redhat.com>
* gcc.target/i386/const-in-bss.c: New test.
PR tree-optimization/82052 PR tree-optimization/82052
* gcc.c-torture/compile/pr82052.c: New test. * gcc.c-torture/compile/pr82052.c: New test.
......
/* { dg-do compile { target *-*-linux* } } */
__attribute__((section("readonly1"))) const int foo1c;
/* { dg-final { scan-assembler "readonly1,\"a\"" } } */
/* { dg-final { scan-assembler-not "readonly1,\"aw\"" } } */
...@@ -976,16 +976,16 @@ decode_reg_name (const char *name) ...@@ -976,16 +976,16 @@ decode_reg_name (const char *name)
bool bool
bss_initializer_p (const_tree decl) bss_initializer_p (const_tree decl)
{ {
return (DECL_INITIAL (decl) == NULL /* Do not put constants into the .bss section, they belong in a readonly
/* In LTO we have no errors in program; error_mark_node is used section. */
to mark offlined constructors. */ return (!TREE_READONLY (decl)
|| (DECL_INITIAL (decl) == error_mark_node && (DECL_INITIAL (decl) == NULL
&& !in_lto_p) /* In LTO we have no errors in program; error_mark_node is used
|| (flag_zero_initialized_in_bss to mark offlined constructors. */
/* Leave constant zeroes in .rodata so they || (DECL_INITIAL (decl) == error_mark_node
can be shared. */ && !in_lto_p)
&& !TREE_READONLY (decl) || (flag_zero_initialized_in_bss
&& initializer_zerop (DECL_INITIAL (decl)))); && initializer_zerop (DECL_INITIAL (decl)))));
} }
/* Compute the alignment of variable specified by DECL. /* Compute the alignment of variable specified by DECL.
...@@ -6517,7 +6517,8 @@ categorize_decl_for_section (const_tree decl, int reloc) ...@@ -6517,7 +6517,8 @@ categorize_decl_for_section (const_tree decl, int reloc)
ret = SECCAT_BSS; ret = SECCAT_BSS;
else if (! TREE_READONLY (decl) else if (! TREE_READONLY (decl)
|| TREE_SIDE_EFFECTS (decl) || TREE_SIDE_EFFECTS (decl)
|| ! TREE_CONSTANT (DECL_INITIAL (decl))) || (DECL_INITIAL (decl)
&& ! TREE_CONSTANT (DECL_INITIAL (decl))))
{ {
/* Here the reloc_rw_mask is not testing whether the section should /* Here the reloc_rw_mask is not testing whether the section should
be read-only or not, but whether the dynamic link will have to be read-only or not, but whether the dynamic link will have to
...@@ -6537,7 +6538,8 @@ categorize_decl_for_section (const_tree decl, int reloc) ...@@ -6537,7 +6538,8 @@ categorize_decl_for_section (const_tree decl, int reloc)
location. -fmerge-all-constants allows even that (at the location. -fmerge-all-constants allows even that (at the
expense of not conforming). */ expense of not conforming). */
ret = SECCAT_RODATA; ret = SECCAT_RODATA;
else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST) else if (DECL_INITIAL (decl)
&& TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
ret = SECCAT_RODATA_MERGE_STR_INIT; ret = SECCAT_RODATA_MERGE_STR_INIT;
else else
ret = SECCAT_RODATA_MERGE_CONST; ret = SECCAT_RODATA_MERGE_CONST;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment