linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] kbuild: test --build-id linker flag by ld-option instead of cc-ldoption
@ 2018-02-23  4:56 Masahiro Yamada
  2018-02-23  4:56 ` [PATCH 2/2] kbuild: simplify ld-option implementation Masahiro Yamada
  0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2018-02-23  4:56 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Arnd Bergmann, Sam Ravnborg, Nick Desaulniers, Matthias Kaehlcke,
	Masahiro Yamada, Michal Marek, linux-kernel

'--build-id' is passed to $(LD), so it should be tested by 'ld-option'.

This seems a kind of misconversion when ld-option was renamed to
cc-ldoption.

Commit f86fd3066052 ("kbuild: rename ld-option to cc-ldoption") renamed
all instances of 'ld-option' to 'cc-ldoption'.

Then, commit 691ef3e7fdc1 ("kbuild: introduce ld-option") re-added
'ld-option' as a new implementation.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 4f295a2..1ed2a15 100644
--- a/Makefile
+++ b/Makefile
@@ -866,8 +866,7 @@ KBUILD_AFLAGS   += $(ARCH_AFLAGS)   $(KAFLAGS)
 KBUILD_CFLAGS   += $(ARCH_CFLAGS)   $(KCFLAGS)
 
 # Use --build-id when available.
-LDFLAGS_BUILD_ID := $(patsubst -Wl$(comma)%,%,\
-			      $(call cc-ldoption, -Wl$(comma)--build-id,))
+LDFLAGS_BUILD_ID := $(call ld-option, --build-id)
 KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
 LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] kbuild: simplify ld-option implementation
  2018-02-23  4:56 [PATCH 1/2] kbuild: test --build-id linker flag by ld-option instead of cc-ldoption Masahiro Yamada
@ 2018-02-23  4:56 ` Masahiro Yamada
  2018-02-26 23:22   ` Nick Desaulniers
  0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2018-02-23  4:56 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Arnd Bergmann, Sam Ravnborg, Nick Desaulniers, Matthias Kaehlcke,
	Masahiro Yamada, Cao jin, Mark Charlebois, Michael Forney,
	linux-kernel, Douglas Anderson, Josh Poimboeuf, Ingo Molnar

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 a way for standalone testing of linker options.
A trick I found is to use '-v'.  This 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>
---

 scripts/Kbuild.include | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 34cbd81..f9c2f07 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -237,9 +237,7 @@ cc-ldoption = $(call try-run-cached,\
 
 # ld-option
 # Usage: LDFLAGS += $(call ld-option, -X)
-ld-option = $(call try-run-cached,\
-	$(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \
-	$(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
+ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2))
 
 # ar-option
 # Usage: KBUILD_ARFLAGS := $(call ar-option,D)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] kbuild: simplify ld-option implementation
  2018-02-23  4:56 ` [PATCH 2/2] kbuild: simplify ld-option implementation Masahiro Yamada
@ 2018-02-26 23:22   ` Nick Desaulniers
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2018-02-26 23:22 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Linux Kbuild mailing list, Arnd Bergmann, sam, Matthias Kaehlcke,
	Cao jin, Mark Charlebois, forney, LKML, Doug Anderson,
	Josh Poimboeuf, Ingo Molnar

Nice! Now we don't need to invoke $CC to find out info about linker support.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>

On Thu, Feb 22, 2018 at 8:57 PM Masahiro Yamada <
yamada.masahiro@socionext.com> wrote:

> 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 a way for standalone testing of linker options.
> A trick I found is to use '-v'.  This 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>
> ---

>   scripts/Kbuild.include | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)

> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 34cbd81..f9c2f07 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -237,9 +237,7 @@ cc-ldoption = $(call try-run-cached,\

>   # ld-option
>   # Usage: LDFLAGS += $(call ld-option, -X)
> -ld-option = $(call try-run-cached,\
> -       $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o
> "$$TMPO"; \
> -       $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
> +ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2))

>   # ar-option
>   # Usage: KBUILD_ARFLAGS := $(call ar-option,D)
> --
> 2.7.4



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-26 23:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-23  4:56 [PATCH 1/2] kbuild: test --build-id linker flag by ld-option instead of cc-ldoption Masahiro Yamada
2018-02-23  4:56 ` [PATCH 2/2] kbuild: simplify ld-option implementation Masahiro Yamada
2018-02-26 23:22   ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).