termux-packages/packages/uftrace/arm-clang-mcount-hook.patch

32 lines
704 B
Diff

diff --git a/arch/arm/mcount.S b/arch/arm/mcount.S
index bbfc597..eb28831 100644
--- a/arch/arm/mcount.S
+++ b/arch/arm/mcount.S
@@ -60,6 +60,26 @@ GLOBAL(__gnu_mcount_nc)
bx ip
END(__gnu_mcount_nc)
+/* for clang */
+GLOBAL(mcount)
+ push {r0-r3, lr}
+ ands r3, lr, #1 /* check lr for ARM/THUMB detection */
+ add r0, fp, #4 /* r0 points to pushed LR */
+ bne 1f
+ ldr r1, [fp] /* fp (=r11) might point to return address on ARM */
+ ldr r2, [r0]
+ cmp r1, r2
+ moveq r0, lr
+1:
+ mov r1, lr /* child ip */
+ mov r2, sp /* mcount_args */
+
+ bl mcount_entry
+
+ pop {r0-r3, lr}
+ bx lr
+END(mcount)
+
ENTRY(mcount_return)
push {r0-r3, lr, pc} /* ensure 8-byte alignment */