From 2c6f3e56cbba35365ce0f558e9bfbb122a63a63d Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Fri, 27 Nov 2020 10:45:35 +0000 Subject: ELF: Support .noinit and .persistent sections The ".persistent" section is for data that should be initialized during load, but not during application reset. The ".noinit" section is for data that should not be initialized during load or application reset. Targets utilizing the elf.sc linker script template can define HAVE_{NOINIT,PERSISTENT}=yes to include the .noinit or .persistent output sections in the generated linker script. Targets with existing support for .noinit did not handle unique .noinit.* and .gnu.linkonce.n.* sections the .noinit output section, this patch also fixes that. bfd/ChangeLog: * elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p. (special_sections_n): Add .noinit. (special_sections_p): Add .persistent. binutils/ChangeLog: * testsuite/lib/binutils-common.exp (supports_noinit_section): New. (supports_persistent_section): New. gas/ChangeLog: * testsuite/gas/elf/elf.exp: Run new tests. * testsuite/gas/elf/section25.d: New test. * testsuite/gas/elf/section25.s: New test. * testsuite/gas/elf/section26.d: New test. * testsuite/gas/elf/section26.s: New test. ld/ChangeLog: * emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section definition. Define HAVE_{NOINIT,PERSISTENT}=yes. * scripttempl/avr.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.* input section wildcard patterns. * scripttempl/elf.sc: Define .noinit and .persistent sections when HAVE_NOINIT or HAVE_PERSISTENT are defined to "yes". * scripttempl/elf32msp430.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*. input section wildcard patterns. (.persistent): Add .persistent.* and .gnu.linkonce.p.*. input section wildcard patterns. * scripttempl/elfarcv2.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*. input section wildcard patterns. * scripttempl/pru.sc: Likewise. * 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. * testsuite/ld-elf/persistent-sections-1.d: New test. * testsuite/ld-elf/persistent-sections-2.d: New test. * testsuite/ld-elf/persistent-sections-2.l: New test. * testsuite/ld-elf/persistent-sections.s: New test. --- ld/scripttempl/avr.sc | 2 +- ld/scripttempl/elf.sc | 28 ++++++++++++++++++++++++++++ ld/scripttempl/elf32msp430.sc | 12 ++++++++++-- ld/scripttempl/elfarcv2.sc | 2 +- ld/scripttempl/pru.sc | 2 +- 5 files changed, 41 insertions(+), 5 deletions(-) (limited to 'ld/scripttempl') diff --git a/ld/scripttempl/avr.sc b/ld/scripttempl/avr.sc index b85748b..77238d6 100644 --- a/ld/scripttempl/avr.sc +++ b/ld/scripttempl/avr.sc @@ -271,7 +271,7 @@ cat < data} ${RELOCATING+ PROVIDE (__bsssize = SIZEOF(.bss)); } + /* This section contains data that is not initialized during load, + or during the application's initialization sequence. */ .noinit ${RELOCATING-0}${RELOCATING+SIZEOF(.bss) + ADDR(.bss)} : { + ${RELOCATING+. = ALIGN(2);} ${RELOCATING+ PROVIDE (__noinit_start = .) ; } - *(.noinit) + *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*}) + ${RELOCATING+. = ALIGN(2);} ${RELOCATING+ PROVIDE (__noinit_end = .) ; } } ${RELOCATING+ > data} + /* This section contains data that is initialized during load, + but not during the application's initialization sequence. */ .persistent ${RELOCATING-0}${RELOCATING+SIZEOF(.noinit) + ADDR(.noinit)} : { + ${RELOCATING+. = ALIGN(2);} ${RELOCATING+ PROVIDE (__persistent_start = .) ; } - *(.persistent) + *(.persistent${RELOCATING+ .persistent.* .gnu.linkonce.p.*}) + ${RELOCATING+. = ALIGN(2);} ${RELOCATING+ PROVIDE (__persistent_end = .) ; } } ${RELOCATING+ > data} diff --git a/ld/scripttempl/elfarcv2.sc b/ld/scripttempl/elfarcv2.sc index b6cab6c..a0c4f7e 100644 --- a/ld/scripttempl/elfarcv2.sc +++ b/ld/scripttempl/elfarcv2.sc @@ -283,7 +283,7 @@ SECTIONS /* Global data not cleared after reset. */ .noinit ${RELOCATING-0}: { - *(.noinit*) + *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*}) ${RELOCATING+. = ALIGN(${ALIGNMENT});} ${RELOCATING+ PROVIDE (__start_heap = .) ; } } ${RELOCATING+ > ${DATA_MEMORY}} diff --git a/ld/scripttempl/pru.sc b/ld/scripttempl/pru.sc index 9ef7980..08aceaa 100644 --- a/ld/scripttempl/pru.sc +++ b/ld/scripttempl/pru.sc @@ -167,7 +167,7 @@ SECTIONS .noinit ${RELOCATING-0} : { ${RELOCATING+ PROVIDE (_noinit_start = .) ; } - *(.noinit) + *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*}) ${RELOCATING+ PROVIDE (_noinit_end = .) ; } ${RELOCATING+ PROVIDE (_heap_start = .) ; } ${RELOCATING+ . += __HEAP_SIZE ; } -- cgit v1.1