aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.c
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2017-09-01 10:26:00 -0600
committerJeff Law <law@gcc.gnu.org>2017-09-01 10:26:00 -0600
commit2ec399d8a6c9c26d69b73faf77c694fa3915dcec (patch)
treebfc2df7ff0476e32664d7b7175de7f5c2f04cd02 /gcc/varasm.c
parentdb6bb1ec036f180584d221cdc66dff7bb7180d7a (diff)
downloadgcc-2ec399d8a6c9c26d69b73faf77c694fa3915dcec.zip
gcc-2ec399d8a6c9c26d69b73faf77c694fa3915dcec.tar.gz
gcc-2ec399d8a6c9c26d69b73faf77c694fa3915dcec.tar.bz2
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
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r--gcc/varasm.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c
index e539337..d38d2c2 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -976,16 +976,16 @@ decode_reg_name (const char *name)
bool
bss_initializer_p (const_tree decl)
{
- return (DECL_INITIAL (decl) == NULL
- /* In LTO we have no errors in program; error_mark_node is used
- to mark offlined constructors. */
- || (DECL_INITIAL (decl) == error_mark_node
- && !in_lto_p)
- || (flag_zero_initialized_in_bss
- /* Leave constant zeroes in .rodata so they
- can be shared. */
- && !TREE_READONLY (decl)
- && initializer_zerop (DECL_INITIAL (decl))));
+ /* Do not put constants into the .bss section, they belong in a readonly
+ section. */
+ return (!TREE_READONLY (decl)
+ && (DECL_INITIAL (decl) == NULL
+ /* In LTO we have no errors in program; error_mark_node is used
+ to mark offlined constructors. */
+ || (DECL_INITIAL (decl) == error_mark_node
+ && !in_lto_p)
+ || (flag_zero_initialized_in_bss
+ && initializer_zerop (DECL_INITIAL (decl)))));
}
/* Compute the alignment of variable specified by DECL.
@@ -6517,7 +6517,8 @@ categorize_decl_for_section (const_tree decl, int reloc)
ret = SECCAT_BSS;
else if (! TREE_READONLY (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
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)
location. -fmerge-all-constants allows even that (at the
expense of not conforming). */
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;
else
ret = SECCAT_RODATA_MERGE_CONST;