This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Thu, 31 Dec 2015 23:08:12 +0100
- Subject: [PATCH] tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
Old linkers might have created an STT_SECTION symbol for the section
header string table section, which isn't actually used. For now just
warn about such symbols. If such a symbol would actually really be used
(but why?) then we would have to handle it by removing it and rewriting
the symbol table.
This is a testsuite only change, but includes an extra test with files
that have such STT_SECTION symbols to make sure it will be handled in
case we "upgrade" the elfstrmerge test to a real utility.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
tests/ChangeLog | 7 +++++++
tests/Makefile.am | 4 ++--
tests/elfstrmerge.c | 9 +++++++--
tests/run-elfstrmerge-test.sh | 40 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 56 insertions(+), 4 deletions(-)
create mode 100755 tests/run-elfstrmerge-test.sh
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b6cf28d..087e22f 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2015-12-31 Mark Wielaard <mjw@redhat.com>
+
+ * elfstrmerge.c (main): Warn about STT_SECTION symbol for shstrhndx.
+ * run-elfstrmerge-test.sh: New test.
+ * Makefile.am (TESTS): Add run-elfstrmerge-test.sh
+ (EXTRA_DIST): Likewise.
+
2015-12-16 Mark Wielaard <mjw@redhat.com>
* run-compress-test.sh: New test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d48393..d67fc7f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -81,7 +81,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-strip-test9.sh run-strip-test10.sh \
run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \
run-unstrip-test.sh run-unstrip-test2.sh \
- run-unstrip-test3.sh run-unstrip-M.sh \
+ run-unstrip-test3.sh run-unstrip-M.sh run-elfstrmerge-test.sh \
run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \
run-elflint-test.sh run-elflint-self.sh run-ranlib-test.sh \
run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \
@@ -171,7 +171,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-unstrip-test.sh run-unstrip-test2.sh \
testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \
testfile-info-link.stripped.bz2 run-unstrip-test3.sh \
- run-unstrip-M.sh \
+ run-unstrip-M.sh run-elfstrmerge-test.sh \
run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \
run-ranlib-test3.sh run-ranlib-test4.sh \
run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 6b927c8..4149ca6 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -518,8 +518,13 @@ main (int argc, char **argv)
if (gelf_getsym (data, i, &sym) == NULL)
fail_elf_idx ("Couldn't get symbol", fname, i);
- if (sym.st_shndx != SHN_UNDEF
- && sym.st_shndx < SHN_LORESERVE)
+ if (GELF_ST_TYPE (sym.st_info) == STT_SECTION
+ && sym.st_shndx == shdrstrndx)
+ fprintf (stderr, "WARNING:"
+ " symbol table [%zd] contains section symbol %zd"
+ " for old shdrstrndx %zd\n", ndx, i, shdrstrndx);
+ else if (sym.st_shndx != SHN_UNDEF
+ && sym.st_shndx < SHN_LORESERVE)
sym.st_shndx = newsecndx (sym.st_shndx, "section", ndx,
"symbol", i);
if (update_name && sym.st_name != 0)
diff --git a/tests/run-elfstrmerge-test.sh b/tests/run-elfstrmerge-test.sh
new file mode 100755
index 0000000..d08b6fc
--- /dev/null
+++ b/tests/run-elfstrmerge-test.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2015 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
+
+# Merge string tables of file and check result with elflint.
+testrun_elfcompress()
+{
+ testfile="$1"
+ testfiles ${testfile}
+
+ mergedfile="${testfile}.merged"
+ tempfiles ${mergedfile}
+
+ echo "merging string tables ${testfile} -> ${mergedfile}"
+ testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile}
+ testrun ${abs_top_builddir}/src/elflint --gnu-ld ${mergedfile}
+}
+
+# Random ELF32 testfile with extra STT_SECTION symbols
+testrun_elfcompress testfile4
+
+# Random ELF64 testfile with extra STT_SECTION symbols
+testrun_elfcompress testfile12
+
+exit 0
--
2.5.0