NetBSD Problem Report #48250

From martin@duskware.de  Fri Sep 27 18:18:17 2013
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 475457267A
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 27 Sep 2013 18:18:17 +0000 (UTC)
Date: Fri, 27 Sep 2013 20:18:14 CEST
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: gdb vs. -pie executables
X-Send-Pr-Version: 3.95

>Number:         48250
>Category:       bin
>Synopsis:       gdb confused by -pie executables
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 27 18:20:00 +0000 2013
>Closed-Date:    Wed May 25 20:00:50 +0000 2016
>Last-Modified:  Wed May 25 20:00:50 +0000 2016
>Originator:     Martin Husemann
>Release:        NetBSD 6.99.23
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD night-owl.duskware.de 6.99.23 NetBSD 6.99.23 (NIGHT-OWL) #202: Fri Sep 20 19:59:50 CEST 2013 martin@night-owl.duskware.de:/usr/src/sys/arch/amd64/compile/NIGHT-OWL amd64
Architecture: x86_64
Machine: amd64
>Description:

An executable compiled with -pic confuses the address mapping in gdb
(may be a bug in ld.elf_so, forgetting to fix up some variable looked
at by gdb?), so it does not find the correct address where .text is
mapped.

>How-To-Repeat:

[/tmp] martin@night-owl > cat test.c 
#include <stdio.h>
int main(int argc, char **argv) { printf ("hello\n"); return 0; }
[/tmp] martin@night-owl > !cc
cc -fpie -pie -g test.c
[/tmp] martin@night-owl > gdb ./a.out 
[..]
(gdb) break main
Breakpoint 1 at 0xa8f: file test.c, line 2.
(gdb) run
Starting program: /tmp/a.out 
Error in re-setting breakpoint 1: Cannot access memory at address 0xa80
Error in re-setting breakpoint 1: Cannot access memory at address 0xa80
hello
[Inferior 1 (process 1544) exited normally]

>Fix:
This has been fixed now on head. There is still an issue debugging ASLR
binaries. The symbol table of the dynamic linker itself is not loaded somehow,
but other symbol tables are.

>Release-Note:

>Audit-Trail:

From: Andreas Gustafsson <gson@gson.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/48250: gdb vs. -pie executables
Date: Sun,  3 Apr 2016 17:30:18 +0300 (EEST)

 Here's the commit that fixed it, for the record:

   2015.07.02.03.47.54 christos src/sys/kern/sys_process.c 1.166
   2015.07.02.03.47.54 christos src/sys/sys/ptrace.h 1.46

 -- 
 Andreas Gustafsson, gson@gson.org

State-Changed-From-To: open->closed
State-Changed-By: leot@NetBSD.org
State-Changed-When: Wed, 25 May 2016 20:00:50 +0000
State-Changed-Why:
Christos recently fixed it.

FTR:
 src/sys/kern/core_elf32.c -r1.46
 src/sys/sys/exec_elf.h -r1.154
 src/external/gpl3/gdb/dist/bfd/elf.c -r1.7
 src/external/gpl3/gdb/dist/include/elf/common.h -r1.2


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.