From patchwork Wed Dec 27 02:48:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 25107 Received: (qmail 112124 invoked by alias); 27 Dec 2017 02:48:54 -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 91786 invoked by uid 89); 27 Dec 2017 02:48:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Dec 2017 02:48:27 +0000 Received: from [10.0.0.11] (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 4B4D21E519; Tue, 26 Dec 2017 21:48:23 -0500 (EST) Subject: Re: hurd: PIE support To: bug-hurd@gnu.org, gdb-patches@sourceware.org, thomas@codesourcery.com References: <20171222165554.l7rvub52zs2p5bvt@var.youpi.perso.aquilenet.fr> From: Simon Marchi Message-ID: <47cd545e-6931-cacf-5517-189f4dcaaea9@simark.ca> Date: Tue, 26 Dec 2017 21:48:23 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171222165554.l7rvub52zs2p5bvt@var.youpi.perso.aquilenet.fr> On 2017-12-22 11:55 AM, Samuel Thibault wrote: > 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 Hi Samuel, The patch looks good to me, although I can't really try it and confirm it works. Some coding style comments: unless the variable is logically a boolean, we try to be explicit in our comparisons: if (pointer != NULL) if (integer != 0) instead of if (pointer) if (integer) So if you could fix that throughout the patch, it would be appreciated. We would also need a ChangeLog entry. If you can add that, as well as a proper title and commit message, and re-submit using git-send-email, it would be appreciated. More comments below. + *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; } Thanks, Simon --- 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; Can we do these two checks earlier, so we don't do unnecessary work in those cases? Also, please add a space after sizeof (as if it was a function call). + if (memaddr + len > sizeof(auxv)) + len = sizeof(auxv) - memaddr; + + memcpy (readbuf, (gdb_byte*) &auxv + memaddr, len); Space before *.