]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elf32_offscn.c: Do not match SHT_NOBITS sections at OFFSET.
authorMark Wielaard <mjw@redhat.com>
Mon, 2 Apr 2012 15:11:25 +0000 (17:11 +0200)
committerMark Wielaard <mjw@redhat.com>
Mon, 2 Apr 2012 15:11:25 +0000 (17:11 +0200)
readelf -d doesn't work if a SHT_NOBITS section is right before the actual
.dynamic section at the same offset. elflint also fails on such binaries.
So skip SHT_NOBITS sections at the same offset in [g]elf[32|64]_offscn().

libelf/ChangeLog
libelf/elf32_offscn.c
tests/ChangeLog
tests/Makefile.am
tests/run-elflint-test.sh
tests/run-readelf-d.sh [new file with mode: 0755]
tests/testlib_dynseg.so.bz2 [new file with mode: 0755]

index 19b76e8d26d0d1b5a4ed597ac929a8bfa9fd082d..89dd35f544543e45aee3a6a1bc30c307a6a8cf01 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-02  Mark Wielaard  <mjw@redhat.com>
+
+       * elf32_offscn.c: Do not match SHT_NOBITS sections at OFFSET unless
+       there are no nonempty sections at that offset.
+
 2012-03-21  Roland McGrath  <roland@hack.frob.com>
 
        * elf-knowledge.h (SECTION_STRIP_P): Remove < SHT_NUM check.
index 86eff8b10b97a7b51979d4ec1cc54dbc999b1fac..5dcfc4a125689d85261352721414ebee0f149395 100644 (file)
@@ -101,7 +101,8 @@ elfw2(LIBELFBITS,offscn) (elf, offset)
            /* If this section is empty, the following one has the same
               sh_offset.  We presume the caller is looking for a nonempty
               section, so keep looking if this one is empty.  */
-           if (runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_size != 0)
+           if (runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_size != 0
+               && runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_type != SHT_NOBITS)
              goto out;
          }
 
index 8d2b83f18623740b691244383bc3dcaf115f136e..6f6c5928da1f7e4971274aa7c8b0c0fffa44da51 100644 (file)
@@ -1,3 +1,10 @@
+2012-04-02  Mark Wielaard  <mjw@redhat.com>
+
+       * Makefile.am (TESTS): Add run-readelf-d.sh.
+       (EXTRA_DIST): Add testlib_dynseg.so.bz2 and run-readelf-d.sh.
+       * run-readelf-d.sh: New test.
+       * run-elflint-test.sh: Check new testfile.
+
 2012-03-21  Tom Tromey  <tromey@redhat.com>
 
        * typeiter.c: New file.
index f2c211b563a24bc8ce8ae677332e434c0fbcc31a..980aa1252caf3e35826c3f6dd5e819c99d88f8be 100644 (file)
@@ -86,7 +86,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
        run-disasm-x86.sh run-disasm-x86-64.sh \
        run-early-offscn.sh run-dwarf-getmacros.sh \
        run-test-flag-nobits.sh run-prelink-addr-test.sh \
-       run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh
+       run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh \
+       run-readelf-d.sh
 # run-show-ciefde.sh
 
 if !STANDALONE
@@ -162,7 +163,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             testfile55-32.prelink.bz2 testfile55-64.bz2 \
             testfile55-64.debug.bz2 testfile55-64.prelink.bz2 \
             testfile56.bz2 testfile57.bz2 testfile58.bz2 \
-            run-typeiter.sh testfile59.bz2
+            run-typeiter.sh testfile59.bz2 \
+            run-readelf-d.sh testlib_dynseg.so.bz2
 
 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
                              bindir=$(DESTDIR)$(bindir) \
index e0e1c547d92a98219e9521859bd964e6f1afacb0..0c872fe571aadaa3c63af181ee400dd292b06882 100755 (executable)
@@ -44,4 +44,8 @@ testrun ../src/elflint -q --gnu-ld testfile42
 testfiles testfile46
 testrun ../src/elflint -q testfile46
 
+# see also run-readelf-d.sh
+testfiles testlib_dynseg.so
+testrun ../src/elflint -q --gnu-ld testlib_dynseg.so
+
 exit 0
diff --git a/tests/run-readelf-d.sh b/tests/run-readelf-d.sh
new file mode 100755 (executable)
index 0000000..9022e70
--- /dev/null
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2012 Red Hat, Inc.
+# This file is part of Red Hat elfutils.
+#
+# Red Hat elfutils 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; version 2 of the License.
+#
+# Red Hat 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+#
+# Red Hat elfutils is an included package of the Open Invention Network.
+# An included package of the Open Invention Network is a package for which
+# Open Invention Network licensees cross-license their patents.  No patent
+# license is granted, either expressly or impliedly, by designation as an
+# included package.  Should you wish to participate in the Open Invention
+# Network licensing program, please visit www.openinventionnetwork.com
+# <http://www.openinventionnetwork.com>.
+
+. $srcdir/test-subr.sh
+
+# #include <stdio.h>
+# 
+# __thread int i;
+# 
+# void print_i ()
+# {
+#   printf("%d\n", i);
+# }
+#
+# gcc -fPIC -shared -o testlib_dynseg.so testlib_dynseg.c
+# With ld --version
+# GNU gold (GNU Binutils 2.22.52.20120402) 1.11
+
+testfiles testlib_dynseg.so
+
+testrun_compare ../src/readelf -d testlib_dynseg.so <<\EOF
+
+Dynamic segment contains 28 entries:
+ Addr: 0x00000000000017e0  Offset: 0x0007e0  Link to section: [ 3] '.dynstr'
+  Type              Value
+  PLTGOT            0x00000000000019c8
+  PLTRELSZ          72 (bytes)
+  JMPREL            0x0000000000000568
+  PLTREL            RELA
+  RELA              0x00000000000004d8
+  RELASZ            144 (bytes)
+  RELAENT           24 (bytes)
+  RELACOUNT         1
+  SYMTAB            0x0000000000000228
+  SYMENT            24 (bytes)
+  STRTAB            0x0000000000000360
+  STRSZ             190 (bytes)
+  GNU_HASH          0x0000000000000420
+  NEEDED            Shared library: [libc.so.6]
+  NEEDED            Shared library: [ld-linux-x86-64.so.2]
+  INIT              0x00000000000005b0
+  FINI              0x0000000000000748
+  VERSYM            0x0000000000000460
+  VERDEF            0x000000000000047c
+  VERDEFNUM         1
+  VERNEED           0x0000000000000498
+  VERNEEDNUM        2
+  NULL              
+  NULL              
+  NULL              
+  NULL              
+  NULL              
+  NULL              
+EOF
+
+exit 0
diff --git a/tests/testlib_dynseg.so.bz2 b/tests/testlib_dynseg.so.bz2
new file mode 100755 (executable)
index 0000000..94296a4
Binary files /dev/null and b/tests/testlib_dynseg.so.bz2 differ