linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
@ 2014-07-08 20:16 behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 1/6] arm: LLVMLinux: Add global named register current_stack_pointer for ARM behanw at converseincode.com
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

The LLVMLinux project aims to fully build the Linux kernel using both gcc and
clang (the C front end for the LLVM compiler infrastructure project). 

Clang only supports global named registers for non-allocatable registers like
the stack pointer. By centralizing the definition of current_stack_pointer, the
use of named registers for ARM remains largely unchanged while working for both
gcc and clang.

Behan Webster (6):
  arm: LLVMLinux: Add global named register current_stack_pointer for
    ARM
  arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address
  arm: LLVMLinux: Use current_stack_pointer for return_address
  arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
  arm: LLVMLinux: Calculate current_thread_info from
    current_stack_pointer
  arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace

 arch/arm/include/asm/ptrace.h      | 5 ++---
 arch/arm/include/asm/thread_info.h | 9 +++++++--
 arch/arm/kernel/return_address.c   | 3 +--
 arch/arm/kernel/stacktrace.c       | 4 +---
 arch/arm/kernel/unwind.c           | 3 +--
 5 files changed, 12 insertions(+), 12 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/6] arm: LLVMLinux: Add global named register current_stack_pointer for ARM
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
@ 2014-07-08 20:16 ` behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 2/6] arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address behanw at converseincode.com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

Define a global named register for current_stack_pointer. The use of this new
variable guarantees that both gcc and clang can access this register in C code.

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

diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index e4e4208..9cb9c66 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -100,6 +100,11 @@ struct thread_info {
 #define init_stack		(init_thread_union.stack)
 
 /*
+ * how to get the current stack pointer in C
+ */
+register unsigned long current_stack_pointer asm ("sp");
+
+/*
  * how to get the thread information struct from C
  */
 static inline struct thread_info *current_thread_info(void) __attribute_const__;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/6] arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 1/6] arm: LLVMLinux: Add global named register current_stack_pointer for ARM behanw at converseincode.com
@ 2014-07-08 20:16 ` behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 3/6] arm: LLVMLinux: Use current_stack_pointer for return_address behanw at converseincode.com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

Use the global current_stack_pointer to calculate the end of the stack for
current_pt_regs()

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

diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index c877654..45bc592 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -148,9 +148,8 @@ 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 *)((current_stack_pointer | (THREAD_SIZE - 1)) - 7) - 1; \
 })
 
 #endif /* __ASSEMBLY__ */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/6] arm: LLVMLinux: Use current_stack_pointer for return_address
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 1/6] arm: LLVMLinux: Add global named register current_stack_pointer for ARM behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 2/6] arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address behanw at converseincode.com
@ 2014-07-08 20:16 ` behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 4/6] arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk behanw at converseincode.com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and Clang.

Signed-off-by: Behan Webster <behanw@converseincode.com>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Reviewed-by: Jan-Simon M??ller <dl9pf@gmx.de>
---
 arch/arm/kernel/return_address.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/kernel/return_address.c b/arch/arm/kernel/return_address.c
index fafedd8..5bceaef 100644
--- a/arch/arm/kernel/return_address.c
+++ b/arch/arm/kernel/return_address.c
@@ -39,13 +39,12 @@ void *return_address(unsigned int level)
 {
 	struct return_address_data data;
 	struct stackframe frame;
-	register unsigned long current_sp asm ("sp");
 
 	data.level = level + 2;
 	data.addr = NULL;
 
 	frame.fp = (unsigned long)__builtin_frame_address(0);
-	frame.sp = current_sp;
+	frame.sp = current_stack_pointer;
 	frame.lr = (unsigned long)__builtin_return_address(0);
 	frame.pc = (unsigned long)return_address;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/6] arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
                   ` (2 preceding siblings ...)
  2014-07-08 20:16 ` [PATCH 3/6] arm: LLVMLinux: Use current_stack_pointer for return_address behanw at converseincode.com
@ 2014-07-08 20:16 ` behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 5/6] arm: LLVMLinux: Calculate current_thread_info from current_stack_pointer behanw at converseincode.com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and clang.

Signed-off-by: Behan Webster <behanw@converseincode.com>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Reviewed-by: Jan-Simon M??ller <dl9pf@gmx.de>
---
 arch/arm/kernel/stacktrace.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
index f065eb0..92b7237 100644
--- a/arch/arm/kernel/stacktrace.c
+++ b/arch/arm/kernel/stacktrace.c
@@ -134,12 +134,10 @@ static noinline void __save_stack_trace(struct task_struct *tsk,
 		frame.pc = thread_saved_pc(tsk);
 #endif
 	} else {
-		register unsigned long current_sp asm ("sp");
-
 		/* We don't want this function nor the caller */
 		data.skip += 2;
 		frame.fp = (unsigned long)__builtin_frame_address(0);
-		frame.sp = current_sp;
+		frame.sp = current_stack_pointer;
 		frame.lr = (unsigned long)__builtin_return_address(0);
 		frame.pc = (unsigned long)__save_stack_trace;
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/6] arm: LLVMLinux: Calculate current_thread_info from current_stack_pointer
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
                   ` (3 preceding siblings ...)
  2014-07-08 20:16 ` [PATCH 4/6] arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk behanw at converseincode.com
@ 2014-07-08 20:16 ` behanw at converseincode.com
  2014-07-08 20:16 ` [PATCH 6/6] arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace behanw at converseincode.com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and clang.

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

diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index 9cb9c66..3184d94 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -111,8 +111,8 @@ static inline struct thread_info *current_thread_info(void) __attribute_const__;
 
 static inline struct thread_info *current_thread_info(void)
 {
-	register unsigned long sp asm ("sp");
-	return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
+	return (struct thread_info *)
+		(current_stack_pointer & ~(THREAD_SIZE - 1));
 }
 
 #define thread_saved_pc(tsk)	\
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/6] arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
                   ` (4 preceding siblings ...)
  2014-07-08 20:16 ` [PATCH 5/6] arm: LLVMLinux: Calculate current_thread_info from current_stack_pointer behanw at converseincode.com
@ 2014-07-08 20:16 ` behanw at converseincode.com
  2014-07-09  9:57 ` [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM Will Deacon
  2014-07-13  9:10 ` Nicolas Pitre
  7 siblings, 0 replies; 11+ messages in thread
From: behanw at converseincode.com @ 2014-07-08 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

From: Behan Webster <behanw@converseincode.com>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and clang.

Signed-off-by: Behan Webster <behanw@converseincode.com>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Reviewed-by: Jan-Simon M??ller <dl9pf@gmx.de>
---
 arch/arm/kernel/unwind.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c
index e67682f..e20e8dc 100644
--- a/arch/arm/kernel/unwind.c
+++ b/arch/arm/kernel/unwind.c
@@ -471,7 +471,6 @@ int unwind_frame(struct stackframe *frame)
 void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 {
 	struct stackframe frame;
-	register unsigned long current_sp asm ("sp");
 
 	pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk);
 
@@ -487,7 +486,7 @@ void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 			 ? regs->ARM_pc : regs->ARM_lr;
 	} else if (tsk == current) {
 		frame.fp = (unsigned long)__builtin_frame_address(0);
-		frame.sp = current_sp;
+		frame.sp = current_stack_pointer;
 		frame.lr = (unsigned long)__builtin_return_address(0);
 		frame.pc = (unsigned long)unwind_backtrace;
 	} else {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
                   ` (5 preceding siblings ...)
  2014-07-08 20:16 ` [PATCH 6/6] arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace behanw at converseincode.com
@ 2014-07-09  9:57 ` Will Deacon
  2014-07-09 11:24   ` Jan-Simon Möller
  2014-07-13  9:10 ` Nicolas Pitre
  7 siblings, 1 reply; 11+ messages in thread
From: Will Deacon @ 2014-07-09  9:57 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jul 08, 2014 at 09:16:10PM +0100, behanw at converseincode.com wrote:
> From: Behan Webster <behanw@converseincode.com>
> 
> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
> clang (the C front end for the LLVM compiler infrastructure project). 
> 
> Clang only supports global named registers for non-allocatable registers like
> the stack pointer. By centralizing the definition of current_stack_pointer, the
> use of named registers for ARM remains largely unchanged while working for both
> gcc and clang.

All looks sane to me. For the series:

  Acked-by: Will Deacon <will.deacon@arm.com>

BTW, have you tried building an arm64 kernel with clang?

Will

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
  2014-07-09  9:57 ` [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM Will Deacon
@ 2014-07-09 11:24   ` Jan-Simon Möller
  0 siblings, 0 replies; 11+ messages in thread
From: Jan-Simon Möller @ 2014-07-09 11:24 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Will,


> BTW, have you tried building an arm64 kernel with clang?

ragarding arm64: yes, there is a test target already - see  
http://git.linuxfoundation.org/?p=llvmlinux.git;a=tree;f=targets/vexpress64

Reproduce with:
git clone http://git.linuxfoundation.org/llvmlinux.git
cd llvmlinux/targets/vexpress64
make


Best,
Jan-Simon

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
  2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
                   ` (6 preceding siblings ...)
  2014-07-09  9:57 ` [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM Will Deacon
@ 2014-07-13  9:10 ` Nicolas Pitre
  2014-07-17  4:17   ` Behan Webster
  7 siblings, 1 reply; 11+ messages in thread
From: Nicolas Pitre @ 2014-07-13  9:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 8 Jul 2014, behanw at converseincode.com wrote:

> From: Behan Webster <behanw@converseincode.com>
> 
> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
> clang (the C front end for the LLVM compiler infrastructure project). 
> 
> Clang only supports global named registers for non-allocatable registers like
> the stack pointer. By centralizing the definition of current_stack_pointer, the
> use of named registers for ARM remains largely unchanged while working for both
> gcc and clang.

You verified that the compiled code is identical on gcc?  If so:

Acked-by: Nicolas Pitre <nico@linaro.org>

> 
> Behan Webster (6):
>   arm: LLVMLinux: Add global named register current_stack_pointer for
>     ARM
>   arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address
>   arm: LLVMLinux: Use current_stack_pointer for return_address
>   arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
>   arm: LLVMLinux: Calculate current_thread_info from
>     current_stack_pointer
>   arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace
> 
>  arch/arm/include/asm/ptrace.h      | 5 ++---
>  arch/arm/include/asm/thread_info.h | 9 +++++++--
>  arch/arm/kernel/return_address.c   | 3 +--
>  arch/arm/kernel/stacktrace.c       | 4 +---
>  arch/arm/kernel/unwind.c           | 3 +--
>  5 files changed, 12 insertions(+), 12 deletions(-)
> 
> -- 
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
  2014-07-13  9:10 ` Nicolas Pitre
@ 2014-07-17  4:17   ` Behan Webster
  0 siblings, 0 replies; 11+ messages in thread
From: Behan Webster @ 2014-07-17  4:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 07/13/14 02:10, Nicolas Pitre wrote:
> On Tue, 8 Jul 2014, behanw at converseincode.com wrote:
>
>> From: Behan Webster <behanw@converseincode.com>
>>
>> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
>> clang (the C front end for the LLVM compiler infrastructure project).
>>
>> Clang only supports global named registers for non-allocatable registers like
>> the stack pointer. By centralizing the definition of current_stack_pointer, the
>> use of named registers for ARM remains largely unchanged while working for both
>> gcc and clang.
> You verified that the compiled code is identical on gcc?
Yes. Identical.

>    If so:
>
> Acked-by: Nicolas Pitre <nico@linaro.org>
Thanks,

Behan

-- 
Behan Webster
behanw at converseincode.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-17  4:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-08 20:16 [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM behanw at converseincode.com
2014-07-08 20:16 ` [PATCH 1/6] arm: LLVMLinux: Add global named register current_stack_pointer for ARM behanw at converseincode.com
2014-07-08 20:16 ` [PATCH 2/6] arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address behanw at converseincode.com
2014-07-08 20:16 ` [PATCH 3/6] arm: LLVMLinux: Use current_stack_pointer for return_address behanw at converseincode.com
2014-07-08 20:16 ` [PATCH 4/6] arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk behanw at converseincode.com
2014-07-08 20:16 ` [PATCH 5/6] arm: LLVMLinux: Calculate current_thread_info from current_stack_pointer behanw at converseincode.com
2014-07-08 20:16 ` [PATCH 6/6] arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace behanw at converseincode.com
2014-07-09  9:57 ` [PATCH 0/6] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM Will Deacon
2014-07-09 11:24   ` Jan-Simon Möller
2014-07-13  9:10 ` Nicolas Pitre
2014-07-17  4:17   ` Behan Webster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).