LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM
Subsystems (3)
v2 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
Mark Charlebois (1):
arm: LLVMLinux: Use global stack register variable for percpu
arch/arm/include/asm/percpu.h | 4 ++-- 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 +-- 6 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/7 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
@@ -101,6 +101,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 v2 2/7 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
@@ -154,9 +154,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 v2 3/7 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 v2 4/7 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 v2 5/7 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
@@ -112,8 +112,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 v2 6/7 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);
@@ -485,7 +484,7 @@ void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk) frame.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
PATCH v2 7/7 arm: LLVMLinux: Use global stack register variable for percpu
In reply to [email protected]From: Mark Charlebois <[email protected]>
Using global current_stack_pointer works on both clang and gcc. current_stack_pointer is an unsigned long and needs to be cast as a pointer to dereference.
--- arch/arm/include/asm/percpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/include/asm/percpu.h +2 -2
@@ -30,14 +30,14 @@ static inline void set_my_cpu_offset(unsigned long off)static inline unsigned long __my_cpu_offset (void ) {unsigned long off; - registerunsigned long *sp asm ("sp" );/* * Read TPIDRPRW. * We want to allow caching the value, so avoid using volatile and * instead use a fake stack read to hazard against barrier(). */ - asm("mrc p15, 0, %0, c13, c0, 4" :"=r" (off) :"Q" (*sp)); + asm("mrc p15, 0, %0, c13, c0, 4" :"=r" (off) + :"Q" (*(const unsigned long *)current_stack_pointer));return off; }
Signature · 1 line
1.9.1