+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>
PR target/82012
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.
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
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;