kbuild: add -fcf-protection=none when using retpoline flags
authorSeth Forshee <seth.forshee@canonical.com>
Wed, 17 Jul 2019 16:06:26 +0000 (11:06 -0500)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 20 Jul 2019 02:20:24 +0000 (11:20 +0900)
The gcc -fcf-protection=branch option is not compatible with
-mindirect-branch=thunk-extern. The latter is used when
CONFIG_RETPOLINE is selected, and this will fail to build with
a gcc which has -fcf-protection=branch enabled by default. Adding
-fcf-protection=none when building with retpoline enabled
prevents such build failures.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Makefile

index 86d26c0ad9a9d6319cdbdca7e3e3206e702fc79e..fd6f7949bc1a3e1c805b2865675a4dedd1db8ce7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -882,6 +882,12 @@ KBUILD_CFLAGS   += $(call cc-option,-Werror=designated-init)
 # change __FILE__ to the relative path from the srctree
 KBUILD_CFLAGS  += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 
+# ensure -fcf-protection is disabled when using retpoline as it is
+# incompatible with -mindirect-branch=thunk-extern
+ifdef CONFIG_RETPOLINE
+KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
+endif
+
 # use the deterministic mode of AR if available
 KBUILD_ARFLAGS := $(call ar-option,D)