]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149800: Fix macOS universal2 build of perf trampoline (GH-149894 follow-up) (...
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Mon, 25 May 2026 22:01:27 +0000 (23:01 +0100)
committerGitHub <noreply@github.com>
Mon, 25 May 2026 22:01:27 +0000 (23:01 +0100)
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.

Makefile.pre.in

index ea15726a2de548afd6bd8e785549f259279db9bc..242aca0dc05eec2076542841431a9cd6f84f660f 100644 (file)
@@ -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.