diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2025-03-13 11:52:00 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2025-03-14 15:59:02 -0700 |
commit | d87be451ebbf831d44ac168ca9ea2b79ab5a79b3 (patch) | |
tree | 661cf269efff62c359f22c734fa9a9ed4d810f34 | |
parent | 5cac5ee6be6a4c5668b119c0e2967a5967ba6b35 (diff) | |
download | binutils-d87be451ebbf831d44ac168ca9ea2b79ab5a79b3.zip binutils-d87be451ebbf831d44ac168ca9ea2b79ab5a79b3.tar.gz binutils-d87be451ebbf831d44ac168ca9ea2b79ab5a79b3.tar.bz2 |
elf: Clear the SEC_ALLOC bit for NOLOAD note sections
When generating an ELF output file, if a note section is marked as
NOLOAD, clear the SEC_ALLOC bit so that it won't be treated as an
SHF_ALLOC section, like a .bss style section.
PR ld/32787
* ld.texi: Update NOLOAD for ELF output files.
* ldlang.c (lang_add_section): Clear the SEC_ALLOC bit for NOLOAD
note sections for ELF output files.
* testsuite/ld-elf/pr32787.d: New file.
* testsuite/ld-elf/pr32787.t: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
-rw-r--r-- | ld/ld.texi | 8 | ||||
-rw-r--r-- | ld/ldlang.c | 6 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr32787.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr32787.t | 12 |
4 files changed, 32 insertions, 3 deletions
@@ -5965,7 +5965,13 @@ parentheses. The following types are defined: @item NOLOAD The section should be marked as not loadable, so that it will not be -loaded into memory when the program is run. +loaded into memory when the program is run. When generating an ELF +output file, the memory space is allocated for the section at run-time, +except for SHT_NOTE sections. For other output files, no memory space +is allocated at run-time. + +Note - the ELF behaviour is a bug that may change to be consistent +with non-ELF targets. @item READONLY The section should be marked as read-only. diff --git a/ld/ldlang.c b/ld/ldlang.c index 011c526..0048dfa 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2827,8 +2827,10 @@ lang_add_section (lang_statement_list_type *ptr, /* Unfortunately GNU ld has managed to evolve two different meanings to NOLOAD in scripts. ELF gets a .bss style noload, alloc, no contents section. All others get a noload, noalloc - section. */ - if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) + section. Unlike a .bss style section, if a note section is + marked as NOLOAD, also clear SEC_ALLOC. */ + if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour + && elf_section_type (section) != SHT_NOTE) flags &= ~SEC_HAS_CONTENTS; else flags &= ~SEC_ALLOC; diff --git a/ld/testsuite/ld-elf/pr32787.d b/ld/testsuite/ld-elf/pr32787.d new file mode 100644 index 0000000..8d07b8d --- /dev/null +++ b/ld/testsuite/ld-elf/pr32787.d @@ -0,0 +1,9 @@ +#source: start.s +#ld: --build-id -T pr32787.t +#nm: -n +# The following targets don't support --build-id. +#xfail: [uses_genelf] + +#... +.* start +#pass diff --git a/ld/testsuite/ld-elf/pr32787.t b/ld/testsuite/ld-elf/pr32787.t new file mode 100644 index 0000000..cf5aeb1 --- /dev/null +++ b/ld/testsuite/ld-elf/pr32787.t @@ -0,0 +1,12 @@ +SECTIONS { + . = SIZEOF_HEADERS; + .text : { + *(.text) + } + .data : { + _data_start = .; + *(.data) + } + .note.gnu.build-id (NOLOAD) : { *(.note.gnu.build-id) } + /DISCARD/ : { *(*) } +} |