]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix unstrip for modifying file in place.
authorRoland McGrath <roland@redhat.com>
Tue, 15 Jun 2010 00:44:38 +0000 (17:44 -0700)
committerRoland McGrath <roland@redhat.com>
Tue, 15 Jun 2010 00:44:38 +0000 (17:44 -0700)
src/ChangeLog
src/unstrip.c
tests/ChangeLog
tests/run-unstrip-test.sh

index ab33cbf2002fac54cddc15e1a0527cdc0d39bc62..3c8c33c72b3bb644dd1bed5e9652fecad8696d38 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-14  Roland McGrath  <roland@redhat.com>
+
+       * unstrip.c (copy_elided_sections): Make sure all sections' data have
+       been read in before we write anything out.
+
 2010-06-04  Roland McGrath  <roland@redhat.com>
 
        * unstrip.c (update_shdr): New function.
index 59d3ead576e07ada4ca5207a4fabb1df396933a9..443cd620d3cc04a902f8164864e825473aa24368 100644 (file)
@@ -1781,6 +1781,15 @@ more sections in stripped file than debug file -- arguments reversed?"));
            GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
            ELF_CHECK (shdr != NULL, _("cannot get section header: %s"));
 
+           /* We must make sure we have read in the data of all sections
+              beforehand and marked them to be written out.  When we're
+              modifying the existing file in place, we might overwrite
+              this part of the file before we get to handling the section.  */
+
+           ELF_CHECK (elf_flagdata (elf_getdata (scn, NULL),
+                                    ELF_C_SET, ELF_F_DIRTY),
+                      _("cannot read section data: %s"));
+
            if (skip_reloc
                && (shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA))
              continue;
@@ -1813,7 +1822,8 @@ more sections in stripped file than debug file -- arguments reversed?"));
 
            placed[i] = true;
          }
-    } while (skip_reloc);
+    }
+  while (skip_reloc);
 
   if (stripped_ehdr->e_phnum > 0)
     ELF_CHECK (gelf_newphdr (unstripped, stripped_ehdr->e_phnum),
index 60b0847a973563d0280a4ff009fd199182d726c1..0176fb4951bd1de47b6039eca2d7336a6c3e4cf9 100644 (file)
@@ -1,3 +1,7 @@
+2010-06-04  Roland McGrath  <roland@redhat.com>
+
+       * run-unstrip-test.sh: Also test modifying the file in place.
+
 2010-04-22  Roland McGrath  <roland@redhat.com>
 
        * addrcfi.c (handle_cfi): Fix function name in error message.
index 8f0fc69885ce7700a81b5801e294cc3ca78cdb3a..b9959a109c84e0957b56999e8a282282879defe4 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2007 Red Hat, Inc.
+# Copyright (C) 2007-2010 Red Hat, Inc.
 # This file is part of Red Hat elfutils.
 #
 # Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -30,7 +30,7 @@ stripped=${stripped:-testfile17}
 debugfile=${debugfile:-${stripped}.debug}
 
 testfiles $original $stripped $debugfile
-tempfiles testfile.unstrip
+tempfiles testfile.unstrip testfile.inplace
 
 # These are old reference output from run-test-strip6.sh, when
 # strip left the .debug file with unchanged sh_size in
@@ -40,3 +40,12 @@ tempfiles testfile.unstrip
 testrun ../src/unstrip -o testfile.unstrip $stripped $debugfile
 
 testrun ../src/elfcmp --hash-inexact $original testfile.unstrip
+
+# Also test modifying the file in place.
+
+rm -f testfile.inplace
+cp $debugfile testfile.inplace
+chmod 644 testfile.inplace
+testrun ../src/unstrip $stripped testfile.inplace
+
+testrun ../src/elfcmp --hash-inexact $original testfile.inplace