From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15280 invoked by alias); 5 Jul 2010 18:16:24 -0000 Received: (qmail 15269 invoked by uid 22791); 5 Jul 2010 18:16:23 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Jul 2010 18:16:17 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o65IFwil013829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Jul 2010 14:15:58 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o65IFt2Q030889 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 5 Jul 2010 14:15:57 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o65IFtsD027066; Mon, 5 Jul 2010 20:15:55 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o65IFtpf027065; Mon, 5 Jul 2010 20:15:55 +0200 Date: Mon, 05 Jul 2010 18:16:00 -0000 From: Jan Kratochvil To: Joel Brobecker Cc: gdb-patches@sourceware.org Subject: Re: ping: [patch 6/6] PIE: Fix back re-run Message-ID: <20100705181555.GF26551@host0.dyn.jankratochvil.net> References: <20100329161905.GE2940@host0.dyn.jankratochvil.net> <20100609151008.GF7183@host0.dyn.jankratochvil.net> <20100701191041.GX2595@adacore.com> <20100704101855.GF6875@host0.dyn.jankratochvil.net> <20100705174820.GD2595@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100705174820.GD2595@adacore.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-07/txt/msg00090.txt.bz2 On Mon, 05 Jul 2010 19:48:20 +0200, Joel Brobecker wrote: > Congrats on being able to teach me some about PIE and prelinking ;-). Thanks, I even discovered that PIEs are intentionally skipped during prelinking while responding to your review. Not that it changes too much on the code IIRC, anyway it is done. Checked-in. The whole series is now in. Thanks, Jan http://sourceware.org/ml/gdb-cvs/2010-07/msg00029.html --- src/gdb/ChangeLog 2010/07/05 18:00:39 1.11966 +++ src/gdb/ChangeLog 2010/07/05 18:04:32 1.11967 @@ -1,6 +1,13 @@ 2010-07-05 Jan Kratochvil Joel Brobecker + Fix re-run of PIE executable, PR shlibs/11776. + * solib-svr4.c (svr4_relocate_main_executable) : Remove + the part of pre-set SYMFILE_OBJFILE->SECTION_OFFSETS. + +2010-07-05 Jan Kratochvil + Joel Brobecker + * auxv.c (memory_xfer_auxv): Update attach comment. * solib-svr4.c (svr4_special_symbol_handling): Remove the call to svr4_relocate_main_executable. --- src/gdb/solib-svr4.c 2010/07/05 18:00:39 1.136 +++ src/gdb/solib-svr4.c 2010/07/05 18:04:33 1.137 @@ -1989,17 +1989,32 @@ { CORE_ADDR displacement; - if (symfile_objfile) - { - int i; - - /* Remote target may have already set specific offsets by `qOffsets' - which should be preferred. */ - - for (i = 0; i < symfile_objfile->num_sections; i++) - if (ANOFFSET (symfile_objfile->section_offsets, i) != 0) - return; - } + /* If we are re-running this executable, SYMFILE_OBJFILE->SECTION_OFFSETS + probably contains the offsets computed using the PIE displacement + from the previous run, which of course are irrelevant for this run. + So we need to determine the new PIE displacement and recompute the + section offsets accordingly, even if SYMFILE_OBJFILE->SECTION_OFFSETS + already contains pre-computed offsets. + + If we cannot compute the PIE displacement, either: + + - The executable is not PIE. + + - SYMFILE_OBJFILE does not match the executable started in the target. + This can happen for main executable symbols loaded at the host while + `ld.so --ld-args main-executable' is loaded in the target. + + Then we leave the section offsets untouched and use them as is for + this run. Either: + + - These section offsets were properly reset earlier, and thus + already contain the correct values. This can happen for instance + when reconnecting via the remote protocol to a target that supports + the `qOffsets' packet. + + - The section offsets were not reset earlier, and the best we can + hope is that the old offsets are still applicable to the new run. + */ if (! svr4_exec_displacement (&displacement)) return; --- src/gdb/testsuite/ChangeLog 2010/07/05 18:02:56 1.2375 +++ src/gdb/testsuite/ChangeLog 2010/07/05 18:04:33 1.2376 @@ -1,6 +1,14 @@ 2010-07-05 Jan Kratochvil Joel Brobecker + Fix re-run of PIE executable, PR shlibs/11776. + * gdb.base/break-interp.exp (test_ld): Turn off "disable-randomization". + Remove $displacement_main to match the solib-svr4.c change. New "kill" + and re-"run" of the inferior. + +2010-07-05 Jan Kratochvil + Joel Brobecker + Cope with missing /usr/sbin/prelink. * lib/prelink-support.exp (prelink_no): : New. --- src/gdb/testsuite/gdb.base/break-interp.exp 2010/07/05 18:01:53 1.17 +++ src/gdb/testsuite/gdb.base/break-interp.exp 2010/07/05 18:04:33 1.18 @@ -337,6 +337,11 @@ # Print the "PIE (Position Independent Executable) displacement" message. gdb_test_no_output "set verbose on" + # We want to test the re-run of a PIE in the case where the executable + # is loaded with a different displacement, but disable-randomization + # prevents that from happening. So turn it off. + gdb_test "set disable-randomization off" + reach "dl_main" "run segv" $displacement gdb_test "bt" "#0 +\[^\r\n\]*\\mdl_main\\M.*" "dl bt" @@ -347,7 +352,13 @@ reach "libfunc" continue "NONE" gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt" + } + # Try re-run if the new PIE displacement takes effect. + gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y" + reach "dl_main" "run segv" $displacement + + if $ifmain { test_core $file $displacement test_attach $file $displacement