Dmitry Voytik
unread,Jul 2, 2026, 6:41:39 AMJul 2Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Borislav Petkov, linux-to...@vger.kernel.org, Alexander Potapenko, Peter Zijlstra, Thomas Gleixner, Ingo Molnar, Dave Hansen, Josh Poimboeuf, Dmitry Vyukov, Andrew Morton, Ankur Arora, H . Peter Anvin, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Marco Elver, x...@kernel.org, linux-...@vger.kernel.org, kasa...@googlegroups.com, linu...@kvack.org, ll...@lists.linux.dev
Hi Borislav,
Very good question. My uneducated guess - bugs in clang.
Out of curiosity, I compared (see below) what clang and gcc do when
ASM_CALL_CONSTRAINT moves around, and it indeed affects generated
code, which is weird.
I might just be holding it wrong, like optimization must be on, etc.
> If that were the case, we have a bunch more of those bugs around the tree.
At least, it makes objtool happy for the defconfig + KMSAN.
> Anyway, + linux-toolchains.
Thanks for looking into this.
Comparing clang and gcc:
// clang asm_clang.c -o out
// gcc asm_clang.c -o out
// objdump -d --disassemble=main out
#include <stdio.h>
int func() {
return 42;
}
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
# define __ASM_FORM_RAW(x, ...) __stringify(x,##__VA_ARGS__)
# define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
#define __ASM_REG(reg) __ASM_SEL_RAW(e##reg, r##reg)
#define _ASM_SP __ASM_REG(sp)
register unsigned long current_stack_pointer asm(_ASM_SP);
#define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
int main() {
int output_val = 0;
__asm__ __volatile__ ( "call func\n\t" : "=a" (output_val) : :);
// clang v22.1.6
// 1142: e8 d9 ff ff ff call 1120 <func>
// 1147: 89 45 f8 mov %eax,-0x8(%rbp)
// gcc:
// 112f: e8 e5 ff ff ff call 1119 <func>
// 1134: 89 45 fc mov %eax,-0x4(%rbp)
__asm__ __volatile__ (
"call func\n\t" : ASM_CALL_CONSTRAINT, "=a" (output_val) : :);
// clang v22.1.6
// 114a: 48 89 e0 mov %rsp,%rax
// 114d: 48 89 c4 mov %rax,%rsp
// 1150: e8 cb ff ff ff call 1120 <func>
// 1155: 48 89 e1 mov %rsp,%rcx
// 1158: 48 89 cc mov %rcx,%rsp
// 115b: 89 45 f8 mov %eax,-0x8(%rbp)
// gcc:
// 1137: e8 dd ff ff ff call 1119 <func>
// 113c: 89 45 fc mov %eax,-0x4(%rbp)
__asm__ __volatile__ (
"call func\n\t" : "=a" (output_val), ASM_CALL_CONSTRAINT : :);
// clang v22.1.6
// 115e: 48 89 e0 mov %rsp,%rax
// 1161: 48 89 c4 mov %rax,%rsp
// 1164: e8 b7 ff ff ff call 1120 <func>
// 1169: 89 c1 mov %eax,%ecx
// 116b: 48 89 e0 mov %rsp,%rax
// 116e: 89 4d f8 mov %ecx,-0x8(%rbp)
// 1171: 48 89 c4 mov %rax,%rsp
// gcc:
// 113f: e8 d5 ff ff ff call 1119 <func>
// 1144: 89 45 fc mov %eax,-0x4(%rbp)
return 0;