]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
strip: Ignore --reloc-debug-sections-only for non-ET_REL files.
authorAaron Merey <amerey@redhat.com>
Tue, 5 Nov 2024 22:41:26 +0000 (17:41 -0500)
committerAaron Merey <amerey@redhat.com>
Tue, 5 Nov 2024 22:41:26 +0000 (17:41 -0500)
strip --reloc-debug-sections-only is expected to be a no-op for
non-ET_REL files.  This was not enforced in the code.  Sections
were copied over to a new output file and normally its contents
would be identical to the input file.

However the output file is not identical to a non-ET_REL input
file if the linker organized sections such that the indices of
SHF_ALLOC sections are not in a contigous group.

In this case strip will modify sections in order to keep all SHF_ALLOC
sections in a contiguous group.

Fix this by ignoring --reloc-debug-sections-only for non-ET_REL files.

https://sourceware.org/bugzilla/show_bug.cgi?id=32253

Signed-off-by: Aaron Merey <amerey@redhat.com>
src/strip.c

index 403e0f6fbe723dd1f9e23ea6167819e08a56d8bf..3812fb17a3b865381f97baf3e601116a7f272a1b 100644 (file)
@@ -1139,6 +1139,13 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 
   if (reloc_debug_only)
     {
+      if (ehdr->e_type != ET_REL)
+       {
+         /* Only ET_REL files can have debug relocations to remove.  */
+         error (0, 0, _("Ignoring --reloc-debug-sections-only for " \
+                        "non-ET_REL file '%s'"), fname);
+         goto fail_close;
+       }
       if (handle_debug_relocs (elf, ebl, newelf, ehdr, fname, shstrndx,
                               &lastsec_offset, &lastsec_size) != 0)
        {