]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
authorMark Wielaard <mjw@redhat.com>
Thu, 31 Dec 2015 22:03:20 +0000 (23:03 +0100)
committerMark Wielaard <mjw@redhat.com>
Tue, 5 Jan 2016 07:55:44 +0000 (08:55 +0100)
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
tests/Makefile.am
tests/elfstrmerge.c
tests/run-elfstrmerge-test.sh [new file with mode: 0755]

index b8d1d954983fc6ea2bfad3dc61ef35cc0527e5c5..933f7c9290eb1c5c6fd44a4132e625f2e43ee7bf 100644 (file)
@@ -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.
index 8fca80140463dae4d498a5672c6454b0d4cd2632..54d88f257406301ae83df7ed5d3d72a118462067 100644 (file)
@@ -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 \
index 6b927c83a2845a70ff4e892660e07382b00552a8..4149ca6e71e367225a8738c002863bb420205682 100644 (file)
@@ -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 (executable)
index 0000000..d08b6fc
--- /dev/null
@@ -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