From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49971 invoked by alias); 22 Dec 2017 17:13:02 -0000 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 Received: (qmail 49942 invoked by uid 89); 22 Dec 2017 17:13:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: hera.aquilenet.fr Received: from hera.aquilenet.fr (HELO hera.aquilenet.fr) (141.255.128.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Dec 2017 17:12:59 +0000 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id AFC16FF07; Fri, 22 Dec 2017 18:12:59 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ubcl6V3da-rr; Fri, 22 Dec 2017 18:12:59 +0100 (CET) Received: from var.youpi.perso.aquilenet.fr (unknown [37.170.86.56]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 76501FEFD; Fri, 22 Dec 2017 18:12:56 +0100 (CET) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.90_RC4) (envelope-from ) id 1eSQby-0004NM-NR; Fri, 22 Dec 2017 17:55:54 +0100 Date: Fri, 22 Dec 2017 17:13:00 -0000 From: Samuel Thibault To: bug-hurd@gnu.org, gdb-patches@sourceware.org, thomas@codesourcery.com Subject: hurd: PIE support Message-ID: <20171222165554.l7rvub52zs2p5bvt@var.youpi.perso.aquilenet.fr> Mail-Followup-To: bug-hurd@gnu.org, gdb-patches@sourceware.org, thomas@codesourcery.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="asyzgw6swwrz5lek" Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-SW-Source: 2017-12/txt/msg00479.txt.bz2 --asyzgw6swwrz5lek Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 247 Hello, PIE is being pushed more and more, so we have to support it in the Hurd port :) The simplest way to fix things is to provide gdb with the entry address through auxv. The attached patch implements this. Could you have a look soon? Samuel --asyzgw6swwrz5lek Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=PIE Content-length: 2480 hurd: Add enough auxv support for AT_ENTRY for PIE binaries * gdb/gnu-nat.c: Include and . (gnu_xfer_auxv): New function. (gnu_xfer_partial): Call gnu_xfer_auxv when `object' is TARGET_OBJECT_AUXV. Index: gdb-7.12/gdb/gnu-nat.c =================================================================== --- gdb-7.12.orig/gdb/gnu-nat.c +++ gdb-7.12/gdb/gnu-nat.c @@ -52,6 +52,8 @@ extern "C" #include #include #include +#include +#include #include "inferior.h" #include "symtab.h" @@ -2542,6 +2544,61 @@ gnu_xfer_memory (gdb_byte *readbuf, cons } } +/* GNU does not have auxv, but we can at least fake the AT_ENTRY entry for PIE + binaries. */ +static enum target_xfer_status +gnu_xfer_auxv (gdb_byte *readbuf, const gdb_byte *writebuf, + CORE_ADDR memaddr, ULONGEST len, ULONGEST *xfered_len) +{ + task_t task = (gnu_current_inf + ? (gnu_current_inf->task + ? gnu_current_inf->task->port : 0) + : 0); + process_t proc; + int res; + kern_return_t err; + vm_address_t entry; + ElfW(auxv_t) auxv[2]; + + if (task == MACH_PORT_NULL) + return TARGET_XFER_E_IO; + if (writebuf != NULL) + return TARGET_XFER_E_IO; + + err = proc_task2proc (proc_server, task, &proc); + if (err) + return TARGET_XFER_E_IO; + + /* Get entry from proc server. */ + err = proc_get_entry (proc, &entry); + if (err) + return TARGET_XFER_E_IO; + + /* Fake auxv entry. */ + auxv[0].a_type = AT_ENTRY; + auxv[0].a_un.a_val = entry; + auxv[1].a_type = AT_NULL; + auxv[1].a_un.a_val = 0; + + inf_debug (gnu_current_inf, "reading auxv %s[%s] --> %s", + paddress (target_gdbarch (), memaddr), pulongest (len), + host_address_to_string (readbuf)); + + if (memaddr == sizeof(auxv)) + return TARGET_XFER_EOF; + + if (memaddr > sizeof(auxv)) + return TARGET_XFER_E_IO; + + if (memaddr + len > sizeof(auxv)) + len = sizeof(auxv) - memaddr; + + memcpy (readbuf, (gdb_byte*) &auxv + memaddr, len); + *xfered_len = len; + + return TARGET_XFER_OK; +} + /* Target to_xfer_partial implementation. */ static enum target_xfer_status @@ -2554,6 +2611,8 @@ gnu_xfer_partial (struct target_ops *ops { case TARGET_OBJECT_MEMORY: return gnu_xfer_memory (readbuf, writebuf, offset, len, xfered_len); + case TARGET_OBJECT_AUXV: + return gnu_xfer_auxv (readbuf, writebuf, offset, len, xfered_len); default: return TARGET_XFER_E_IO; } --asyzgw6swwrz5lek--