aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.c
diff options
context:
space:
mode:
authorJozef Lawrynowicz <jozef.l@mittosystems.com>2020-11-23 12:06:39 +0000
committerJozef Lawrynowicz <jozef.l@mittosystems.com>2020-11-23 12:15:51 +0000
commit762ca20364a590be2cb9c79c0101ccbff74b5de1 (patch)
treeb865ba9ae2ac517d369987c8329cd9623cb31478 /gcc/varasm.c
parentfb8309d4abdcd4c8de07bd4c42e22d1e80471765 (diff)
downloadgcc-762ca20364a590be2cb9c79c0101ccbff74b5de1.zip
gcc-762ca20364a590be2cb9c79c0101ccbff74b5de1.tar.gz
gcc-762ca20364a590be2cb9c79c0101ccbff74b5de1.tar.bz2
Implement the "persistent" attribute
The "persistent" attribute is used for variables that are initialized by the program loader, but are not initialized by the runtime startup code. "persistent" variables are placed in a non-volatile area of memory, which allows their value to "persist" between processor resets. gcc/c-family/ChangeLog: * c-attribs.c (handle_special_var_sec_attribute): New. (handle_noinit_attribute): Remove. (attr_noinit_exclusions): Rename to... (attr_section_exclusions): ...this, and add "persistent" attribute exclusion. (c_common_attribute_table): Add "persistent" attribute. gcc/ChangeLog: * doc/extend.texi (Common Variable Attributes): Document the "persistent" variable attribute. * doc/sourcebuild.texi (Effective-Target Keywords): Document the "persistent" effective target keyword. * tree.h (DECL_PERSISTENT_P): Define. * varasm.c (bss_initializer_p): Return false for a DECL_PERSISTENT_P decl initialized to zero. (default_section_type_flags): Handle the ".persistent" section. (default_elf_select_section): Likewise. (default_unique_section): Likewise. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/noinit-attribute.c: Moved to... * c-c++-common/torture/attr-noinit-main.inc: ...here. * lib/target-supports.exp (check_effective_target_persistent): New. * c-c++-common/torture/attr-noinit-1.c: New test. * c-c++-common/torture/attr-noinit-2.c: New test. * c-c++-common/torture/attr-noinit-3.c: New test. * c-c++-common/torture/attr-noinit-invalid.c: New test. * c-c++-common/torture/attr-persistent-1.c: New test. * c-c++-common/torture/attr-persistent-2.c: New test. * c-c++-common/torture/attr-persistent-3.c: New test. * c-c++-common/torture/attr-persistent-invalid.c: New test. * c-c++-common/torture/attr-persistent-main.inc: New test.
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r--gcc/varasm.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c
index da7d0d7..b92da26 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -1057,7 +1057,11 @@ bss_initializer_p (const_tree decl, bool named)
|| (DECL_INITIAL (decl) == error_mark_node
&& !in_lto_p)
|| (flag_zero_initialized_in_bss
- && initializer_zerop (DECL_INITIAL (decl)))));
+ && initializer_zerop (DECL_INITIAL (decl))
+ /* A decl with the "persistent" attribute applied and
+ explicitly initialized to 0 should not be treated as a BSS
+ variable. */
+ && !DECL_PERSISTENT_P (decl))));
}
/* Compute the alignment of variable specified by DECL.
@@ -6680,6 +6684,9 @@ default_section_type_flags (tree decl, const char *name, int reloc)
if (strcmp (name, ".noinit") == 0)
flags |= SECTION_WRITE | SECTION_BSS | SECTION_NOTYPE;
+ if (strcmp (name, ".persistent") == 0)
+ flags |= SECTION_WRITE | SECTION_NOTYPE;
+
/* Various sections have special ELF types that the assembler will
assign by default based on the name. They are neither SHT_PROGBITS
nor SHT_NOBITS, so when changing sections we don't want to print a
@@ -7023,6 +7030,11 @@ default_elf_select_section (tree decl, int reloc,
sname = ".sdata2";
break;
case SECCAT_DATA:
+ if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
+ {
+ sname = ".persistent";
+ break;
+ }
return data_section;
case SECCAT_DATA_REL:
sname = ".data.rel";
@@ -7093,6 +7105,11 @@ default_unique_section (tree decl, int reloc)
break;
case SECCAT_DATA:
prefix = one_only ? ".d" : ".data";
+ if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
+ {
+ prefix = one_only ? ".p" : ".persistent";
+ break;
+ }
break;
case SECCAT_DATA_REL:
prefix = one_only ? ".d.rel" : ".data.rel";