diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-02-22 23:56:53 -0500 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-25 13:01:20 -0400 |
commit | 0294e6f4a0006856e1f36b8cd8fa088d9e499e98 (patch) | |
tree | 74d65f211a396234f29476b417744f0f1042693c | |
parent | 22340a06534a10296209bc2d02365a2770ded8fc (diff) |
kbuild: simplify ld-option implementation
Currently, linker options are tested by the coordination of $(CC) and
$(LD) because $(LD) needs some object to link.
As commit 86a9df597cdd ("kbuild: fix linker feature test macros when
cross compiling with Clang") addressed, we need to make sure $(CC)
and $(LD) agree the underlying architecture of the passed object.
This could be a bit complex when we combine tools from different groups.
For example, we can use clang for $(CC), but we still need to rely on
GCC toolchain for $(LD).
So, I was searching for a way of standalone testing of linker options.
A trick I found is to use '-v'; this not only prints the version string,
but also tests if the given option is recognized.
If a given option is supported,
$ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419
GNU ld (Linaro_Binutils-2017.11) 2.28.2.20170706
$ echo $?
0
If unsupported,
$ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419
GNU ld (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 - Linaro GCC 2013.04) 2.23.1
aarch64-linux-gnu-ld: unrecognized option '--fix-cortex-a53-843419'
aarch64-linux-gnu-ld: use the --help option for usage information
$ echo $?
1
Gold works likewise.
$ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-843419
GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14
masahiro@pug:~/ref/linux$ echo $?
0
$ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-999999
GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14
aarch64-linux-gnu-ld.gold: --fix-cortex-a53-999999: unknown option
aarch64-linux-gnu-ld.gold: use the --help option for usage information
$ echo $?
1
LLD too.
$ ld.lld -v --gc-sections
LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
$ echo $?
0
$ ld.lld -v --fix-cortex-a53-843419
LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
$ echo $?
0
$ ld.lld -v --fix-cortex-a53-999999
ld.lld: error: unknown argument: --fix-cortex-a53-999999
LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers)
$ echo $?
1
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
-rw-r--r-- | scripts/Kbuild.include | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 34cbd81024b0..f9c2f07442c5 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include | |||
@@ -237,9 +237,7 @@ cc-ldoption = $(call try-run-cached,\ | |||
237 | 237 | ||
238 | # ld-option | 238 | # ld-option |
239 | # Usage: LDFLAGS += $(call ld-option, -X) | 239 | # Usage: LDFLAGS += $(call ld-option, -X) |
240 | ld-option = $(call try-run-cached,\ | 240 | ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) |
241 | $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \ | ||
242 | $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) | ||
243 | 241 | ||
244 | # ar-option | 242 | # ar-option |
245 | # Usage: KBUILD_ARFLAGS := $(call ar-option,D) | 243 | # Usage: KBUILD_ARFLAGS := $(call ar-option,D) |