--- /dev/null
+From 7269e59e48cf66de9a974a5cd0d3cc2eeb86e2ca Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 17 Jul 2019 11:06:26 -0500
+Subject: kbuild: add -fcf-protection=none when using retpoline flags
+
+From: Seth Forshee <seth.forshee@canonical.com>
+
+[ Upstream commit 29be86d7f9cb18df4123f309ac7857570513e8bc ]
+
+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>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ Makefile | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/Makefile b/Makefile
+index 61660387eb34b..52aaa6150099e 100644
+--- a/Makefile
++++ b/Makefile
+@@ -843,6 +843,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)
+
+--
+2.20.1
+
--- /dev/null
+From c827c9b8535db3267f9c92da5cc69389345e2074 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 30 Mar 2018 13:15:26 +0900
+Subject: kbuild: use -fmacro-prefix-map to make __FILE__ a relative path
+
+From: Masahiro Yamada <yamada.masahiro@socionext.com>
+
+[ Upstream commit a73619a845d5625079cc1b3b820f44c899618388 ]
+
+The __FILE__ macro is used everywhere in the kernel to locate the file
+printing the log message, such as WARN_ON(), etc. If the kernel is
+built out of tree, this can be a long absolute path, like this:
+
+ WARNING: CPU: 1 PID: 1 at /path/to/build/directory/arch/arm64/kernel/foo.c:...
+
+This is because Kbuild runs in the objtree instead of the srctree,
+then __FILE__ is expanded to a file path prefixed with $(srctree)/.
+
+Commit 9da0763bdd82 ("kbuild: Use relative path when building in a
+subdir of the source tree") improved this to some extent; $(srctree)
+becomes ".." if the objtree is a child of the srctree.
+
+For other cases of out-of-tree build, __FILE__ is still the absolute
+path. It also means the kernel image depends on where it was built.
+
+A brand-new option from GCC, -fmacro-prefix-map, solves this problem.
+If your compiler supports it, __FILE__ is the relative path from the
+srctree regardless of O= option. This provides more readable log and
+more reproducible builds.
+
+Please note __FILE__ is always an absolute path for external modules.
+
+Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ Makefile | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/Makefile b/Makefile
+index 1d7f47334ca2b..61660387eb34b 100644
+--- a/Makefile
++++ b/Makefile
+@@ -840,6 +840,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
+ # Require designated initializers for all marked structures
+ 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)/=)
++
+ # use the deterministic mode of AR if available
+ KBUILD_ARFLAGS := $(call ar-option,D)
+
+--
+2.20.1
+