Skip to content

Commit e6b17d1

Browse files
authored
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.
1 parent cb60f48 commit e6b17d1

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Makefile.pre.in

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,8 +3122,20 @@ Python/asm_trampoline_aarch64.o: $(srcdir)/Python/asm_trampoline_aarch64.S
31223122
Python/asm_trampoline_riscv64.o: $(srcdir)/Python/asm_trampoline_riscv64.S
31233123
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
31243124

3125-
Python/asm_trampoline_universal2.o: Python/asm_trampoline_aarch64.o Python/asm_trampoline_x86_64.o
3126-
lipo -create -output $@ Python/asm_trampoline_aarch64.o Python/asm_trampoline_x86_64.o
3125+
# On macOS universal2 builds, $(PY_CORE_CFLAGS) contains "-arch arm64 -arch x86_64",
3126+
# which would produce fat .o files containing both architectures for each .S input.
3127+
# lipo -create then refuses to combine them because they share architectures.
3128+
# Build each per-arch object with a single -arch flag before merging with lipo.
3129+
Python/asm_trampoline_universal2.o: $(srcdir)/Python/asm_trampoline_aarch64.S $(srcdir)/Python/asm_trampoline_x86_64.S
3130+
$(CC) -c $(filter-out -arch arm64 x86_64,$(PY_CORE_CFLAGS)) -arch arm64 \
3131+
-o Python/asm_trampoline_arm64-apple-darwin.o $(srcdir)/Python/asm_trampoline_aarch64.S
3132+
$(CC) -c $(filter-out -arch arm64 x86_64,$(PY_CORE_CFLAGS)) -arch x86_64 \
3133+
-o Python/asm_trampoline_x86_64-apple-darwin.o $(srcdir)/Python/asm_trampoline_x86_64.S
3134+
lipo -create -output $@ \
3135+
Python/asm_trampoline_arm64-apple-darwin.o \
3136+
Python/asm_trampoline_x86_64-apple-darwin.o
3137+
rm -f Python/asm_trampoline_arm64-apple-darwin.o \
3138+
Python/asm_trampoline_x86_64-apple-darwin.o
31273139

31283140
Python/emscripten_trampoline_inner.wasm: $(srcdir)/Python/emscripten_trampoline_inner.c
31293141
# emcc has a path that ends with emsdk/upstream/emscripten/emcc, we're looking for emsdk/upstream/bin/clang.

0 commit comments

Comments
 (0)