summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2010-06-14 17:44:38 -0700
committerRoland McGrath <[email protected]>2010-06-14 17:44:38 -0700
commitec86e5fa64540a6bb027b0dd505322455968c8e2 (patch)
treea507db79de6100f0ca8fb760192f7886bdf420f2
parentd763578420c9570a882f542d9ec8eb0b5974dffe (diff)
Fix unstrip for modifying file in place.
-rw-r--r--src/ChangeLog5
-rw-r--r--src/unstrip.c12
-rw-r--r--tests/ChangeLog4
-rwxr-xr-xtests/run-unstrip-test.sh13
4 files changed, 31 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ab33cbf2..3c8c33c7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-14 Roland McGrath <[email protected]>
+
+ * unstrip.c (copy_elided_sections): Make sure all sections' data have
+ been read in before we write anything out.
+
2010-06-04 Roland McGrath <[email protected]>
* unstrip.c (update_shdr): New function.
diff --git a/src/unstrip.c b/src/unstrip.c
index 59d3ead5..443cd620 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -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),
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 60b0847a..0176fb49 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2010-06-04 Roland McGrath <[email protected]>
+
+ * run-unstrip-test.sh: Also test modifying the file in place.
+
2010-04-22 Roland McGrath <[email protected]>
* addrcfi.c (handle_cfi): Fix function name in error message.
diff --git a/tests/run-unstrip-test.sh b/tests/run-unstrip-test.sh
index 8f0fc698..b9959a10 100755
--- a/tests/run-unstrip-test.sh
+++ b/tests/run-unstrip-test.sh
@@ -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