Fix sbrk in PIE binaries
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 13 Jul 2020 19:34:17 +0000 (20:34 +0100)
committerAurelien Jarno <aurel32@debian.org>
Mon, 13 Jul 2020 19:34:17 +0000 (20:34 +0100)
In PIE mode, the program gets loaded at very low address, and thus _end is very
low, just before libraries, and thus initializing the brk to it does not make
sense, since there is no room left there. Hardcode the brk to 0x8000000 for now
as a workaround.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name tg-pie-sbrk.diff

sysdeps/mach/hurd/brk.c

index 4fac03fcc3c328b6f3506c947a6aad3cab8261cf..9cc4502f6bd6ede9ee0e4ecd5990f74eaa9b769d 100644 (file)
@@ -143,8 +143,12 @@ init_brk (void)
   /* If _hurd_brk is already set, don't change it.  The assumption is that
      it was set in a previous run before something like Emacs's unexec was
      called and dumped all the data up to the break at that point.  */
-  if (_hurd_brk == 0)
+  if (_hurd_brk == 0) {
     _hurd_brk = (vm_address_t) &_end;
+    if (_hurd_brk < 0x8000000)
+      /* XXX: PIE case, get out of library area */
+      _hurd_brk = 0x8000000;
+  }
 
   pagend = round_page (_hurd_brk);