Skip to content

Commit 859ff98

Browse files
committed
gh-149800: Split perf trampoline assembly into per-architecture files
1 parent 9ee9f58 commit 859ff98

7 files changed

Lines changed: 130 additions & 89 deletions

File tree

Makefile.pre.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3111,9 +3111,18 @@ config.status: $(srcdir)/configure
31113111

31123112
.PRECIOUS: config.status $(BUILDPYTHON) Makefile Makefile.pre
31133113

3114-
Python/asm_trampoline.o: $(srcdir)/Python/asm_trampoline.S
3114+
Python/asm_trampoline_x86_64.o: $(srcdir)/Python/asm_trampoline_x86_64.S
31153115
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
31163116

3117+
Python/asm_trampoline_aarch64.o: $(srcdir)/Python/asm_trampoline_aarch64.S
3118+
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
3119+
3120+
Python/asm_trampoline_riscv64.o: $(srcdir)/Python/asm_trampoline_riscv64.S
3121+
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
3122+
3123+
Python/asm_trampoline_universal2.o: Python/asm_trampoline_aarch64.o Python/asm_trampoline_x86_64.o
3124+
lipo -create -output $@ Python/asm_trampoline_aarch64.o Python/asm_trampoline_x86_64.o
3125+
31173126
Python/emscripten_trampoline_inner.wasm: $(srcdir)/Python/emscripten_trampoline_inner.c
31183127
# emcc has a path that ends with emsdk/upstream/emscripten/emcc, we're looking for emsdk/upstream/bin/clang.
31193128
$$(dirname $$(dirname $(CC)))/bin/clang -o $@ $< -mgc -O2 -Wl,--no-entry -Wl,--import-table -Wl,--import-memory -target wasm32-unknown-unknown -nostdlib

Python/asm_trampoline.S

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef ASM_TRAMPOLINE_AARCH_64_H_
2-
#define ASM_TRAMPOLINE_AARCH_64_H_
3-
41
/*
52
* References:
63
* - https://developer.arm.com/documentation/101028/0012/5--Feature-test-macros
@@ -38,6 +35,30 @@
3835
#define GNU_PROPERTY_AARCH64_GCS 0
3936
#endif
4037

38+
.text
39+
#if defined(__APPLE__)
40+
.globl __Py_trampoline_func_start
41+
__Py_trampoline_func_start:
42+
#else
43+
.globl _Py_trampoline_func_start
44+
_Py_trampoline_func_start:
45+
#endif
46+
SIGN_LR
47+
stp x29, x30, [sp, -16]!
48+
mov x29, sp
49+
blr x3
50+
ldp x29, x30, [sp], 16
51+
VERIFY_LR
52+
ret
53+
#if defined(__APPLE__)
54+
.globl __Py_trampoline_func_end
55+
__Py_trampoline_func_end:
56+
#else
57+
.globl _Py_trampoline_func_end
58+
_Py_trampoline_func_end:
59+
.section .note.GNU-stack,"",@progbits
60+
#endif
61+
4162
/* Add the BTI, PAC and GCS support to GNU Notes section */
4263
#if GNU_PROPERTY_AARCH64_BTI != 0 || GNU_PROPERTY_AARCH64_POINTER_AUTH != 0 || GNU_PROPERTY_AARCH64_GCS != 0
4364
.pushsection .note.gnu.property, "a"; /* Start a new allocatable section */
@@ -52,5 +73,3 @@
5273
.long 0; /* padding for 8 byte alignment */
5374
.popsection; /* end the section */
5475
#endif
55-
56-
#endif

Python/asm_trampoline_riscv64.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.text
2+
.globl _Py_trampoline_func_start
3+
_Py_trampoline_func_start:
4+
addi sp,sp,-16
5+
sd ra,8(sp)
6+
jalr a3
7+
ld ra,8(sp)
8+
addi sp,sp,16
9+
jr ra
10+
.globl _Py_trampoline_func_end
11+
_Py_trampoline_func_end:
12+
.section .note.GNU-stack,"",@progbits

Python/asm_trampoline_x86_64.S

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.text
2+
#if defined(__APPLE__)
3+
.globl __Py_trampoline_func_start
4+
__Py_trampoline_func_start:
5+
#else
6+
.globl _Py_trampoline_func_start
7+
_Py_trampoline_func_start:
8+
#endif
9+
#if defined(__CET__) && (__CET__ & 1)
10+
endbr64
11+
#endif
12+
push %rbp
13+
mov %rsp, %rbp
14+
call *%rcx
15+
pop %rbp
16+
ret
17+
#if defined(__APPLE__)
18+
.globl __Py_trampoline_func_end
19+
__Py_trampoline_func_end:
20+
#else
21+
.globl _Py_trampoline_func_end
22+
_Py_trampoline_func_end:
23+
.section .note.GNU-stack,"",@progbits
24+
#endif
25+
# Note for indicating the assembly code supports CET
26+
#if defined(__CET__) && (__CET__ & 1)
27+
.section .note.gnu.property,"a"
28+
.align 8
29+
.long 1f - 0f
30+
.long 4f - 1f
31+
.long 5
32+
0:
33+
.string "GNU"
34+
1:
35+
.align 8
36+
.long 0xc0000002
37+
.long 3f - 2f
38+
2:
39+
.long 0x3
40+
3:
41+
.align 8
42+
4:
43+
#endif

configure

Lines changed: 20 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,20 +3818,37 @@ AC_MSG_RESULT([$SHLIBS])
38183818
dnl perf trampoline is Linux and macOS specific and requires an arch-specific
38193819
dnl trampoline in assembly.
38203820
AC_MSG_CHECKING([perf trampoline])
3821+
PERF_TRAMPOLINE_OBJ=""
38213822
AS_CASE([$PLATFORM_TRIPLET],
3822-
[x86_64-linux-gnu], [perf_trampoline=yes],
3823-
[aarch64-linux-gnu], [perf_trampoline=yes],
3823+
[x86_64-linux-gnu], [perf_trampoline=yes
3824+
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline_x86_64.o],
3825+
[aarch64-linux-gnu], [perf_trampoline=yes
3826+
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline_aarch64.o],
38243827
[darwin], [AS_CASE([$MACOSX_DEPLOYMENT_TARGET],
38253828
[[10.[0-9]|10.1[0-1]]], [perf_trampoline=no],
3826-
[perf_trampoline=yes]
3829+
[perf_trampoline=yes
3830+
if test "${enable_universalsdk}" && test "$UNIVERSAL_ARCHS" = "universal2"; then
3831+
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline_universal2.o
3832+
else
3833+
case "$host_cpu" in
3834+
x86_64)
3835+
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline_x86_64.o
3836+
;;
3837+
aarch64|arm64)
3838+
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline_aarch64.o
3839+
;;
3840+
*)
3841+
perf_trampoline=no
3842+
;;
3843+
esac
3844+
fi]
38273845
)],
38283846
[perf_trampoline=no]
38293847
)
38303848
AC_MSG_RESULT([$perf_trampoline])
38313849

38323850
AS_VAR_IF([perf_trampoline], [yes], [
38333851
AC_DEFINE([PY_HAVE_PERF_TRAMPOLINE], [1], [Define to 1 if you have the perf trampoline.])
3834-
PERF_TRAMPOLINE_OBJ=Python/asm_trampoline.o
38353852
])
38363853
AC_SUBST([PERF_TRAMPOLINE_OBJ])
38373854

0 commit comments

Comments
 (0)