From: Mark Wielaard Date: Tue, 9 Feb 2016 13:18:49 +0000 (+0100) Subject: elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH. X-Git-Tag: elfutils-0.166~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4dc76404ce8116b806550d7515ec98be953df9e;p=thirdparty%2Felfutils.git elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH. 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index 707c27177..e4b17d623 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2016-02-09 Mark Wielaard + + * 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 * elflint.c (check_elf_header): Recognize ELFOSABI_FREEBSD. diff --git a/src/elflint.c b/src/elflint.c index eae776143..15b12f6f5 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -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; } diff --git a/tests/ChangeLog b/tests/ChangeLog index a043ade6d..bcc296f14 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2016-02-09 Mark Wielaard + + * 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 * run-strip-nobitsalign.sh: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index f3e7c01ca..fedcb39d2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/run-elflint-test.sh b/tests/run-elflint-test.sh index 68615b961..f3bd9012c 100755 --- a/tests/run-elflint-test.sh +++ b/tests/run-elflint-test.sh @@ -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 , 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 index 000000000..86e0bcc79 Binary files /dev/null and b/tests/testfile-s390x-hash-both.bz2 differ