[binutils-gdb] ELF: SHF_MERGE vs SHT_NOBITS

Jan Beulich jbeulich@sourceware.org
Mon Nov 18 10:38:52 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=70ab7e0acfaf1cb32dfc184794e28408620a34f9

commit 70ab7e0acfaf1cb32dfc184794e28408620a34f9
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Nov 18 11:36:30 2024 +0100

    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:
---
 bfd/merge.c          | 1 +
 gas/config/obj-elf.c | 3 +++
 2 files changed, 4 insertions(+)

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;


More information about the Binutils-cvs mailing list