Commit dbaaabd6 authored by Linus Torvalds's avatar Linus Torvalds

clang: work around asm input constraint problems

Work around clang problems with asm constraints that have multiple
possibilities, particularly "g" and "rm".

Clang seems to turn inputs like that into the most generic form, which
is the memory input - but to make matters worse, clang won't even use a
possible original memory location, but will spill the value to stack,
and use the stack for the asm input.

See

  https://github.com/llvm/llvm-project/issues/20571#issuecomment-980933442

for some explanation of why clang has this strange behavior, but the end
result is that "g" and "rm" really end up generating horrid code.

Link: https://github.com/llvm/llvm-project/issues/20571
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a38297e3
...@@ -118,3 +118,13 @@ ...@@ -118,3 +118,13 @@
#define __diag_ignore_all(option, comment) \ #define __diag_ignore_all(option, comment) \
__diag_clang(13, ignore, option) __diag_clang(13, ignore, option)
/*
* clang has horrible behavior with "g" or "rm" constraints for asm
* inputs, turning them into something worse than "m". Avoid using
* constraints with multiple possible uses (but "ir" seems to be ok):
*
* https://github.com/llvm/llvm-project/issues/20571
*/
#define ASM_INPUT_G "ir"
#define ASM_INPUT_RM "r"
...@@ -391,6 +391,15 @@ struct ftrace_likely_data { ...@@ -391,6 +391,15 @@ struct ftrace_likely_data {
#define asm_goto_output(x...) asm volatile goto(x) #define asm_goto_output(x...) asm volatile goto(x)
#endif #endif
/*
* Clang has trouble with constraints with multiple
* alternative behaviors (mainly "g" and "rm").
*/
#ifndef ASM_INPUT_G
#define ASM_INPUT_G "g"
#define ASM_INPUT_RM "rm"
#endif
#ifdef CONFIG_CC_HAS_ASM_INLINE #ifdef CONFIG_CC_HAS_ASM_INLINE
#define asm_inline asm __inline #define asm_inline asm __inline
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment