Skip to content

Commit c1e42ef

Browse files
ardbiesheuvelRussell King (Oracle)
authored andcommitted
ARM: 9151/1: Thumb2: avoid __builtin_thread_pointer() on Clang
If available, we use the __builtin_thread_pointer() helper to get the value of the TLS register, to help the compiler understand that it doesn't need to reload it every time we access 'current'. Unfortunately, Clang fails to emit the MRC system register read directly when building for Thumb2, and instead, it issues a call to the __aeabi_read_tp helper, which the kernel does not provide, and so this result in link failures at build time. So create a special case for this, and emit the MRC directly using an asm() block, just like we do when the helper is not available to begin with. Link: ClangBuiltLinux#1485 Reviewed-by: Nick Desaulniers <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent fa191b7 commit c1e42ef

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/arm/include/asm/current.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ static inline struct task_struct *get_current(void)
2626
{
2727
struct task_struct *cur;
2828

29-
#if __has_builtin(__builtin_thread_pointer)
29+
#if __has_builtin(__builtin_thread_pointer) && \
30+
!(defined(CONFIG_THUMB2_KERNEL) && \
31+
defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 130001)
3032
/*
3133
* Use the __builtin helper when available - this results in better
3234
* code, especially when using GCC in combination with the per-task
3335
* stack protector, as the compiler will recognize that it needs to
3436
* load the TLS register only once in every function.
37+
*
38+
* Clang < 13.0.1 gets this wrong for Thumb2 builds:
39+
* https://github.com/ClangBuiltLinux/linux/issues/1485
3540
*/
3641
cur = __builtin_thread_pointer();
3742
#else

0 commit comments

Comments
 (0)