]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH.
authorMark Wielaard <mjw@redhat.com>
Tue, 9 Feb 2016 13:18:49 +0000 (14:18 +0100)
committerMark Wielaard <mjw@redhat.com>
Mon, 15 Feb 2016 22:45:19 +0000 (23:45 +0100)
GCC6 -Wduplicated-cond found the following issue:

elflint.c: In function ‘compare_hash_gnu_hash’:
elflint.c:2483:34: error: duplicated ‘if’ condition [-Werror=duplicated-cond]
   else if (hash_shdr->sh_entsize == sizeof (Elf64_Word))
            ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
elflint.c:2448:29: note: previously used here
   if (hash_shdr->sh_entsize == sizeof (Elf32_Word))
       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

Which is correct, a Word in both Elf32 and Elf64 files is 4 bytes.
We meant to check for sizeof (Elf64_Xword) which is 8 bytes.

Also fix the section index and name in the error message.

The reason we probably didn't see this issue before is that SHT_HASH
sections really always should have sh_entsize of 4 even on 64bit arches.
There are however a couple of arches with mistakes in their sysv ABI.
See libelf/common.h. This also would only be triggered if on such an
architectures when the ELF file would have both a SHT_HASH and SHT_GNU_HASH
section and elflint would try to compare those sections.

Add an example testfile-s390x-hash-both to run-elflint-test.sh.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/elflint.c
tests/ChangeLog
tests/Makefile.am
tests/run-elflint-test.sh
tests/testfile-s390x-hash-both.bz2 [new file with mode: 0755]

index 707c271770da8abebf5878f59224bee90dfde7c0..e4b17d6233d1eac6f51732a1b8e2fbf5ae99414e 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-09  Mark Wielaard  <mjw@redhat.com>
+
+       * elflint.c (compare_hash_gnu_hash): Check hash sh_entsize against
+       sizeof (Elf64_Xword). Correct invalid sh_entsize error message
+       section idx and name.
+
 2016-01-13  Mark Wielaard  <mjw@redhat.com>
 
        * elflint.c (check_elf_header): Recognize ELFOSABI_FREEBSD.
index eae776143fcc604d0ab6dc8e9445770802a2d632..15b12f6f5a3ec3c36dc75a325156edff09181909 100644 (file)
@@ -2482,7 +2482,7 @@ hash section [%2zu] '%s' uses too much data\n"),
            }
        }
     }
-  else if (hash_shdr->sh_entsize == sizeof (Elf64_Word))
+  else if (hash_shdr->sh_entsize == sizeof (Elf64_Xword))
     {
       const Elf64_Xword *hasharr = (Elf64_Xword *) hash_data->d_buf;
       if (hash_data->d_size < 2 * sizeof (Elf32_Word))
@@ -2523,7 +2523,7 @@ hash section [%2zu] '%s' uses too much data\n"),
     {
       ERROR (gettext ("\
 hash section [%2zu] '%s' invalid sh_entsize\n"),
-            gnu_hash_idx, gnu_hash_name);
+            hash_idx, hash_name);
       return;
     }
 
index a043ade6de3d4579bc5bd0504bcdc6fbc00ed2a7..bcc296f14dbe728912f1fc5275dcc4c294d36709 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-09  Mark Wielaard  <mjw@redhat.com>
+
+       * testfile-s390x-hash-both.bz2: New testfile.
+       * Makefile.am (EXTRA_DIST): Add testfile-s390x-hash-both.bz2.
+       * run-elflint-test.sh: Add elflint testfile-s390x-hash-both test.
+
 2016-02-04  Mark Wielaard  <mjw@redhat.com>
 
        * run-strip-nobitsalign.sh: New test.
index f3e7c01cacb63a308f545bb1eb5da8a951535d3c..fedcb39d2f0efc448690f812b425f06d1b6957c0 100644 (file)
@@ -236,6 +236,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             testfile56.bz2 testfile57.bz2 testfile58.bz2 \
             run-typeiter.sh testfile59.bz2 \
             run-readelf-d.sh testlib_dynseg.so.bz2 \
+            testfile-s390x-hash-both.bz2 \
             run-readelf-gdb_index.sh testfilegdbindex5.bz2 \
             testfilegdbindex7.bz2 \
             run-readelf-s.sh testfilebazdbg.bz2 testfilebazdyn.bz2 \
index 68615b96158eca0fd6c5358a0dfb3e24d5fa8a35..f3bd9012cd44352a84402441a45e865afadec591 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2005, 2007, 2008 Red Hat, Inc.
+# Copyright (C) 2005, 2007, 2008, 2015 Red Hat, Inc.
 # This file is part of elfutils.
 # Written by Ulrich Drepper <drepper@redhat.com>, 2005.
 #
@@ -40,4 +40,11 @@ testrun ${abs_top_builddir}/src/elflint -q testfile46
 testfiles testlib_dynseg.so
 testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testlib_dynseg.so
 
+# s390x has SHT_HASH with sh_entsize 8 (really should be 4, but see common.h)
+# This was wrongly checked when comparing .gnu.hash and .hash.
+# Simple "int main (int argc, char **argv) { return 0; }"
+# gcc -Xlinker --hash-style=both -o testfile-s390x-hash-both s390x-hash-both.c
+testfiles testfile-s390x-hash-both
+testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile-s390x-hash-both
+
 exit 0
diff --git a/tests/testfile-s390x-hash-both.bz2 b/tests/testfile-s390x-hash-both.bz2
new file mode 100755 (executable)
index 0000000..86e0bcc
Binary files /dev/null and b/tests/testfile-s390x-hash-both.bz2 differ