Skip to content

Commit f9daab0

Browse files
MaskRaywilldeacon
authored andcommitted
arm64: jump_label: use constraints "Si" instead of "i"
The generic constraint "i" seems to be copied from x86 or arm (and with a redundant generic operand modifier "c"). It works with -fno-PIE but not with -fPIE/-fPIC in GCC's aarch64 port. The machine constraint "S", which denotes a symbol or label reference with a constant offset, supports PIC and has been available in GCC since 2012 and in Clang since 7.0. However, Clang before 19 does not support "S" on a symbol with a constant offset [1] (e.g. `static_key_false(&nf_hooks_needed[pf][hook])` in include/linux/netfilter.h), so we use "i" as a fallback. Suggested-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Fangrui Song <maskray@google.com> Link: llvm/llvm-project#80255 [1] Acked-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20240206074552.541154-1-maskray@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent c0b26c0 commit f9daab0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

arch/arm64/include/asm/jump_label.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
#define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE
1717

18+
/*
19+
* Prefer the constraint "S" to support PIC with GCC. Clang before 19 does not
20+
* support "S" on a symbol with a constant offset, so we use "i" as a fallback.
21+
*/
1822
static __always_inline bool arch_static_branch(struct static_key * const key,
1923
const bool branch)
2024
{
@@ -23,9 +27,9 @@ static __always_inline bool arch_static_branch(struct static_key * const key,
2327
" .pushsection __jump_table, \"aw\" \n\t"
2428
" .align 3 \n\t"
2529
" .long 1b - ., %l[l_yes] - . \n\t"
26-
" .quad %c0 - . \n\t"
30+
" .quad (%[key] - .) + %[bit0] \n\t"
2731
" .popsection \n\t"
28-
: : "i"(&((char *)key)[branch]) : : l_yes);
32+
: : [key]"Si"(key), [bit0]"i"(branch) : : l_yes);
2933

3034
return false;
3135
l_yes:
@@ -40,9 +44,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
4044
" .pushsection __jump_table, \"aw\" \n\t"
4145
" .align 3 \n\t"
4246
" .long 1b - ., %l[l_yes] - . \n\t"
43-
" .quad %c0 - . \n\t"
47+
" .quad (%[key] - .) + %[bit0] \n\t"
4448
" .popsection \n\t"
45-
: : "i"(&((char *)key)[branch]) : : l_yes);
49+
: : [key]"Si"(key), [bit0]"i"(branch) : : l_yes);
4650

4751
return false;
4852
l_yes:

0 commit comments

Comments
 (0)