Skip to content

Commit d591b5e

Browse files
authored
GH-134291: Support older macOS deployment targets for JIT builds (GH-137211)
1 parent 5f35f9b commit d591b5e

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

.github/workflows/jit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ jobs:
117117
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
118118
brew install llvm@${{ matrix.llvm }}
119119
export SDKROOT="$(xcrun --show-sdk-path)"
120+
# Set MACOSX_DEPLOYMENT_TARGET and -Werror=unguarded-availability to
121+
# make sure we don't break downstream distributors (like uv):
122+
export CFLAGS_JIT='-Werror=unguarded-availability'
123+
export MACOSX_DEPLOYMENT_TARGET=10.15
120124
./configure --enable-experimental-jit --enable-universalsdk --with-universal-archs=universal2 ${{ matrix.debug && '--with-pydebug' || '' }}
121125
make all --jobs 4
122126
./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove some newer macOS API usage from the JIT compiler in order to restore
2+
compatibility with older OSX 10.15 deployment targets.

Python/jit.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ jit_alloc(size_t size)
6969
#else
7070
int flags = MAP_ANONYMOUS | MAP_PRIVATE;
7171
int prot = PROT_READ | PROT_WRITE;
72-
# ifdef MAP_JIT
73-
flags |= MAP_JIT;
74-
prot |= PROT_EXEC;
75-
# endif
7672
unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0);
7773
int failed = memory == MAP_FAILED;
7874
#endif
@@ -118,11 +114,8 @@ mark_executable(unsigned char *memory, size_t size)
118114
int old;
119115
int failed = !VirtualProtect(memory, size, PAGE_EXECUTE_READ, &old);
120116
#else
121-
int failed = 0;
122117
__builtin___clear_cache((char *)memory, (char *)memory + size);
123-
#ifndef MAP_JIT
124-
failed = mprotect(memory, size, PROT_EXEC | PROT_READ);
125-
#endif
118+
int failed = mprotect(memory, size, PROT_EXEC | PROT_READ);
126119
#endif
127120
if (failed) {
128121
jit_error("unable to protect executable memory");
@@ -531,9 +524,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
531524
if (memory == NULL) {
532525
return -1;
533526
}
534-
#ifdef MAP_JIT
535-
pthread_jit_write_protect_np(0);
536-
#endif
537527
// Collect memory stats
538528
OPT_STAT_ADD(jit_total_memory_size, total_size);
539529
OPT_STAT_ADD(jit_code_size, code_size);
@@ -571,9 +561,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
571561
data += group->data_size;
572562
assert(code == memory + code_size);
573563
assert(data == memory + code_size + state.trampolines.size + code_padding + data_size);
574-
#ifdef MAP_JIT
575-
pthread_jit_write_protect_np(1);
576-
#endif
577564
if (mark_executable(memory, total_size)) {
578565
jit_free(memory, total_size);
579566
return -1;

0 commit comments

Comments
 (0)