0.169-3 dup-shstrtab and strip-empty fixes.

- Add elfutils-0.169-dup-shstrtab.patch
- Add elfutils-0.169-strip-empty.patch
This commit is contained in:
Mark Wielaard 2017-06-07 21:52:20 +02:00
parent d0b10ff230
commit 4341caedce
3 changed files with 342 additions and 1 deletions

View File

@ -0,0 +1,98 @@
commit e014cbba4e16f717807bca88512d2875a1c17ee4
Author: Mark Wielaard <mark@klomp.org>
Date: Wed Jun 7 14:05:36 2017 +0200
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 <mark@klomp.org>
diff --git a/src/ChangeLog b/src/ChangeLog
index cbb77fc..6ac0ef2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-06 Mark Wielaard <mark@klomp.org>
+
+ * strip.c (handle_elf): Assume e_shstrndx section can be removed.
+
2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
* readelf.c: Include strings.h.
diff --git a/src/strip.c b/src/strip.c
index f747441..11b2a37 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 5b0d486..5800946 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-06 Mark Wielaard <mark@klomp.org>
+
+ * run-strip-test.sh: Test strip -g doesn't introduce extra .shstrtab.
+
2017-02-13 Ulf Hermann <ulf.hermann@qt.io>
Mark Wielaard <mark@klomp.org>
diff --git a/tests/run-strip-test.sh b/tests/run-strip-test.sh
index 42aa988..280814e 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

View File

@ -0,0 +1,235 @@
commit b065d4a401e2120c11c92357b213a85e6d70f300
Author: Mark Wielaard <mark@klomp.org>
Date: Wed Jun 7 20:32:38 2017 +0200
strip: Don't generate empty output file when nothing to do.
If there was nothing to do strip would skip generating a separate
debug file if one was requested, but it would also not finish the
creation of a new output file (with the non-stripped sections).
Also if there was an error any partially created output would be kept.
Make sure that when the -o output file option is given we always generate
a complete output file (except on error). Also make sure that when the -f
debug file option is given it is only generated when it is not empty.
Add testcase run-strip-nothing.sh that tests the various combinations.
https://sourceware.org/bugzilla/show_bug.cgi?id=21522
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/src/ChangeLog b/src/ChangeLog
index 6ac0ef2..e19122e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-07 Mark Wielaard <mark@klomp.org>
+
+ * strip.c (handle_elf): Introduce new handle_elf boolean. Use it to
+ determine whether to create an output and/or debug file. Remove new
+ output file on error.
+
2017-06-06 Mark Wielaard <mark@klomp.org>
* strip.c (handle_elf): Assume e_shstrndx section can be removed.
diff --git a/src/strip.c b/src/strip.c
index 11b2a37..2bf95f9 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1063,15 +1063,17 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
shdr_info[cnt].se = dwelf_strtab_add (shst, shdr_info[cnt].name);
}
- /* Test whether we are doing anything at all. */
- 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. */
- if (debug_fname != NULL && !remove_shdrs)
+ /* Test whether we are doing anything at all. Either all removable
+ sections are already gone. Or the only section we would remove is
+ the .shstrtab section which we would add again. */
+ bool removing_sections = !(cnt == idx
+ || (cnt == idx + 1
+ && shdr_info[ehdr->e_shstrndx].idx == 0));
+ if (output_fname == NULL && !removing_sections)
+ goto fail_close;
+
+ /* Create the reference to the file with the debug info (if any). */
+ if (debug_fname != NULL && !remove_shdrs && removing_sections)
{
/* Add the section header string table section name. */
shdr_info[cnt].se = dwelf_strtab_add_len (shst, ".gnu_debuglink", 15);
@@ -1759,7 +1761,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* Remove any relocations between debug sections in ET_REL
for the debug file when requested. These relocations are always
zero based between the unallocated sections. */
- if (debug_fname != NULL && reloc_debug && ehdr->e_type == ET_REL)
+ if (debug_fname != NULL && removing_sections
+ && reloc_debug && ehdr->e_type == ET_REL)
{
scn = NULL;
cnt = 0;
@@ -1997,7 +2000,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* Now that we have done all adjustments to the data,
we can actually write out the debug file. */
- if (debug_fname != NULL)
+ if (debug_fname != NULL && removing_sections)
{
/* Finally write the file. */
if (unlikely (elf_update (debugelf, ELF_C_WRITE) == -1))
@@ -2230,7 +2233,11 @@ cannot set access and modification date of '%s'"),
/* Close the file descriptor if we created a new file. */
if (output_fname != NULL)
- close (fd);
+ {
+ close (fd);
+ if (result != 0)
+ unlink (output_fname);
+ }
return result;
}
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 5800946..5550eac 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-07 Mark Wielaard <mark@klomp.org>
+
+ * run-strip-nothing.sh: New test.
+ * Makefile.am (TESTS): Add run-strip-nothing.sh.
+ (EXTRA_DIST): Likewise.
+
2017-06-06 Mark Wielaard <mark@klomp.org>
* run-strip-test.sh: Test strip -g doesn't introduce extra .shstrtab.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3a12fe3..28e997c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -81,6 +81,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-strip-test3.sh run-strip-test4.sh run-strip-test5.sh \
run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \
run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \
+ run-strip-nothing.sh \
run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \
run-strip-nobitsalign.sh \
run-unstrip-test.sh run-unstrip-test2.sh run-unstrip-test3.sh \
@@ -174,6 +175,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \
run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \
+ run-strip-nothing.sh \
run-strip-strmerge.sh run-strip-nobitsalign.sh \
testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \
run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
diff --git a/tests/run-strip-nothing.sh b/tests/run-strip-nothing.sh
new file mode 100755
index 0000000..e80bd90
--- /dev/null
+++ b/tests/run-strip-nothing.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2017 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# If there is nothing to strip then -o output should be identical to input.
+# And there should not be an (empty) -f debug file.
+
+tempfiles a.out strip.out debug.out
+
+# Create no-debug a.out.
+echo "int main() { return 1; }" | gcc -xc -
+
+# strip to file
+testrun ${abs_top_builddir}/src/strip -g -o strip.out ||
+ { echo "*** failed to strip -g -o strip.out a.out"; exit -1; }
+
+testrun ${abs_top_builddir}/src/elfcmp a.out strip.out ||
+ { echo "*** failed strip.out different from a.out"; exit -1; }
+
+# strip original
+testrun ${abs_top_builddir}/src/strip -g ||
+ { echo "*** failed to strip -g a.out"; exit -1; }
+
+testrun ${abs_top_builddir}/src/elfcmp strip.out a.out ||
+ { echo "*** failed a.out different from strip.out"; exit -1; }
+
+# strip to file with debug file
+testrun ${abs_top_builddir}/src/strip -g -o strip.out -f debug.out ||
+ { echo "*** failed to strip -g -o strip.out -f debug.out a.out"; exit -1; }
+
+testrun ${abs_top_builddir}/src/elfcmp a.out strip.out ||
+ { echo "*** failed strip.out different from a.out (with debug)"; exit -1; }
+
+test ! -f debug.out ||
+ { echo "*** failed strip.out and debug.out exist"; exit -1; }
+
+# strip original with debug file
+testrun ${abs_top_builddir}/src/strip -g -f debug.out ||
+ { echo "*** failed to strip -g -f debug.out a.out"; exit -1; }
+
+testrun ${abs_top_builddir}/src/elfcmp strip.out a.out ||
+ { echo "*** failed a.out different from strip.out (with debug)"; exit -1; }
+
+test ! -f debug.out ||
+ { echo "*** failed a.out and debug.out exist"; exit -1; }
+
+exit 0
--- elfutils-0.169/tests/Makefile.in.orig 2017-06-07 21:48:55.475994222 +0200
+++ elfutils-0.169/tests/Makefile.in 2017-06-07 21:49:20.441430261 +0200
@@ -138,8 +138,8 @@
run-strip-test.sh run-strip-test2.sh run-strip-test3.sh \
run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
run-strip-test7.sh run-strip-test8.sh run-strip-test9.sh \
- run-strip-test10.sh run-strip-test11.sh run-strip-groups.sh \
- run-strip-reloc.sh run-strip-strmerge.sh \
+ run-strip-test10.sh run-strip-test11.sh run-strip-nothing.sh \
+ run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \
run-strip-nobitsalign.sh run-unstrip-test.sh \
run-unstrip-test2.sh run-unstrip-test3.sh run-unstrip-test4.sh \
run-unstrip-M.sh run-elfstrmerge-test.sh run-ecp-test.sh \
@@ -1046,6 +1046,7 @@
run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \
run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \
+ run-strip-nothing.sh \
run-strip-strmerge.sh run-strip-nobitsalign.sh \
testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \
run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
@@ -2332,6 +2333,13 @@
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+run-strip-nothing.sh.log: run-strip-nothing.sh
+ @p='run-strip-nothing.sh'; \
+ b='run-strip-nothing.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
run-strip-groups.sh.log: run-strip-groups.sh
@p='run-strip-groups.sh'; \

View File

@ -1,7 +1,7 @@
Name: elfutils Name: elfutils
Summary: A collection of utilities and DSOs to handle ELF files and DWARF data Summary: A collection of utilities and DSOs to handle ELF files and DWARF data
Version: 0.169 Version: 0.169
%global baserelease 2 %global baserelease 3
URL: http://elfutils.org/ URL: http://elfutils.org/
%global source_url ftp://sourceware.org/pub/elfutils/%{version}/ %global source_url ftp://sourceware.org/pub/elfutils/%{version}/
License: GPLv3+ and (GPLv2+ or LGPLv3+) License: GPLv3+ and (GPLv2+ or LGPLv3+)
@ -23,6 +23,8 @@ Source: %{?source_url}%{name}-%{version}.tar.bz2
Patch1: elfutils-0.169-ppc64-fallback-unwinder.patch Patch1: elfutils-0.169-ppc64-fallback-unwinder.patch
Source1: backtrace.ppc64le.fp.exec.bz2 Source1: backtrace.ppc64le.fp.exec.bz2
Source2: backtrace.ppc64le.fp.core.bz2 Source2: backtrace.ppc64le.fp.core.bz2
Patch2: elfutils-0.169-dup-shstrtab.patch
Patch3: elfutils-0.169-strip-empty.patch
Requires: elfutils-libelf%{depsuffix} = %{version}-%{release} Requires: elfutils-libelf%{depsuffix} = %{version}-%{release}
Requires: elfutils-libs%{depsuffix} = %{version}-%{release} Requires: elfutils-libs%{depsuffix} = %{version}-%{release}
@ -175,6 +177,8 @@ profiling) of processes.
# Apply patches # Apply patches
%patch1 -p1 -b .ppc64_unwind %patch1 -p1 -b .ppc64_unwind
cp %SOURCE1 %SOURCE2 tests/ cp %SOURCE1 %SOURCE2 tests/
%patch2 -p1 -b .shstrtab_dup
%patch3 -p1 -b .strip_empty
find . -name \*.sh ! -perm -0100 -print | xargs chmod +x find . -name \*.sh ! -perm -0100 -print | xargs chmod +x
@ -305,6 +309,10 @@ rm -rf ${RPM_BUILD_ROOT}
%endif %endif
%changelog %changelog
* Wed Jun 7 2017 Mark Wielaard <mjw@fedoraproject.org> - 0.169-3
- Add elfutils-0.169-dup-shstrtab.patch
- Add elfutils-0.169-strip-empty.patch
* Tue May 30 2017 Mark Wielaard <mjw@fedoraproject.org> - 0.169-2 * Tue May 30 2017 Mark Wielaard <mjw@fedoraproject.org> - 0.169-2
- Add ppc64 fallback unwinder. - Add ppc64 fallback unwinder.