]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.165/kbuild-fix-linker-feature-test-macros-when-cross-compiling-with-clang.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.4.165 / kbuild-fix-linker-feature-test-macros-when-cross-compiling-with-clang.patch
1 From foo@baz Wed Nov 21 18:50:39 CET 2018
2 From: Nick Desaulniers <ndesaulniers@google.com>
3 Date: Mon, 6 Nov 2017 10:47:54 -0800
4 Subject: kbuild: fix linker feature test macros when cross compiling with Clang
5
6 From: Nick Desaulniers <ndesaulniers@google.com>
7
8 commit 86a9df597cdd564d2d29c65897bcad42519e3678 upstream.
9
10 I was not seeing my linker flags getting added when using ld-option when
11 cross compiling with Clang. Upon investigation, this seems to be due to
12 a difference in how GCC vs Clang handle cross compilation.
13
14 GCC is configured at build time to support one backend, that is implicit
15 when compiling. Clang is explicit via the use of `-target <triple>` and
16 ships with all supported backends by default.
17
18 GNU Make feature test macros that compile then link will always fail
19 when cross compiling with Clang unless Clang's triple is passed along to
20 the compiler. For example:
21
22 $ clang -x c /dev/null -c -o temp.o
23 $ aarch64-linux-android/bin/ld -E temp.o
24 aarch64-linux-android/bin/ld:
25 unknown architecture of input file `temp.o' is incompatible with
26 aarch64 output
27 aarch64-linux-android/bin/ld:
28 warning: cannot find entry symbol _start; defaulting to
29 0000000000400078
30 $ echo $?
31 1
32
33 $ clang -target aarch64-linux-android- -x c /dev/null -c -o temp.o
34 $ aarch64-linux-android/bin/ld -E temp.o
35 aarch64-linux-android/bin/ld:
36 warning: cannot find entry symbol _start; defaulting to 00000000004002e4
37 $ echo $?
38 0
39
40 This causes conditional checks that invoke $(CC) without the target
41 triple, then $(LD) on the result, to always fail.
42
43 Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
44 Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
45 Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
46 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
47 [nc: Fix conflicts due to lack of commit 3298b690b21cd in linux-4.4.y
48 Use KBUILD_CFLAGS instead of CC_OPTION_FLAGS because commit
49 d26e94149276f that introduced that variable isn't in 4.4 either]
50 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
51 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
52 ---
53 scripts/Kbuild.include | 5 +++--
54 1 file changed, 3 insertions(+), 2 deletions(-)
55
56 --- a/scripts/Kbuild.include
57 +++ b/scripts/Kbuild.include
58 @@ -147,12 +147,13 @@ cc-ifversion = $(shell [ $(cc-version) $
59 # cc-ldoption
60 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
61 cc-ldoption = $(call try-run,\
62 - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
63 + $(CC) $(1) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
64
65 # ld-option
66 # Usage: LDFLAGS += $(call ld-option, -X)
67 ld-option = $(call try-run,\
68 - $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
69 + $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \
70 + $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
71
72 # ar-option
73 # Usage: KBUILD_ARFLAGS := $(call ar-option,D)