public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* libgcc patch committed: Avoid hooks in split-stack code
@ 2020-04-03 21:58 Ian Lance Taylor
  2020-04-04 17:10 ` Eric Botcazou
  2020-04-07 10:19 ` Richard Biener
  0 siblings, 2 replies; 10+ messages in thread
From: Ian Lance Taylor @ 2020-04-03 21:58 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

The split-stack code invokes mmap and munmap with a limited amount of
stack space.  That is fine when the functions just make a system call,
but it's not fine when programs use LD_PRELOAD or linker tricks to add
hooks to mmap/munmap.  Those hooks may use too much stack space,
leading to an obscure program crash.

Avoid that at least on GNU/Linux by calling __mmap/__munmap instead.

Bootstrapped and ran Go and split-stack tests on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

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.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1013 bytes --]

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] 10+ messages in thread

end of thread, other threads:[~2020-04-07 18:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 21:58 libgcc patch committed: Avoid hooks in split-stack code Ian Lance Taylor
2020-04-04 17:10 ` Eric Botcazou
2020-04-04 20:23   ` Ian Lance Taylor
2020-04-04 20:28     ` Eric Botcazou
2020-04-04 20:35       ` H.J. Lu
2020-04-04 20:48         ` Ian Lance Taylor
2020-04-04 21:16           ` Eric Botcazou
2020-04-07 10:19 ` Richard Biener
2020-04-07 10:33   ` Jakub Jelinek
2020-04-07 18:31     ` 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).