Skip to content

Commit dbaaabd

Browse files
committed
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 llvm/llvm-project#20571 (comment) 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: llvm/llvm-project#20571 Cc: Peter Zijlstra <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a38297e commit dbaaabd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/linux/compiler-clang.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,13 @@
118118

119119
#define __diag_ignore_all(option, comment) \
120120
__diag_clang(13, ignore, option)
121+
122+
/*
123+
* clang has horrible behavior with "g" or "rm" constraints for asm
124+
* inputs, turning them into something worse than "m". Avoid using
125+
* constraints with multiple possible uses (but "ir" seems to be ok):
126+
*
127+
* https://github.com/llvm/llvm-project/issues/20571
128+
*/
129+
#define ASM_INPUT_G "ir"
130+
#define ASM_INPUT_RM "r"

include/linux/compiler_types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,15 @@ struct ftrace_likely_data {
391391
#define asm_goto_output(x...) asm volatile goto(x)
392392
#endif
393393

394+
/*
395+
* Clang has trouble with constraints with multiple
396+
* alternative behaviors (mainly "g" and "rm").
397+
*/
398+
#ifndef ASM_INPUT_G
399+
#define ASM_INPUT_G "g"
400+
#define ASM_INPUT_RM "rm"
401+
#endif
402+
394403
#ifdef CONFIG_CC_HAS_ASM_INLINE
395404
#define asm_inline asm __inline
396405
#else

0 commit comments

Comments
 (0)