]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
strip: Also handle gnu compressed debug sections with --reloc-debug-sections
authorMark Wielaard <mark@klomp.org>
Fri, 9 Nov 2018 14:19:07 +0000 (15:19 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 13 Nov 2018 15:53:40 +0000 (16:53 +0100)
Check whether a section was gnu compressed and decompress it first
before trying to resolve relocations. Recompress it afterwards.

This found a bug in elf_compress_gnu which would use the "raw" file
contents even if the user had just created the section (copying over
the section from the original input file).

Add compressed ET_REL tests to run-strip-reloc.sh testcase.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf_compress_gnu.c
src/ChangeLog
src/strip.c
tests/ChangeLog
tests/run-strip-reloc.sh

index 2675ba559a605d2ab97b954c0161c148e05beea6..ab078cb5aeb22c90aa91100abe11edb5639e08cf 100644 (file)
@@ -1,3 +1,7 @@
+2018-11-09  Mark Wielaard  <mark@klomp.org>
+
+       * elf_compress_gnu.c (elf_compress_gnu): Use elf_getdata.
+
 2018-11-12  Mark Wielaard  <mark@klomp.org>
 
        * elf-knowledge.c (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX): New define.
index 198dc7d5b47a08351d9cc345d0ffb12df0c26634..1ecd6a08edc6c7e7061012de0ca4f78e91135a84 100644 (file)
@@ -144,9 +144,10 @@ elf_compress_gnu (Elf_Scn *scn, int inflate, unsigned int flags)
   else if (inflate == 0)
     {
       /* In theory the user could have constucted a compressed section
-        by hand.  But we always just take the rawdata directly and
-        decompress that.  */
-      Elf_Data *data = elf_rawdata (scn, NULL);
+        by hand.  And in practice they do. For example when copying
+        a section from one file to another using elf_newdata. So we
+        have to use elf_getdata (not elf_rawdata).  */
+      Elf_Data *data = elf_getdata (scn, NULL);
       if (data == NULL)
        return -1;
 
index f014de8ff589091f4d1b56fc78d26fad215e0b2e..7eecfcb5cf81f7ffaa9f6b8119b777fa846a25ec 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-09  Mark Wielaard  <mark@klomp.org>
+
+       * strip.c (remove_debug_relocations): Check if section is gnu
+       compressed and decompress and recompress it.
+
 2018-11-12  Mark Wielaard  <mark@klomp.org>
 
        * elflint.c (check_note_data): Recognize NT_GNU_BUILD_ATTRIBUTE_OPEN
index e953c4d5f3c3dcccb83f772c03e96d0cf1497686..15180737aa6bdca47931b06e69c3b5da91f0e282 100644 (file)
@@ -485,12 +485,22 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr,
             (and recompress if necessary at the end).  */
          GElf_Chdr tchdr;
          int tcompress_type = 0;
-         if (gelf_getchdr (tscn, &tchdr) != NULL)
+         bool is_gnu_compressed = false;
+         if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
            {
-             tcompress_type = tchdr.ch_type;
-             if (elf_compress (tscn, 0, 0) != 1)
+             is_gnu_compressed = true;
+             if (elf_compress_gnu (tscn, 0, 0) != 1)
                INTERNAL_ERROR (fname);
            }
+         else
+           {
+             if (gelf_getchdr (tscn, &tchdr) != NULL)
+               {
+                 tcompress_type = tchdr.ch_type;
+                 if (elf_compress (tscn, 0, 0) != 1)
+                   INTERNAL_ERROR (fname);
+               }
+           }
 
          Elf_Data *tdata = elf_getdata (tscn, NULL);
          if (tdata == NULL || tdata->d_buf == NULL
@@ -686,9 +696,16 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr,
          shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize;
          gelf_update_shdr (scn, shdr);
 
-         if (tcompress_type != 0)
-           if (elf_compress (tscn, tcompress_type, ELF_CHF_FORCE) != 1)
-             INTERNAL_ERROR (fname);
+         if (is_gnu_compressed)
+           {
+             if (elf_compress_gnu (tscn, 1, ELF_CHF_FORCE) != 1)
+               INTERNAL_ERROR (fname);
+           }
+         else if (tcompress_type != 0)
+           {
+             if (elf_compress (tscn, tcompress_type, ELF_CHF_FORCE) != 1)
+               INTERNAL_ERROR (fname);
+           }
        }
     }
 }
index e6a9bde45b722dc864c631a74f78579033f9d4c7..514229b76044ed4aa69b9e37dccabc431907611a 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-09  Mark Wielaard  <mark@klomp.org>
+
+       * run-strip-reloc.sh: Also test testfile-debug-rel-ppc64-z.o
+       testfile-debug-rel-ppc64-g.o.
+
 2018-11-12  Mark Wielaard  <mark@klomp.org>
 
        * run-readelf-n.sh: Add testfile-annobingroup.o test.
index 6f299aba2c1d15b2ad14d36073c4bf1102a838b0..0c6b1c2cdae4872ac574aa495d1f072fb60591f9 100755 (executable)
@@ -139,4 +139,10 @@ runtest strip-compressed.o 1
 testfiles testfile-debug-rel-ppc64.o
 runtest testfile-debug-rel-ppc64.o 1
 
+testfiles testfile-debug-rel-ppc64-z.o
+runtest testfile-debug-rel-ppc64-z.o 1
+
+testfiles testfile-debug-rel-ppc64-g.o
+runtest testfile-debug-rel-ppc64-g.o 1
+
 exit $status