From 60e45ad86cf6f61fa1508ed07fdb5966f164d3c2 Mon Sep 17 00:00:00 2001 From: Luke Craig Date: Tue, 31 Mar 2026 14:05:37 -0400 Subject: [PATCH] gen_portal_tramp: fix mips bug with nop padding --- scripts/gen_portal_tramp.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/gen_portal_tramp.py b/scripts/gen_portal_tramp.py index 34d4265..b7df268 100644 --- a/scripts/gen_portal_tramp.py +++ b/scripts/gen_portal_tramp.py @@ -5,9 +5,19 @@ print("// Auto-generated trampoline functions\n") print("#define PORTAL_TRAMPOLINE_COUNT {0}\n".format(COUNT)) + +# Conditionally apply the NOP padding only for MIPS targets to fix the kprobe branch bug. +# For all other architectures, emit an empty asm block that still embeds the unique ID +# to universally defeat Identical Code Folding (ICF). +print("#if defined(__mips__)") +print("#define TRAMP_BODY(i) asm volatile(\"nop\\n\\tnop\\n\\tnop\\n\\tnop\" : : \"i\"(i))") +print("#else") +print("#define TRAMP_BODY(i) asm volatile(\"\" : : \"i\"(i))") +print("#endif\n") + for i in range(COUNT): print(f"void portal_tramp_fn_{i:x}(void);") - print(f"void portal_tramp_fn_{i:x}(void) {{}}") + print(f"void portal_tramp_fn_{i:x}(void) {{ TRAMP_BODY({i}); }}") print("\nvoid (*portal_tramp_table[{0}])(void) = {{".format(COUNT)) for i in range(COUNT):