arch/arm64: fix backtrace return address precision

The return address stored in the frame should point to the instruction
after the call. To get the actual call site, we need to subtract the
instruction size (sizeof(void *)) from the saved return address.

This ensures that backtrace addresses correctly point to the calling
instruction rather than the next instruction.

Signed-off-by: yinshengkai <yinshengkai@bytedance.com>
This commit is contained in:
yinshengkai
2025-12-01 19:43:23 +08:00
committed by Xiang Xiao
parent 1d6d682947
commit 5892554984
+15 -2
View File
@@ -44,6 +44,19 @@
* Description:
* backtrace() parsing the return address through frame pointer
*
* Note:
*
* The stack layout is as follows:
*
* Stack (grows downward):
* +--------------------+
* high addr | locals of A |
* +--------------------+
* | prev_fp(A)=0 | ← FP of A (first frame)
* | saved_lr(A) |
* +--------------------+
* | locals of B |
*
****************************************************************************/
nosanitize_address
@@ -57,7 +70,7 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
{
if ((*skip)-- <= 0)
{
buffer[i++] = pc;
buffer[i++] = (void *)((uintptr_t)pc - sizeof(void *));
}
}
@@ -70,7 +83,7 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
if ((*skip)-- <= 0)
{
buffer[i++] = (void *)*(fp + 1);
buffer[i++] = (void *)(*(fp + 1) - sizeof(void *));
}
}