Commit 87358710 authored by David Woodhouse's avatar David Woodhouse Committed by Ingo Molnar

x86/retpoline: Support retpoline builds with Clang

Signed-off-by: default avatarDavid Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: arjan.van.de.ven@intel.com
Cc: bp@alien8.de
Cc: dave.hansen@intel.com
Cc: jmattson@google.com
Cc: karahmed@amazon.de
Cc: kvm@vger.kernel.org
Cc: pbonzini@redhat.com
Cc: rkrcmar@redhat.com
Link: http://lkml.kernel.org/r/1519037457-7643-5-git-send-email-dwmw@amazon.co.ukSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent dd84441a
...@@ -232,7 +232,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables ...@@ -232,7 +232,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
# Avoid indirect branches in kernel to deal with Spectre # Avoid indirect branches in kernel to deal with Spectre
ifdef CONFIG_RETPOLINE ifdef CONFIG_RETPOLINE
RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
RETPOLINE_CFLAGS += $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
ifneq ($(RETPOLINE_CFLAGS),) ifneq ($(RETPOLINE_CFLAGS),)
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
endif endif
......
...@@ -27,3 +27,8 @@ ...@@ -27,3 +27,8 @@
#if __has_feature(address_sanitizer) #if __has_feature(address_sanitizer)
#define __SANITIZE_ADDRESS__ #define __SANITIZE_ADDRESS__
#endif #endif
/* Clang doesn't have a way to turn it off per-function, yet. */
#ifdef __noretpoline
#undef __noretpoline
#endif
...@@ -93,6 +93,10 @@ ...@@ -93,6 +93,10 @@
#define __weak __attribute__((weak)) #define __weak __attribute__((weak))
#define __alias(symbol) __attribute__((alias(#symbol))) #define __alias(symbol) __attribute__((alias(#symbol)))
#ifdef RETPOLINE
#define __noretpoline __attribute__((indirect_branch("keep")))
#endif
/* /*
* it doesn't make sense on ARM (currently the only user of __naked) * it doesn't make sense on ARM (currently the only user of __naked)
* to trace naked functions because then mcount is called without * to trace naked functions because then mcount is called without
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include <linux/types.h> #include <linux/types.h>
/* Built-in __init functions needn't be compiled with retpoline */ /* Built-in __init functions needn't be compiled with retpoline */
#if defined(RETPOLINE) && !defined(MODULE) #if defined(__noretpoline) && !defined(MODULE)
#define __noretpoline __attribute__((indirect_branch("keep"))) #define __noinitretpoline __noretpoline
#else #else
#define __noretpoline #define __noinitretpoline
#endif #endif
/* These macros are used to mark some functions or /* These macros are used to mark some functions or
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
/* These are for everybody (although not all archs will actually /* These are for everybody (although not all archs will actually
discard it in modules) */ discard it in modules) */
#define __init __section(.init.text) __cold __latent_entropy __noretpoline #define __init __section(.init.text) __cold __latent_entropy __noinitretpoline
#define __initdata __section(.init.data) #define __initdata __section(.init.data)
#define __initconst __section(.init.rodata) #define __initconst __section(.init.rodata)
#define __exitdata __section(.exit.data) #define __exitdata __section(.exit.data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment