]> xenbits.xensource.com Git - xen.git/commitdiff
x86/clang: add retpoline support
authorRoger Pau Monné <roger.pau@citrix.com>
Thu, 31 Mar 2022 08:56:34 +0000 (10:56 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 31 Mar 2022 08:56:34 +0000 (10:56 +0200)
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 in 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>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
master commit: 9412486707f8f1ca2eb31c2ef330c5e39c0a2f30
master date: 2022-02-21 18:17:56 +0000

xen/arch/x86/Kconfig
xen/arch/x86/arch.mk

index e20e53edfc2d10f06120715a3a826d26b2723ca4..34dcb47ecd172ccba238a1c55594e14c666b9f6e 100644 (file)
@@ -33,7 +33,8 @@ config ARCH_DEFCONFIG
        default "arch/x86/configs/x86_64_defconfig"
 
 config CC_HAS_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
index abb55b440838e0e478385a31300e0e09d7179ea1..976ac5aafe1dd2ea9d6bf739cb270310e8aebc52 100644 (file)
@@ -46,6 +46,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
 
 ifdef CONFIG_XEN_IBT