LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
Subsystems (2)
cover LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
From: Behan Webster <[email protected]>
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(-)
Signature · 1 line
1.9.1
PATCH 1/6 arm: LLVMLinux: Add global named register current_stack_pointer for ARM
From: Behan Webster <[email protected]>
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.
--- arch/arm/include/asm/thread_info.h | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/include/asm/thread_info.h +5 -0
@@ -100,6 +100,11 @@ struct thread_info {#define init_stack (init_thread_union.stack)/* +* how to get the current stack pointer in C +*/ +registerunsigned 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__;
Signature · 1 line
1.9.1
PATCH 2/6 arm: LLVMLinux: Use current_stack_pointer to calculate pt_regs address
In reply to [email protected]From: Behan Webster <[email protected]>
Use the global current_stack_pointer to calculate the end of the stack for current_pt_regs()
--- arch/arm/include/asm/ptrace.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/include/asm/ptrace.h +2 -3
@@ -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__ */
Signature · 1 line
1.9.1
PATCH 3/6 arm: LLVMLinux: Use current_stack_pointer for return_address
In reply to [email protected]From: Behan Webster <[email protected]>
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.
--- arch/arm/kernel/return_address.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/kernel/return_address.c +1 -2
@@ -39,13 +39,12 @@ void *return_address(unsigned int level) {struct return_address_data data;struct stackframe frame; - registerunsigned 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;
Signature · 1 line
1.9.1
PATCH 4/6 arm: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
In reply to [email protected]From: Behan Webster <[email protected]>
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.
--- arch/arm/kernel/stacktrace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm/kernel/stacktrace.c +1 -3
@@ -134,12 +134,10 @@ static noinline void __save_stack_trace(struct task_struct *tsk, frame.pc =thread_saved_pc (tsk);#endif }else { - registerunsigned 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; }
Signature · 1 line
1.9.1
PATCH 5/6 arm: LLVMLinux: Calculate current_thread_info from current_stack_pointer
In reply to [email protected]From: Behan Webster <[email protected]>
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.
--- arch/arm/include/asm/thread_info.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/include/asm/thread_info.h +2 -2
@@ -111,8 +111,8 @@ static inline struct thread_info *current_thread_info(void) __attribute_const__;static inline struct thread_info *current_thread_info (void ) { - registerunsigned 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) \
Signature · 1 line
1.9.1
PATCH 6/6 arm: LLVMLinux: Use current_stack_pointer in unwind_backtrace
In reply to [email protected]From: Behan Webster <[email protected]>
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.
--- arch/arm/kernel/unwind.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/kernel/unwind.c +1 -2
@@ -471,7 +471,6 @@ int unwind_frame(struct stackframe *frame)void unwind_backtrace (struct pt_regs *regs,struct task_struct *tsk) {struct stackframe frame; - registerunsigned 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 {
Signature · 1 line
1.9.1
Quoted 9 lines · On Tue, Jul 08, 2014 at 09:16:10PM +0100, [email protected] wrote:
From: Behan Webster <[email protected]>
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:
BTW, have you tried building an arm64 kernel with clang?
Will
Hi Will,
Quoted 1 line
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
Quoted 9 lines · behanw at converseincode.com
From: Behan Webster <[email protected]>
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:
Quoted 28 lines
Behan Webster (6):
arm: LLVMLinux: Add global named registercurrent_stack_pointerfor
ARM
arm: LLVMLinux: Usecurrent_stack_pointerto calculatept_regsaddress
arm: LLVMLinux: Usecurrent_stack_pointerforreturn_address
arm: LLVMLinux: Usecurrent_stack_pointerinsave_stack_trace_tsk
arm: LLVMLinux: Calculatecurrent_thread_infofrom
current_stack_pointer
arm: LLVMLinux: Usecurrent_stack_pointerinunwind_backtracearch/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(-)Signature · 7 lines
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/
Quoted 4 lines · Nicolas Pitre
Quoted 2 lines · behanw at converseincode.com
From: Behan Webster <[email protected]>
Quoted 8 lines
Quoted 7 lines
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.
Quoted 3 lines
If so:
Acked-by Nicolas Pitre <[email protected]>
Thanks,
Behan
Signature · 2 lines
Behan Webster behanw at converseincode.com