]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.9/kbuild-simplify-ld-option-implementation.patch
fb890d552368257beeec5c1d419063d87b2ed9e7
[thirdparty/kernel/stable-queue.git] / queue-4.9 / kbuild-simplify-ld-option-implementation.patch
1 From e9376686d5827beee5a36c47753bf438952a6621 Mon Sep 17 00:00:00 2001
2 From: Masahiro Yamada <yamada.masahiro@socionext.com>
3 Date: Fri, 23 Feb 2018 13:56:53 +0900
4 Subject: kbuild: simplify ld-option implementation
5
6 From: Masahiro Yamada <yamada.masahiro@socionext.com>
7
8 commit 0294e6f4a0006856e1f36b8cd8fa088d9e499e98 upstream.
9
10 Currently, linker options are tested by the coordination of $(CC) and
11 $(LD) because $(LD) needs some object to link.
12
13 As commit 86a9df597cdd ("kbuild: fix linker feature test macros when
14 cross compiling with Clang") addressed, we need to make sure $(CC)
15 and $(LD) agree the underlying architecture of the passed object.
16
17 This could be a bit complex when we combine tools from different groups.
18 For example, we can use clang for $(CC), but we still need to rely on
19 GCC toolchain for $(LD).
20
21 So, I was searching for a way of standalone testing of linker options.
22 A trick I found is to use '-v'; this not only prints the version string,
23 but also tests if the given option is recognized.
24
25 If a given option is supported,
26
27 $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419
28 GNU ld (Linaro_Binutils-2017.11) 2.28.2.20170706
29 $ echo $?
30 0
31
32 If unsupported,
33
34 $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419
35 GNU ld (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 - Linaro GCC 2013.04) 2.23.1
36 aarch64-linux-gnu-ld: unrecognized option '--fix-cortex-a53-843419'
37 aarch64-linux-gnu-ld: use the --help option for usage information
38 $ echo $?
39 1
40
41 Gold works likewise.
42
43 $ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-843419
44 GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14
45 masahiro@pug:~/ref/linux$ echo $?
46 0
47 $ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-999999
48 GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14
49 aarch64-linux-gnu-ld.gold: --fix-cortex-a53-999999: unknown option
50 aarch64-linux-gnu-ld.gold: use the --help option for usage information
51 $ echo $?
52 1
53
54 LLD too.
55
56 $ ld.lld -v --gc-sections
57 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
58 $ echo $?
59 0
60 $ ld.lld -v --fix-cortex-a53-843419
61 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
62 $ echo $?
63 0
64 $ ld.lld -v --fix-cortex-a53-999999
65 ld.lld: error: unknown argument: --fix-cortex-a53-999999
66 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
67 $ echo $?
68 1
69
70 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
71 Tested-by: Nick Desaulniers <ndesaulniers@google.com>
72 [nc: try-run-cached was added later, just use try-run, which is the
73 current mainline state]
74 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
75 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
76 ---
77 scripts/Kbuild.include | 4 +---
78 1 file changed, 1 insertion(+), 3 deletions(-)
79
80 --- a/scripts/Kbuild.include
81 +++ b/scripts/Kbuild.include
82 @@ -166,9 +166,7 @@ cc-ldoption = $(call try-run,\
83
84 # ld-option
85 # Usage: LDFLAGS += $(call ld-option, -X)
86 -ld-option = $(call try-run,\
87 - $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \
88 - $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
89 +ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2))
90
91 # ar-option
92 # Usage: KBUILD_ARFLAGS := $(call ar-option,D)