summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2017-06-07 14:05:36 +0200
committerMark Wielaard <[email protected]>2017-06-14 14:51:33 +0200
commite0b3232e9a0bc8215ca1be29b1ec6df43811eb87 (patch)
tree28fc9df73820d6e0475a5a5cc6cc34a84e6b64f7
parent660aafcf78818424248faccf2ccab4ac9deee582 (diff)
strip: Make sure old .shstrab is removed when eu-strip recreates it.
Although we always recreate the .shstrtab section for the new output file we never explicitly assumed it could be removed. It might not be possible to remove it when the section string table is shared with a symbol table. But if it is removable we should (and recreate it for the new section list). Regression introduced in commit elfutils-0.163-33-gdf7dfab. "Handle merged strtab/shstrtab string tables in strip and unstrip." Add extra testcase to explicitly check for this case. https://sourceware.org/bugzilla/show_bug.cgi?id=21525 Signed-off-by: Mark Wielaard <[email protected]>
-rw-r--r--src/ChangeLog4
-rw-r--r--src/strip.c16
-rw-r--r--tests/ChangeLog4
-rwxr-xr-xtests/run-strip-test.sh8
4 files changed, 26 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index cbb77fc8..6ac0ef2d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-06 Mark Wielaard <[email protected]>
+
+ * strip.c (handle_elf): Assume e_shstrndx section can be removed.
+
2017-04-20 Ulf Hermann <[email protected]>
* readelf.c: Include strings.h.
diff --git a/src/strip.c b/src/strip.c
index f7474418..11b2a379 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -711,11 +711,13 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
in the sh_link or sh_info element it cannot be removed either
*/
for (cnt = 1; cnt < shnum; ++cnt)
- /* Check whether the section can be removed. */
+ /* Check whether the section can be removed. Since we will create
+ a new .shstrtab assume it will be removed too. */
if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
- : ebl_section_strip_p (ebl, ehdr, &shdr_info[cnt].shdr,
- shdr_info[cnt].name, remove_comment,
- remove_debug))
+ : (ebl_section_strip_p (ebl, ehdr, &shdr_info[cnt].shdr,
+ shdr_info[cnt].name, remove_comment,
+ remove_debug)
+ || cnt == ehdr->e_shstrndx))
{
/* For now assume this section will be removed. */
shdr_info[cnt].idx = 0;
@@ -1062,8 +1064,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
}
/* Test whether we are doing anything at all. */
- if (cnt == idx)
- /* Nope, all removable sections are already gone. */
+ if (cnt == idx
+ || (cnt == idx + 1 && shdr_info[ehdr->e_shstrndx].idx == 0))
+ /* Nope, all removable sections are already gone. Or the only section
+ we would remove is the .shstrtab section which we will add again. */
goto fail_close;
/* Create the reference to the file with the debug info. */
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 43b5bd8a..a7b20224 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-06 Mark Wielaard <[email protected]>
+
+ * run-strip-test.sh: Test strip -g doesn't introduce extra .shstrtab.
+
2017-05-30 Mark Wielaard <[email protected]>
* run-backtrace-fp-core-ppc64le.sh: New test.
diff --git a/tests/run-strip-test.sh b/tests/run-strip-test.sh
index 42aa9888..280814e6 100755
--- a/tests/run-strip-test.sh
+++ b/tests/run-strip-test.sh
@@ -49,6 +49,14 @@ testrun ${abs_top_builddir}/src/unstrip -o testfile.unstrip testfile.temp testfi
testrun ${abs_top_builddir}/src/elfcmp --hash-inexact $original testfile.unstrip
}
+# test strip -g
+testrun ${abs_top_builddir}/src/strip -g -o testfile.temp $original
+
+# Buggy eu-strip created multiple .shstrtab sections
+shstrtab_SECS=$(testrun ${abs_top_builddir}/src/readelf -S testfile.temp | grep '.shstrtab' | wc --lines)
+test $shstrtab_SECS -eq 1 ||
+ { echo "*** failure not just one '.shstrtab' testfile.temp ($shstrtab_SECS)"; status=1; }
+
# Now strip in-place and make sure it is smaller.
SIZE_original=$(stat -c%s $original)
testrun ${abs_top_builddir}/src/strip $original