[PATCH] ARM: Support .noinit and .persistent sections in ELF linker script
Jozef Lawrynowicz
jozef.l@mittosystems.com
Mon Nov 23 15:46:59 GMT 2020
Support for the "persistent" attribute, to place variables in the
".persistent" section, has been added to GCC and needs to be handled in
the default ARM ELF linker script.
The ".persistent" section is for data that is initialized during load,
but not during application reset.
Unique .noinit.* and .gnu.linkonce.n.* sections were unhandled within
the .noinit output section, this patch also fixes that.
Successfuly regtested the LD testsuite for arm-none-eabi, ok to apply?
-------------- next part --------------
>From 1a63288f4dd095eadae91a07b8567f980a1464d5 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Mon, 23 Nov 2020 15:44:18 +0000
Subject: [PATCH] ARM: Support .noinit and .persistent sections in ELF linker
script
Support for the "persistent" attribute, to place variables in the
".persistent" section, has been added to GCC and needs to be handled in
the default ARM ELF linker script.
The ".persistent" section is for data that is initialized during load,
but not during application reset.
Unique .noinit.* and .gnu.linkonce.n.* sections were unhandled within
the .noinit output section, this patch also fixes that.
ld/ChangeLog:
* emulparams/armelf.sh (OTHER_SECTIONS): Handle .noinit.* and
.gnu.linkonce.n.* within the .noinit output section.
Add .persistent output section.
* testsuite/ld-elf/noinit-sections-1.d: New test.
* testsuite/ld-elf/noinit-sections-2.d: New test.
* testsuite/ld-elf/noinit-sections-2.l: New test.
* testsuite/ld-elf/noinit-sections.s: New test.
---
ld/emulparams/armelf.sh | 16 +++++++++++++---
ld/testsuite/ld-elf/noinit-sections-1.d | 11 +++++++++++
ld/testsuite/ld-elf/noinit-sections-2.d | 12 ++++++++++++
ld/testsuite/ld-elf/noinit-sections-2.l | 5 +++++
ld/testsuite/ld-elf/noinit-sections.s | 16 ++++++++++++++++
5 files changed, 57 insertions(+), 3 deletions(-)
create mode 100644 ld/testsuite/ld-elf/noinit-sections-1.d
create mode 100644 ld/testsuite/ld-elf/noinit-sections-2.d
create mode 100644 ld/testsuite/ld-elf/noinit-sections-2.l
create mode 100644 ld/testsuite/ld-elf/noinit-sections.s
diff --git a/ld/emulparams/armelf.sh b/ld/emulparams/armelf.sh
index 24ca8ed59d..f9ccc499cc 100644
--- a/ld/emulparams/armelf.sh
+++ b/ld/emulparams/armelf.sh
@@ -10,7 +10,7 @@ OTHER_TEXT_SECTIONS='*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)'
OTHER_BSS_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__bss_start__ = .${CREATE_SHLIB+)};"
OTHER_BSS_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_bss_end__ = .${CREATE_SHLIB+)}; ${CREATE_SHLIB+PROVIDE (}__bss_end__ = .${CREATE_SHLIB+)};"
OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
-OTHER_SECTIONS='
+OTHER_SECTIONS="
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
/* This section contains data that is not initialised during load
*or* application reset. */
@@ -18,11 +18,21 @@ OTHER_SECTIONS='
{
. = ALIGN(2);
PROVIDE (__noinit_start = .);
- *(.noinit)
+ *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
. = ALIGN(2);
PROVIDE (__noinit_end = .);
}
-'
+/* This section contains data that *is* initialized during load,
+ but *not* during application reset. */
+ .persistent :
+ {
+ . = ALIGN(2);
+ PROVIDE (__persistent_start = .);
+ *(.persistent${RELOCATING+ .persistent.* .gnu.linkonce.p.*})
+ . = ALIGN(2);
+ PROVIDE (__persistent_end = .);
+ }
+"
ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }'
OTHER_READONLY_SECTIONS="
.ARM.extab ${RELOCATING-0} : { *(.ARM.extab${RELOCATING+* .gnu.linkonce.armextab.*}) }
diff --git a/ld/testsuite/ld-elf/noinit-sections-1.d b/ld/testsuite/ld-elf/noinit-sections-1.d
new file mode 100644
index 0000000000..7e35cd2a82
--- /dev/null
+++ b/ld/testsuite/ld-elf/noinit-sections-1.d
@@ -0,0 +1,11 @@
+#name: .noinit and .persistent sections
+#ld: --orphan-handling=warn -e _start
+#source: noinit-sections.s
+#target: arm-*-* msp430-*-elf
+#readelf: -SW
+
+#...
+ +\[ *[0-9]+\] \.noinit +NOBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .*
+#...
+ +\[ *[0-9]+\] \.persistent +PROGBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .*
+#pass
diff --git a/ld/testsuite/ld-elf/noinit-sections-2.d b/ld/testsuite/ld-elf/noinit-sections-2.d
new file mode 100644
index 0000000000..190c46fcf3
--- /dev/null
+++ b/ld/testsuite/ld-elf/noinit-sections-2.d
@@ -0,0 +1,12 @@
+#name: .noinit and .persistent sections (ld -r)
+#ld: --orphan-handling=warn -e _start -r
+#source: noinit-sections.s
+#target: arm-*-* msp430-*-elf
+#readelf: -SW
+#warning_output: noinit-sections-2.l
+
+#...
+ +\[ *[0-9]+\] \.noinit +NOBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .*
+#...
+ +\[ *[0-9]+\] \.persistent +PROGBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .*
+#pass
diff --git a/ld/testsuite/ld-elf/noinit-sections-2.l b/ld/testsuite/ld-elf/noinit-sections-2.l
new file mode 100644
index 0000000000..41ce6de01c
--- /dev/null
+++ b/ld/testsuite/ld-elf/noinit-sections-2.l
@@ -0,0 +1,5 @@
+#...
+[^:]*: warning: orphan section `.noinit.var_noinit' from \S+ being placed in section `.noinit.var_noinit'
+#...
+[^:]*: warning: orphan section `.persistent.var_persistent' from \S+ being placed in section `.persistent.var_persistent'
+#pass
diff --git a/ld/testsuite/ld-elf/noinit-sections.s b/ld/testsuite/ld-elf/noinit-sections.s
new file mode 100644
index 0000000000..793f71769e
--- /dev/null
+++ b/ld/testsuite/ld-elf/noinit-sections.s
@@ -0,0 +1,16 @@
+.section .noinit,"aw",%nobits
+.word 0
+
+.section .noinit.var_noinit,"aw",%nobits
+.word 0
+
+.section .persistent,"aw"
+.word 1
+
+.section .persistent.var_persistent,"aw"
+.word 2
+
+.text
+.global _start
+_start:
+.word 0
--
2.29.2
More information about the Binutils
mailing list