]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/clang: add retpoline support
authorRoger Pau Monne <roger.pau@citrix.com>
Fri, 18 Feb 2022 14:34:15 +0000 (15:34 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 21 Feb 2022 18:17:56 +0000 (18:17 +0000)
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>
xen/arch/x86/Kconfig
xen/arch/x86/arch.mk

index fe89fa72749eef188c17f1e9cdd1a35adfd9caf8..14658740972337ec482ce2574677015d68643089 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 15d0cbe4874a4b036094fa622a0581d9db444676..edfc043dbbaf5a98bfb97d0862da5a456da3dbc0 100644 (file)
@@ -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