Skip to content

Commit 8735871

Browse files
dwmw2Ingo Molnar
authored andcommitted
x86/retpoline: Support retpoline builds with Clang
Signed-off-by: David Woodhouse <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[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: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent dd84441 commit 8735871

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

arch/x86/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
232232

233233
# Avoid indirect branches in kernel to deal with Spectre
234234
ifdef CONFIG_RETPOLINE
235-
RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
235+
RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
236+
RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
237+
238+
RETPOLINE_CFLAGS += $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
236239
ifneq ($(RETPOLINE_CFLAGS),)
237240
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
238241
endif

include/linux/compiler-clang.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@
2727
#if __has_feature(address_sanitizer)
2828
#define __SANITIZE_ADDRESS__
2929
#endif
30+
31+
/* Clang doesn't have a way to turn it off per-function, yet. */
32+
#ifdef __noretpoline
33+
#undef __noretpoline
34+
#endif

include/linux/compiler-gcc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@
9393
#define __weak __attribute__((weak))
9494
#define __alias(symbol) __attribute__((alias(#symbol)))
9595

96+
#ifdef RETPOLINE
97+
#define __noretpoline __attribute__((indirect_branch("keep")))
98+
#endif
99+
96100
/*
97101
* it doesn't make sense on ARM (currently the only user of __naked)
98102
* to trace naked functions because then mcount is called without

include/linux/init.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include <linux/types.h>
77

88
/* Built-in __init functions needn't be compiled with retpoline */
9-
#if defined(RETPOLINE) && !defined(MODULE)
10-
#define __noretpoline __attribute__((indirect_branch("keep")))
9+
#if defined(__noretpoline) && !defined(MODULE)
10+
#define __noinitretpoline __noretpoline
1111
#else
12-
#define __noretpoline
12+
#define __noinitretpoline
1313
#endif
1414

1515
/* These macros are used to mark some functions or
@@ -47,7 +47,7 @@
4747

4848
/* These are for everybody (although not all archs will actually
4949
discard it in modules) */
50-
#define __init __section(.init.text) __cold __latent_entropy __noretpoline
50+
#define __init __section(.init.text) __cold __latent_entropy __noinitretpoline
5151
#define __initdata __section(.init.data)
5252
#define __initconst __section(.init.rodata)
5353
#define __exitdata __section(.exit.data)

0 commit comments

Comments
 (0)