public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/gccgo] libgcc: avoid mmap/munmap hooks in split-stack code on GNU/Linux
@ 2020-04-07  1:33 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2020-04-07  1:33 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:710d54ed4e343a08d2fa0abc6b63c53dec0d9bcb

commit 710d54ed4e343a08d2fa0abc6b63c53dec0d9bcb
Author: Ian Lance Taylor <iant@golang.org>
Date:   Fri Apr 3 14:57:18 2020 -0700

    libgcc: avoid mmap/munmap hooks in split-stack code on GNU/Linux
    
            * generic-morestack.c: On GNU/Linux use __mmap/__munmap rather
            than mmap/munmap, to avoid hooks.

Diff:
---
 libgcc/ChangeLog           |  5 +++++
 libgcc/generic-morestack.c | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index 7548e347640..66e57ece69c 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-03  Ian Lance Taylor  <iant@golang.org>
+
+	* generic-morestack.c: On GNU/Linux use __mmap/__munmap rather
+	than mmap/munmap, to avoid hooks.
+
 2020-04-03  Jim Johnston  <jjohnst@us.ibm.com>
 
 	* config/s390/tpf-unwind.h (MIN_PATRANGE, MAX_PATRANGE)
diff --git a/libgcc/generic-morestack.c b/libgcc/generic-morestack.c
index c26dba1ae4a..bb9f67a7366 100644
--- a/libgcc/generic-morestack.c
+++ b/libgcc/generic-morestack.c
@@ -53,6 +53,23 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "generic-morestack.h"
 
+/* Some systems use LD_PRELOAD or similar tricks to add hooks to
+   mmap/munmap.  That breaks this code, because when we call mmap
+   there is enough stack space for the system call but there is not,
+   in general, enough stack space to run a hook.  At least when using
+   glibc on GNU/Linux we can avoid the problem by calling __mmap and
+   __munmap.  */
+
+#ifdef __gnu_linux__
+
+extern void *__mmap (void *, size_t, int, int, int, off_t);
+extern int __munmap (void *, size_t);
+
+#define mmap __mmap
+#define munmap __munmap
+
+#endif /* defined(__gnu_linux__) */
+
 typedef unsigned uintptr_type __attribute__ ((mode (pointer)));
 
 /* This file contains subroutines that are used by code compiled with


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-07  1:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07  1:33 [gcc/devel/gccgo] libgcc: avoid mmap/munmap hooks in split-stack code on GNU/Linux Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).