diff mbox

arm: LLVMLinux: Calculate pt_regs address from fp

Message ID 1378503762-7236-2-git-send-email-behanw@converseincode.com
State New
Headers show

Commit Message

Behan Webster Sept. 6, 2013, 9:42 p.m. UTC
From: Behan Webster <behanw@converseincode.com>

Use the frame pointer to calculate the end of the stack for current_pt_regs()
The existing code uses the stack pointer to do this calculation.
Using the frame pointer yeilds the same value in a more portable way.
This change supports being able to compile the kernel with gcc and clang.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
---
 arch/arm/include/asm/ptrace.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Russell King - ARM Linux Sept. 6, 2013, 10:18 p.m. UTC | #1
On Fri, Sep 06, 2013 at 05:42:41PM -0400, behanw@converseincode.com wrote:
> From: Behan Webster <behanw@converseincode.com>
> 
> Use the frame pointer to calculate the end of the stack for current_pt_regs()
> The existing code uses the stack pointer to do this calculation.
> Using the frame pointer yeilds the same value in a more portable way.
> This change supports being able to compile the kernel with gcc and clang.

What happens when frame pointers are disabled on gcc?
Behan Webster Sept. 6, 2013, 11:02 p.m. UTC | #2
On 09/06/13 18:18, Russell King - ARM Linux wrote:
> On Fri, Sep 06, 2013 at 05:42:41PM -0400, behanw@converseincode.com wrote:
>> From: Behan Webster <behanw@converseincode.com>
>>
>> Use the frame pointer to calculate the end of the stack for current_pt_regs()
>> The existing code uses the stack pointer to do this calculation.
>> Using the frame pointer yeilds the same value in a more portable way.
>> This change supports being able to compile the kernel with gcc and clang.
> What happens when frame pointers are disabled on gcc?
Drat. Good point. Didn't think of that.

Could be rewritten to use current_stack_pointer (assuming the patch 
series that implements that would be amenable).

Thanks,

Behan
diff mbox

Patch

diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index 04c99f3..8aec2db 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -138,9 +138,9 @@  static inline unsigned long user_stack_pointer(struct pt_regs *regs)
 	return regs->ARM_sp;
 }
 
-#define current_pt_regs(void) ({				\
-	register unsigned long sp asm ("sp");			\
-	(struct pt_regs *)((sp | (THREAD_SIZE - 1)) - 7) - 1;	\
+#define current_pt_regs(void) ({					\
+	(struct pt_regs *)(((unsigned long)(__builtin_frame_address(0))	\
+		| (THREAD_SIZE - 1)) - 7) - 1;				\
 })
 
 #endif /* __ASSEMBLY__ */