mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
fix Apple Silicon JIT compilation
* configure.ac: check for pthread_jit_write_protect_np. * libguile/jit.c: add support for Apple Silicon JIT compilation. Fixes https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44505
This commit is contained in:
parent
b54263dc98
commit
3bdcc3668f
2 changed files with 27 additions and 1 deletions
|
@ -1187,6 +1187,9 @@ case "$with_threads" in
|
||||||
pthread_get_stackaddr_np pthread_attr_get_np pthread_sigmask \
|
pthread_get_stackaddr_np pthread_attr_get_np pthread_sigmask \
|
||||||
pthread_cancel])
|
pthread_cancel])
|
||||||
|
|
||||||
|
# Apple Silicon JIT code arena needs to be unprotected before writing.
|
||||||
|
AC_CHECK_FUNCS([pthread_jit_write_protect_np])
|
||||||
|
|
||||||
# On past versions of Solaris, believe 8 through 10 at least, you
|
# On past versions of Solaris, believe 8 through 10 at least, you
|
||||||
# had to write "pthread_once_t foo = { PTHREAD_ONCE_INIT };".
|
# had to write "pthread_once_t foo = { PTHREAD_ONCE_INIT };".
|
||||||
# This is contrary to POSIX:
|
# This is contrary to POSIX:
|
||||||
|
|
|
@ -47,6 +47,10 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined __APPLE__ && HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
|
||||||
|
#include <libkern/OSCacheControl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "jit.h"
|
#include "jit.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1349,9 +1353,13 @@ allocate_code_arena (size_t size, struct code_arena *prev)
|
||||||
ret->size = size;
|
ret->size = size;
|
||||||
ret->prev = prev;
|
ret->prev = prev;
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
|
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||||
|
#if defined __APPLE__ && HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
|
||||||
|
flags |= MAP_JIT;
|
||||||
|
#endif
|
||||||
ret->base = mmap (NULL, ret->size,
|
ret->base = mmap (NULL, ret->size,
|
||||||
PROT_EXEC | PROT_READ | PROT_WRITE,
|
PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
flags, -1, 0);
|
||||||
if (ret->base == MAP_FAILED)
|
if (ret->base == MAP_FAILED)
|
||||||
{
|
{
|
||||||
perror ("allocating JIT code buffer failed");
|
perror ("allocating JIT code buffer failed");
|
||||||
|
@ -1406,11 +1414,21 @@ emit_code (scm_jit_state *j, void (*emit) (scm_jit_state *))
|
||||||
|
|
||||||
uint8_t *ret = jit_address (j->jit);
|
uint8_t *ret = jit_address (j->jit);
|
||||||
|
|
||||||
|
#if defined __APPLE__ && HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
|
||||||
|
pthread_jit_write_protect_np(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
emit (j);
|
emit (j);
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
if (!jit_has_overflow (j->jit) && jit_end (j->jit, &size))
|
if (!jit_has_overflow (j->jit) && jit_end (j->jit, &size))
|
||||||
{
|
{
|
||||||
|
#if defined __APPLE__ && HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
|
||||||
|
/* protect previous code arena. leave unprotected after emit()
|
||||||
|
since jit_end() also writes to code arena. */
|
||||||
|
pthread_jit_write_protect_np(1);
|
||||||
|
sys_icache_invalidate(arena->base, arena->size);
|
||||||
|
#endif
|
||||||
ASSERT (size <= (arena->size - arena->used));
|
ASSERT (size <= (arena->size - arena->used));
|
||||||
DEBUG ("mcode: %p,+%zu\n", ret, size);
|
DEBUG ("mcode: %p,+%zu\n", ret, size);
|
||||||
arena->used += size;
|
arena->used += size;
|
||||||
|
@ -1424,6 +1442,11 @@ emit_code (scm_jit_state *j, void (*emit) (scm_jit_state *))
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined __APPLE__ && HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
|
||||||
|
/* protect previous code arena */
|
||||||
|
pthread_jit_write_protect_np(1);
|
||||||
|
sys_icache_invalidate(arena->base, arena->size);
|
||||||
|
#endif
|
||||||
jit_reset (j->jit);
|
jit_reset (j->jit);
|
||||||
if (arena->used == 0)
|
if (arena->used == 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue