Skip to content

Commit b1ae32d

Browse files
Alexei StarovoitovKAGA-KOKO
authored andcommitted
x86/cpufeature: Guard asm_volatile_goto usage for BPF compilation
Workaround for the sake of BPF compilation which utilizes kernel headers, but clang does not support ASM GOTO and fails the build. Fixes: d026604 ("x86: Remove FAST_FEATURE_TESTS") Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 13ebe18 commit b1ae32d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
140140

141141
#define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)
142142

143+
#if defined(__clang__) && !defined(CC_HAVE_ASM_GOTO)
144+
145+
/*
146+
* Workaround for the sake of BPF compilation which utilizes kernel
147+
* headers, but clang does not support ASM GOTO and fails the build.
148+
*/
149+
#ifndef __BPF_TRACING__
150+
#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
151+
#endif
152+
153+
#define static_cpu_has(bit) boot_cpu_has(bit)
154+
155+
#else
156+
143157
/*
144158
* Static testing of CPU features. Used the same as boot_cpu_has().
145159
* These will statically patch the target code for additional
@@ -195,6 +209,7 @@ static __always_inline __pure bool _static_cpu_has(u16 bit)
195209
boot_cpu_has(bit) : \
196210
_static_cpu_has(bit) \
197211
)
212+
#endif
198213

199214
#define cpu_has_bug(c, bit) cpu_has(c, (bit))
200215
#define set_cpu_bug(c, bit) set_cpu_cap(c, (bit))

samples/bpf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
255255
$(obj)/%.o: $(src)/%.c
256256
$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
257257
-I$(srctree)/tools/testing/selftests/bpf/ \
258-
-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
258+
-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
259259
-D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
260260
-Wno-gnu-variable-sized-type-not-at-end \
261261
-Wno-address-of-packed-member -Wno-tautological-compare \

0 commit comments

Comments
 (0)