This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: GCC Go Patch to conditionalize use of sys/mman.h methods
- From: Ian Lance Taylor <iant at google dot com>
- To: Joel Sherrill <joel dot sherrill at OARcorp dot com>
- Cc: "Aman \(neshu\) Agarwal" <neshuagarwal1909 at gmail dot com>, "gcc-patches\ at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 07 Apr 2010 15:24:11 -0700
- Subject: Re: GCC Go Patch to conditionalize use of sys/mman.h methods
- References: <4BB0BE86.9060302@oarcorp.com>
Joel Sherrill <joel.sherrill@OARcorp.com> writes:
> In trying to compile Go to target RTEMS, we needed to
> address the unconditional use of methods in sys/mman.h.
> You will need to regenerate configure.
Thanks for the patch. I committed a slightly different patch, as
follows.
Ian
diff -r be2b836f2bd3 libgo/configure.ac
--- a/libgo/configure.ac Wed Mar 10 14:52:12 2010 -0800
+++ b/libgo/configure.ac Wed Apr 07 15:19:40 2010 -0700
@@ -181,6 +181,7 @@
AC_C_BIGENDIAN
+AC_CHECK_HEADERS(sys/mman.h)
AC_CACHE_SAVE
if test ${multilib} = yes; then
diff -r be2b836f2bd3 libgo/runtime/go-trampoline.c
--- a/libgo/runtime/go-trampoline.c Wed Mar 10 14:52:12 2010 -0800
+++ b/libgo/runtime/go-trampoline.c Wed Apr 07 15:19:40 2010 -0700
@@ -4,11 +4,16 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
+#include "config.h"
+
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
+
+#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
+#endif
#include "go-alloc.h"
@@ -21,14 +26,20 @@
{
unsigned int page_size;
void *ret;
- int i;
page_size = getpagesize ();
assert (page_size >= size);
ret = __go_alloc (2 * page_size - 1);
ret = (void *) (((uintptr_t) ret + page_size - 1)
& ~ ((uintptr_t) page_size - 1));
- i = mprotect (ret, size, PROT_READ | PROT_WRITE | PROT_EXEC);
- assert (i == 0);
+
+#ifdef HAVE_SYS_MMAN_H
+ {
+ int i;
+ i = mprotect (ret, size, PROT_READ | PROT_WRITE | PROT_EXEC);
+ assert (i == 0);
+ }
+#endif
+
return ret;
}
diff -r be2b836f2bd3 libgo/runtime/mem.c
--- a/libgo/runtime/mem.c Wed Mar 10 14:52:12 2010 -0800
+++ b/libgo/runtime/mem.c Wed Apr 07 15:19:40 2010 -0700
@@ -1,4 +1,5 @@
#include <errno.h>
+
#include "runtime.h"
#include "malloc.h"
@@ -9,12 +10,12 @@
mstats.sys += n;
p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
- if(p < (void*)4096) {
- if(p == (void*)EACCES) {
+ if (p == MAP_FAILED) {
+ if(errno == EACCES) {
printf("mmap: access denied\n");
printf("If you're running SELinux, enable execmem for this process.\n");
} else {
- printf("mmap: errno=%p\n", p);
+ printf("mmap: errno=%d\n", errno);
}
exit(2);
}
diff -r be2b836f2bd3 libgo/runtime/runtime.h
--- a/libgo/runtime/runtime.h Wed Mar 10 14:52:12 2010 -0800
+++ b/libgo/runtime/runtime.h Wed Apr 07 15:19:40 2010 -0700
@@ -4,13 +4,18 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
+#include "config.h"
+
#define _GNU_SOURCE
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
+
+#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
+#endif
#include "go-alloc.h"
#include "go-panic.h"
@@ -108,9 +113,15 @@
/* Functions. */
#define runtime_memclr(buf, size) __builtin_memset(buf, 0, size)
-#define runtime_mmap mmap
MCache* allocmcache(void);
void free(void *v);
void addfinalizer(void*, void(*fn)(void*), int32);
+#ifdef HAVE_SYS_MMAN_H
+#define runtime_mmap mmap
+#else
+#define runtime_mmap(start, len, prot, flags, fd, offset) malloc(len)
+#define MAP_FAILED NULL
+#endif
+
#define cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)