https://github.com/python/cpython/commit/e6b17d1d6dc3dcb497502b377b1357076feb41f3
commit: e6b17d1d6dc3dcb497502b377b1357076feb41f3
branch: main
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-05-25T23:01:27+01:00
summary:

gh-149800: Fix macOS universal2 build of perf trampoline (GH-149894 follow-up) 
(#150364)

After the perf trampoline assembly was split into per-architecture files,
the macOS universal2 build failed at the lipo step:

    fatal error: lipo: Python/asm_trampoline_aarch64.o and
    Python/asm_trampoline_x86_64.o have the same architectures (x86_64)
    and can't be in the same fat output file

PY_CORE_CFLAGS on universal2 contains "-arch arm64 -arch x86_64", so each
.S file was assembled into a fat .o containing both slices (with one slice
empty because of the #ifdef guards). lipo then refused to merge two fat
objects that share architectures.

Compile each per-arch object with a single -arch flag before merging.

files:
M Makefile.pre.in

diff --git a/Makefile.pre.in b/Makefile.pre.in
index ea15726a2de548..242aca0dc05eec 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -3122,8 +3122,20 @@ Python/asm_trampoline_aarch64.o: 
$(srcdir)/Python/asm_trampoline_aarch64.S
 Python/asm_trampoline_riscv64.o: $(srcdir)/Python/asm_trampoline_riscv64.S
        $(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
 
-Python/asm_trampoline_universal2.o: Python/asm_trampoline_aarch64.o 
Python/asm_trampoline_x86_64.o
-       lipo -create -output $@ Python/asm_trampoline_aarch64.o 
Python/asm_trampoline_x86_64.o
+# On macOS universal2 builds, $(PY_CORE_CFLAGS) contains "-arch arm64 -arch 
x86_64",
+# which would produce fat .o files containing both architectures for each .S 
input.
+# lipo -create then refuses to combine them because they share architectures.
+# Build each per-arch object with a single -arch flag before merging with lipo.
+Python/asm_trampoline_universal2.o: $(srcdir)/Python/asm_trampoline_aarch64.S 
$(srcdir)/Python/asm_trampoline_x86_64.S
+       $(CC) -c $(filter-out -arch arm64 x86_64,$(PY_CORE_CFLAGS)) -arch arm64 
\
+               -o Python/asm_trampoline_arm64-apple-darwin.o 
$(srcdir)/Python/asm_trampoline_aarch64.S
+       $(CC) -c $(filter-out -arch arm64 x86_64,$(PY_CORE_CFLAGS)) -arch 
x86_64 \
+               -o Python/asm_trampoline_x86_64-apple-darwin.o 
$(srcdir)/Python/asm_trampoline_x86_64.S
+       lipo -create -output $@ \
+               Python/asm_trampoline_arm64-apple-darwin.o \
+               Python/asm_trampoline_x86_64-apple-darwin.o
+       rm -f Python/asm_trampoline_arm64-apple-darwin.o \
+         Python/asm_trampoline_x86_64-apple-darwin.o
 
 Python/emscripten_trampoline_inner.wasm: 
$(srcdir)/Python/emscripten_trampoline_inner.c
        # emcc has a path that ends with emsdk/upstream/emscripten/emcc, we're 
looking for emsdk/upstream/bin/clang.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to