This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] 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 <mjw@redhat.com>
---
 src/ChangeLog                      |   6 ++++++
 src/elflint.c                      |   4 ++--
 tests/ChangeLog                    |   6 ++++++
 tests/Makefile.am                  |   1 +
 tests/run-elflint-test.sh          |   9 ++++++++-
 tests/testfile-s390x-hash-both.bz2 | Bin 0 -> 2435 bytes
 6 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100755 tests/testfile-s390x-hash-both.bz2

diff --git a/src/ChangeLog b/src/ChangeLog
index af98c4d..7dfab44 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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-08  Mark Wielaard  <mjw@redhat.com>
 
 	* elfcompress.c (compress_section): Use %zu to print size_t.
diff --git a/src/elflint.c b/src/elflint.c
index 7a7b9ce..e27e692 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -2480,7 +2480,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))
@@ -2521,7 +2521,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 defb8ae..04fe3a3 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -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.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f3e7c01..fedcb39 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 68615b9..f3bd901 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 <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
index 0000000000000000000000000000000000000000..86e0bcc792da1aa7f74c78c6a3de13f3b75b3723
GIT binary patch
literal 2435
zcmb7=={FmQ0>u*{4H{ytgfT*j+MXq7=g~=sG>A@$s<pL5gjhx`Lu!b9jiQ!{YGYUX
zz7}ciN=vLwRa?~3Dt)#Z)5A0GKX~`t^ZRnox#ym1;z+%sgLP20ao7!~9|HtgQK$cC
z>mPhST|Z;s>gim_(m>$$WYpo>j^n!J2M7rgv75UM9Ob^t1=`jaY(a)u<=sHq1tP-OsG
zNjZU;k&i$iK=@c96N&~irZH#$6pC;|fD<bby6$KMb(F;d*`T=O=cQb_N_jb&EB|1o
zz?O%9Tv1BiXQC$o#u&f>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