From: Zqiang <qiang.zh...@windriver.com>

This change is similar to the following patch,  
it also suitable for arm.

[
Author: Steven Rostedt (VMware)
Email: rost...@goodmis.org
Subject: tracing/arm64: Have max stack tracer handle the case of return address 
after data
Date: Fri, 9 Aug 2019 02:15:05 +0000

Most archs (well at least x86) store the function call return address on the
stack before storing the local variables for the function. The max stack
tracer depends on this in its algorithm to display the stack size of each
function it finds in the back trace.

Some archs (arm64), may store the return address (from its link register)
just before calling a nested function. There's no reason to save the link
register on leaf functions, as it wont be updated. This breaks the algorithm
of the max stack tracer.

Add a new define ARCH_FTRACE_SHIFT_STACK_TRACER that an architecture may set
if it stores the return address (link register) after it stores the
function's local variables, and have the stack trace shift the values of the
mapped stack size to the appropriate functions.

Link: 20190802094103.163576-1-jiping....@windriver.com

Reported-by: Jiping Ma <jiping....@windriver.com>
Acked-by: Will Deacon <w...@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rost...@goodmis.org>
Signed-off-by: Jiping Ma <jiping....@windriver.com>
]

Signed-off-by: Zqiang <qiang.zh...@windriver.com>
---
 arch/arm/include/asm/ftrace.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h
index 48ec1d0337da..c70f8fb13ae3 100644
--- a/arch/arm/include/asm/ftrace.h
+++ b/arch/arm/include/asm/ftrace.h
@@ -10,6 +10,19 @@
 #define MCOUNT_ADDR            ((unsigned long)(__gnu_mcount_nc))
 #define MCOUNT_INSN_SIZE       4 /* sizeof mcount call */

+/*
+ * Currently, gcc tends to save the link register after the local variables
+ * on the stack. This causes the max stack tracer to report the function
+ * frame sizes for the wrong functions. By defining
+ * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect
+ * to find the return address on the stack after the local variables have
+ * been set up.
+ *
+ * Note, this may change in the future, and we will need to deal with that
+ * if it were to happen.
+ */
+#define ARCH_FTRACE_SHIFT_STACK_TRACER 1
+
 #ifndef __ASSEMBLY__
 extern void __gnu_mcount_nc(void);

--
2.29.2
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#9870): 
https://lists.yoctoproject.org/g/linux-yocto/message/9870
Mute This Topic: https://lists.yoctoproject.org/mt/82792448/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to