]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ELF: SHF_MERGE vs SHT_NOBITS
authorJan Beulich <jbeulich@suse.com>
Mon, 18 Nov 2024 10:36:30 +0000 (11:36 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 18 Nov 2024 10:36:30 +0000 (11:36 +0100)
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.

bfd/merge.c
gas/config/obj-elf.c

index a4b928d98750564cffbada84f46992926819b558..947f2ce78f24d9fe6338cd73716f9968e0b218e5 100644 (file)
@@ -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;
 
index 4f09b8dc87cb48a55694f769308e9a4c3ec45d0e..deb902e5a5539d16a046e69e9c6d70d6ccc3d4fc 100644 (file)
@@ -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;