Skip to content

Commit 2392232

Browse files
[3.14] GH-134291: Support older macOS deployment targets for JIT builds (GH-137211) (#137701)
Co-authored-by: Brandt Bucher <[email protected]>
1 parent ccb6de3 commit 2392232

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
@@ -113,6 +113,10 @@ jobs:
113113
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
114114
brew install llvm@${{ matrix.llvm }}
115115
export SDKROOT="$(xcrun --show-sdk-path)"
116+
# Set MACOSX_DEPLOYMENT_TARGET and -Werror=unguarded-availability to
117+
# make sure we don't break downstream distributors (like uv):
118+
export CFLAGS_JIT='-Werror=unguarded-availability'
119+
export MACOSX_DEPLOYMENT_TARGET=10.15
116120
./configure --enable-experimental-jit --enable-universalsdk --with-universal-archs=universal2 ${{ matrix.debug && '--with-pydebug' || '' }}
117121
make all --jobs 4
118122
./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");
@@ -528,9 +521,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
528521
if (memory == NULL) {
529522
return -1;
530523
}
531-
#ifdef MAP_JIT
532-
pthread_jit_write_protect_np(0);
533-
#endif
534524
// Collect memory stats
535525
OPT_STAT_ADD(jit_total_memory_size, total_size);
536526
OPT_STAT_ADD(jit_code_size, code_size);
@@ -568,9 +558,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
568558
data += group->data_size;
569559
assert(code == memory + code_size);
570560
assert(data == memory + code_size + state.trampolines.size + data_size);
571-
#ifdef MAP_JIT
572-
pthread_jit_write_protect_np(1);
573-
#endif
574561
if (mark_executable(memory, total_size)) {
575562
jit_free(memory, total_size);
576563
return -1;

0 commit comments

Comments
 (0)