From patchwork Tue Feb 17 23:40:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 5152 Received: (qmail 5048 invoked by alias); 17 Feb 2015 23:40:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 4597 invoked by uid 89); 17 Feb 2015 23:40:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 17 Feb 2015 23:40:05 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1HNe3bx022617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 17 Feb 2015 18:40:03 -0500 Received: from [10.10.50.118] (vpn-50-118.rdu2.redhat.com [10.10.50.118]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1HNe2sJ004776 for ; Tue, 17 Feb 2015 18:40:03 -0500 Message-ID: <54E3D152.6020804@redhat.com> Date: Tue, 17 Feb 2015 16:40:02 -0700 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [PATCH] PR gdb/17968 - [ppc64] SEGV in ppc64_elf_get_synthetic_symtab reading a separate debug file References: <54E39F4C.6050607@redhat.com> In-Reply-To: <54E39F4C.6050607@redhat.com> X-IsSubscribed: yes The original patch was missing a linker script file added as part of the test suite. Attached is an updated patch with the script. Below are test results for ppc64le. === gdb Summary === PATCHED unpatched # of expected passes 27832 27830 # of unexpected failures 87 87 # of unexpected successes 1 1 # of expected failures 57 57 # of known failures 54 54 # of unresolved testcases 1 1 # of untested testcases 35 35 # of unsupported tests 264 264 On 02/17/2015 01:06 PM, Martin Sebor wrote: > The attached patch fixes the SEGV and lets GDB successfully > load all kernel modules installed by default on RHEL 7. GDB > still aborts when attempting to list functions in many of > the modules but that's a separate problem (bug #17993). > > The patch has been tested on ppc64 with the results below. > > === gdb Summary === > > PATCHED unpatched > # of expected passes 29991 29989 > # of unexpected failures 103 103 > # of unexpected successes 1 1 > # of expected failures 67 67 > # of known failures 54 54 > # of untested testcases 32 32 > # of unsupported tests 190 190 > > Martin > diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0bd0792..288ec7d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2015-02-16 Martin Sebor + + PR gdb/17968 + * elread.c (elf_symfile_read): Use synth_abfd only for shared and + executable objects (but not relocatable files). + 2015-02-13 Doug Evans * cp-namespace.c (cp_basic_lookup_symbol): Rename parameter diff --git a/gdb/elfread.c b/gdb/elfread.c index 65c63f0..b1074e0 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1183,19 +1183,22 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags, elf_rel_plt_read (objfile, dyn_symbol_table); } - /* Contrary to binutils --strip-debug/--only-keep-debug the strip command from - elfutils (eu-strip) moves even the .symtab section into the .debug file. + /* Both the Binutils strip command and the Elfutils eu-strip command + remove the .symtab section from executables or dynamic object files + (but not from reloacatable object files like Linux kernel modules) + and move it into the .debug file. bfd_get_synthetic_symtab on ppc64 for each function descriptor ELF symbol 'name' creates a new BSF_SYNTHETIC ELF symbol '.name' with its code - address. But with eu-strip files bfd_get_synthetic_symtab would fail to - read the code address from .opd while it reads the .symtab section from - a separate debug info file as the .opd section is SHT_NOBITS there. + address. But with stripped files without the .symtab section + bfd_get_synthetic_symtab would fail to read the code address from .opd + while it reads the .symtab section from a separate debug info file as + the .opd section is SHT_NOBITS there. With SYNTH_ABFD the .opd section will be read from the original backlinked binary where it is valid. */ - if (objfile->separate_debug_objfile_backlink) +if (abfd->flags & (EXEC_P | DYNAMIC) && objfile->separate_debug_objfile_backlink) synth_abfd = objfile->separate_debug_objfile_backlink->obfd; else synth_abfd = abfd; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 4693abe..9042471 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2015-02-16 Martin Sebor + + PR gdb/17968 + * gdb.base/strip-relocatable.c: New file. + * gdb.base/strip-relocatable.exp: New file. + * gdb.base/strip-relocatable.lds: New file. + 2015-02-11 Jan Kratochvil * gdb.python/py-framefilter.exp (pagination quit - *): New tests. diff --git a/gdb/testsuite/gdb.base/strip-relocatable.c b/gdb/testsuite/gdb.base/strip-relocatable.c new file mode 100644 index 0000000..03a2a51 --- /dev/null +++ b/gdb/testsuite/gdb.base/strip-relocatable.c @@ -0,0 +1,3 @@ +void foo (void) __attribute__ ((section (".bar"))); +void foo (void) { } + diff --git a/gdb/testsuite/gdb.base/strip-relocatable.exp b/gdb/testsuite/gdb.base/strip-relocatable.exp new file mode 100644 index 0000000..3a1aeee --- /dev/null +++ b/gdb/testsuite/gdb.base/strip-relocatable.exp @@ -0,0 +1,87 @@ +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program 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. +# +# This program 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 . + +standard_testfile + +# Full pathname of the test source file. +set srcpath ${srcdir}/${subdir}/$srcfile + +# Full pathname of the linker script. +set ldspath ${srcdir}/${subdir}/[file rootname $srcfile].lds + +# Compile only with debugging. +if {[target_compile $srcpath $binfile.o object debug] != ""} then { + untested ${testfile}.exp + return -1 +} + +# Invoke the linker to create a relocatable file for Binutils testing. +if {[target_link $binfile.o $binfile.bu "--build-id -r -T $ldspath"] != ""} then { + untested $testfile.exp + return -1 +} + +# Verify that a command succeeded. Returns 1 on success, 0 on failure. +proc verify { command } { + set status [catch {remote_exec build $command} -1] + if {[lindex $status 0] != 0} { + return 0 + } + return 1 +} + +# Create a copy of the relocatable file for Elfutils testing. +verify "cp $binfile.bu $binfile.eu" + +# Verify that GDB can read symbols from a relocatable file stripped +# using Binutils strip and objcopy commands. +set test "relocatable file stripped using Binutils" + +if { [# Copy debug info from the relocatable file into a separate .dbg file. + verify "objcopy --only-keep-debug $binfile.bu $binfile.bu.dbg"] && + [# Strip debug (and other unneeded) sections from the relocatable + # file. + verify "strip --strip-debug --strip-unneeded $binfile.bu"] && + [# Insert the .gnu_debuglink section into the relocatable file + # pointing at the separate .dbg file. + verify "objcopy --add-gnu-debuglink $binfile.bu.dbg $binfile.bu"]} { + + # Restart the debugger with the relocatable file as an operand. + clean_restart $binfile.bu + + # Print the type of the function foo defined in the test file + # and verify that it has the expected type. + gdb_test "ptype foo" "type = void \\(void\\)" \ + "symbols in a Binutils-stripped file" +} + + +# Repeat the same test as above but with Elfutils. I.e., verify +# that GDB can read symbols from a relocatable file stripped using +# the Eflutils eu-strip command. +set test "relocatable file stripped using Elfutils" + +# Use eu-strip to strip debug info from the relocatable file +# and move it into a separate .dbg file in one step. +if {[verify "eu-strip -f $binfile.eu.dbg $binfile.eu" ]} { + + # Restart the debugger with the relocatable file as an operand. + clean_restart $testfile.eu + + # Print the type of the function foo defined in the test file + # and verify that it has the expected type. + gdb_test "ptype foo" "type = void \\(void\\)" \ + "symbols in an Elfutils-stripped file" +} diff --git a/gdb/testsuite/gdb.base/strip-relocatable.lds b/gdb/testsuite/gdb.base/strip-relocatable.lds new file mode 100644 index 0000000..24259c2 --- /dev/null +++ b/gdb/testsuite/gdb.base/strip-relocatable.lds @@ -0,0 +1,3 @@ +SECTIONS { + .foobar : { *(.bar) } +}