diff mbox series

[v3,2/3] x86/clang: add retpoline support

Message ID 20220218143416.34475-3-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show
Series retpoline: add clang support + Kconfig selectable | expand

Commit Message

Roger Pau Monné Feb. 18, 2022, 2:34 p.m. UTC
Detect whether the compiler supports clang retpoline option and enable
by default if available, just like it's done for gcc.

Note clang already disables jump tables when retpoline is enabled, so
there's no need to also pass the fno-jump-tables parameter. Also clang
already passes the return address on a register always on amd64, so
there's no need for any equivalent mindirect-branch-register
parameter.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/Kconfig | 4 +++-
 xen/arch/x86/arch.mk | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index a1a90da4fc..f8dca4dc85 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -33,7 +33,9 @@  config ARCH_DEFCONFIG
 	default "arch/x86/configs/x86_64_defconfig"
 
 config CC_INDIRECT_THUNK
-	def_bool $(cc-option,-mindirect-branch-register)
+	def_bool $(cc-option,-mindirect-branch-register) || \
+	         $(cc-option,-mretpoline-external-thunk)
+
 
 config INDIRECT_THUNK
 	def_bool y
diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk
index 6388b1d93f..066d749ba0 100644
--- a/xen/arch/x86/arch.mk
+++ b/xen/arch/x86/arch.mk
@@ -47,6 +47,9 @@  ifeq ($(CONFIG_INDIRECT_THUNK),y)
 CFLAGS-$(CONFIG_CC_IS_GCC) += -mindirect-branch=thunk-extern
 CFLAGS-$(CONFIG_CC_IS_GCC) += -mindirect-branch-register
 CFLAGS-$(CONFIG_CC_IS_GCC) += -fno-jump-tables
+
+# Enable clang retpoline support if available.
+CFLAGS-$(CONFIG_CC_IS_CLANG) += -mretpoline-external-thunk
 endif
 
 # If supported by the compiler, reduce stack alignment to 8 bytes. But allow