From: Jan Beulich Date: Mon, 18 Nov 2024 10:36:30 +0000 (+0100) Subject: ELF: SHF_MERGE vs SHT_NOBITS X-Git-Tag: gdb-16-branchpoint~404 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70ab7e0acfaf1cb32dfc184794e28408620a34f9;p=thirdparty%2Fbinutils-gdb.git ELF: SHF_MERGE vs SHT_NOBITS bfd/merge.c puts in quite some effort to track mergable sections. That's all wasted for sections which don't have contents, as for them _bfd_write_merged_section() will never be called. With the combination not having any useful effect, also warn about this in gas. --- diff --git a/bfd/merge.c b/bfd/merge.c index a4b928d9875..947f2ce78f2 100644 --- a/bfd/merge.c +++ b/bfd/merge.c @@ -627,6 +627,7 @@ _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, if (sec->size == 0 || (sec->flags & SEC_EXCLUDE) != 0 + || (sec->flags & SEC_HAS_CONTENTS) == 0 || sec->entsize == 0) return true; diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index 4f09b8dc87c..deb902e5a55 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -1346,6 +1346,9 @@ obj_elf_section (int push) attr &= ~SHF_MERGE; } + if ((attr & SHF_MERGE) != 0 && type == SHT_NOBITS) + as_warn (_("bogus SHF_MERGE for SHT_NOBITS section")); + if ((attr & SHF_LINK_ORDER) != 0 && *input_line_pointer == ',') { ++input_line_pointer;