AArch64 JIT trampoline clobbers x8
還沒有人認領這個 Issue。
評估
研究方向
從 Python/jit.c 中的 patch_aarch64_trampoline 開始,然後執行提供的 AArch64 C 重現程式以觀察 x8 失敗。檢查報告中描述的 AAPCS64 和 BTI 限制;完成的標準是 trampoline 不再覆寫大型結構體結果緩衝區暫存器,且重現程式成功執行。
由索引模型根據 Issue 內容生成。
描述
Bug report
Bug description:
While auditing the indirect branches the JIT emits on AArch64 for BTI compatibility (part of investigating gh-149697), I noticed that the trampoline for calls out of range of a bl (patch_aarch64_trampoline in Python/jit.c) is:
ldr x8, 8
br x8
The AAPCS64 only allows a veneer to alter x16, x17 and the flags, which is why the linkers' own long-branch stubs use x16. x8 carries the address of the result buffer when the callee returns a struct too large for registers, so a callee reached through this trampoline would store its result through the trampoline's target address instead.
THere is no helper at the moment where a JIT call would return such a struct but a standalone program calling a function that returns a 32-byte struct through the same 16 bytes segfaults with x8 and works with x16. A simple reproducer:
#include <stdio.h>
typedef struct { long a, b, c, d; } big; /* returned through x8 */
big make_big(long x) { return (big){x, x + 1, x + 2, x + 3}; }
/* trampolines */
__asm__(
"via_x8: ldr x8, 1f\n br x8\n 1: .xword make_big\n"
"via_x16: ldr x16, 2f\n br x16\n 2: .xword make_big\n"
);
big via_x8(long), via_x16(long);
int main(void)
{
big r = via_x16(40);
printf("via x16: %ld %ld %ld %ld\n", r.a, r.b, r.c, r.d);
fflush(stdout);
r = via_x8(40);
printf("via x8: %ld %ld %ld %ld\n", r.a, r.b, r.c, r.d);
}
$ gcc -O2 -g repro.c && ./a.out
via x16: 40 41 42 43
Segmentation fault (core dumped)
Using x16 also makes the br acceptable to a BTI C landing pad once JIT memory is mapped with PROT_BTI, which the linkers' stubs already satisfy.
Introduced in gh-119726.
cc @diegorusso
CPython versions tested on:
CPython main branch, 3.16, 3.15, 3.14
Operating systems tested on:
Linux
Linked PRs
- gh-157527
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 平均合併
- 1 天 9 小時
- 30 天內合併 PR
- 558
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
docs pending
難度 2/5 1-3 小時 新手友好度 78/100
-
stdlib type-feature
難度 2/5 1-3 小時 新手友好度 78/100
-
stdlib type-feature
難度 2/5 1-3 小時 新手友好度 72/100
-
build type-bug
難度 2/5 1-3 小時 新手友好度 76/100
-
stdlib topic-email type-feature
難度 2/5 1-3 小時 新手友好度 70/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未關閉CI
難度 2/5 1-3 小時 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難度 2/5 1-3 小時 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 74/100