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
6 From: Masahiro Yamada <yamada.masahiro@socionext.com>
8 commit 0294e6f4a0006856e1f36b8cd8fa088d9e499e98 upstream.
10 Currently, linker options are tested by the coordination of $(CC) and
11 $(LD) because $(LD) needs some object to link.
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.
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).
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.
25 If a given option is supported,
27 $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419
28 GNU ld (Linaro_Binutils-2017.11) 2.28.2.20170706
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
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 $?
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
56 $ ld.lld -v --gc-sections
57 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
60 $ ld.lld -v --fix-cortex-a53-843419
61 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
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)
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>
77 scripts/Kbuild.include | 4 +---
78 1 file changed, 1 insertion(+), 3 deletions(-)
80 --- a/scripts/Kbuild.include
81 +++ b/scripts/Kbuild.include
82 @@ -166,9 +166,7 @@ cc-ldoption = $(call try-run,\
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))
92 # Usage: KBUILD_ARFLAGS := $(call ar-option,D)