Package: gdb
Version: 7.12-6+b1
Severity: important
Tags: patch upstream
User: [email protected]
Usertags: hurd

Hello,

Upstream gdb committed PIE support for hurd-i386, we would need this in
Debian too, so Debian PIE-built packages can be debuggable :)

Could you apply the attached upstream commit to future gdb uploads?
(until gdb 8.1 is released).

Thanks,
Samuel

-- System Information:
Debian Release: buster/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable-debug'), (500, 
'testing-debug'), (500, 'stable-debug'), (500, 'oldoldstable'), (500, 
'buildd-unstable'), (500, 'unstable'), (500, 'stable'), (500, 'oldstable'), (1, 
'experimental-debug'), (1, 'buildd-experimental'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.14.0-3-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), 
LANGUAGE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages gdb depends on:
ii  libbabeltrace-ctf1  1.5.3-4
ii  libbabeltrace1      1.5.3-4
ii  libc6               2.26-2
ii  libexpat1           2.2.5-3
ii  liblzma5            5.2.2-1.3
ii  libncurses5         6.0+20171125-1
ii  libpython3.6        3.6.4-2
ii  libreadline7        7.0-3
ii  libtinfo5           6.0+20171125-1
ii  zlib1g              1:1.2.8.dfsg-5

Versions of packages gdb recommends:
ii  libc6-dbg [libc-dbg]  2.26-2

Versions of packages gdb suggests:
ii  gdb-doc    7.12-2
ii  gdbserver  7.12-6+b1

-- no debconf information

-- 
Samuel
"...[Linux's] capacity to talk via any medium except smoke signals."
(By Dr. Greg Wettstein, Roger Maris Cancer Center)
commit 9c4ac400f0f7d8daa8483dbe73b5699782ae3e22
Author: Samuel Thibault <[email protected]>
Date:   Mon Jan 8 10:30:16 2018 -0500

    hurd: Add enough auxv support for AT_ENTRY for PIE binaries
    
    Add PIE support for hurd, by faking an AT_ENTRY auxv entry.  That value
    is expected to be read by svr4_exec_displacement, which will propagate
    the executable displacement.
    
    gdb/ChangeLog:
    
            * gdb/gnu-nat.c: Include <elf.h> and <link.h>.
            (gnu_xfer_auxv): New function.
            (gnu_xfer_partial): Call gnu_xfer_auxv when `object' is
            TARGET_OBJECT_AUXV.

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 3972b223d8..f2d5fcaa50 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -52,6 +52,8 @@ extern "C"
 #include <setjmp.h>
 #include <signal.h>
 #include <sys/ptrace.h>
+#include <elf.h>
+#include <link.h>
 
 #include "inferior.h"
 #include "symtab.h"
@@ -2541,6 +2543,60 @@ gnu_xfer_memory (gdb_byte *readbuf, const gdb_byte 
*writebuf,
     }
 }
 
+/* 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;
+
+  if (memaddr == sizeof (auxv))
+    return TARGET_XFER_EOF;
+  if (memaddr > sizeof (auxv))
+    return TARGET_XFER_E_IO;
+
+  err = proc_task2proc (proc_server, task, &proc);
+  if (err != 0)
+    return TARGET_XFER_E_IO;
+
+  /* Get entry from proc server.  */
+  err = proc_get_entry (proc, &entry);
+  if (err != 0)
+    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 + 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
@@ -2553,6 +2609,8 @@ gnu_xfer_partial (struct target_ops *ops, enum 
target_object object,
     {
     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;
     }

Reply via email to