summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-12-31 23:03:20 +0100
committerMark Wielaard <mjw@redhat.com>2016-01-05 08:55:44 +0100
commit29ee512fb8a71b0d22065c369a2117ff758bdf5e (patch)
treed73bf06adc50534b8e590e85cd6ac81f0f4deaa9
parent193396a9e2d564a35e1e6c5584276d8e88abf2ed (diff)
downloadelfutils-29ee512fb8a71b0d22065c369a2117ff758bdf5e.tar.gz
elfutils-29ee512fb8a71b0d22065c369a2117ff758bdf5e.tar.xz
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>
-rw-r--r--tests/ChangeLog7
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/elfstrmerge.c9
-rwxr-xr-xtests/run-elfstrmerge-test.sh40
4 files changed, 56 insertions, 4 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b8d1d95..933f7c9 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-08 Jose E. Marchesi <jose.marchesi@oracle.com>
* run-backtrace-core-sparc.sh: New file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8fca801..54d88f2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -80,7 +80,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 \
@@ -167,7 +167,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