From b510765dedfec573c756cb1fcfcb5b0c3830c5e9 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Mon, 23 Nov 2020 11:43:39 +0000 Subject: Fix "noinit" attribute being ignored for -O0 and -fdata-sections Variables with the "noinit" attribute are ignored at -O0 because they are treated like a regular bss variable and placed in the .bss section. With -fdata-sections they are ignored because they are not handled in resolve_unique_section. gcc/ChangeLog: * tree.h (DECL_NOINIT_P): Define. * varasm.c (DECL_NOINIT_P): Check DECL_NOINIT_P before using unnamed bss/lcomm sections for bss_initializer variables. (default_elf_select_section): Use DECL_NOINIT_P instead of looking up attribute for .noinit section selection. (default_unique_section): Check DECL_NOINIT_P for .noinit section selection. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/noinit-attribute.c: Don't override optimization options set by torture test harness. * lib/target-supports.exp (check_effective_target_noinit): Adjust comment formatting. --- gcc/tree.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/tree.h') diff --git a/gcc/tree.h b/gcc/tree.h index 20f66a0..664449a 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -2662,6 +2662,13 @@ extern tree vector_element_bits_tree (const_tree); #define DECL_PRESERVE_P(DECL) \ DECL_COMMON_CHECK (DECL)->decl_common.preserve_flag +/* Nonzero for a decl that is decorated with the "noinit" attribute. + decls with this attribute are placed into the ".noinit" section, so they are + not initialized by the target's startup code. */ +#define DECL_NOINIT_P(DECL) \ + (DECL_P (DECL) \ + && (lookup_attribute ("noinit", DECL_ATTRIBUTES (DECL)) != NULL_TREE)) + /* For function local variables of COMPLEX and VECTOR types, indicates that the variable is not aliased, and that all modifications to the variable have been adjusted so that -- cgit v1.1