linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	sam@ravnborg.org, Matthias Kaehlcke <mka@chromium.org>,
	Cao jin <caoj.fnst@cn.fujitsu.com>,
	Mark Charlebois <charlebm@gmail.com>,
	forney@google.com, LKML <linux-kernel@vger.kernel.org>,
	Doug Anderson <dianders@chromium.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 2/2] kbuild: simplify ld-option implementation
Date: Mon, 26 Feb 2018 23:22:58 +0000	[thread overview]
Message-ID: <CAKwvOdmnzvqnt7eBPSvED45QBnU=ivv3VQek1g6QYTyU-+c_RQ@mail.gmail.com> (raw)
In-Reply-To: <1519361813-8553-2-git-send-email-yamada.masahiro@socionext.com>

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

      reply	other threads:[~2018-02-26 23:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKwvOdmnzvqnt7eBPSvED45QBnU=ivv3VQek1g6QYTyU-+c_RQ@mail.gmail.com' \
    --to=ndesaulniers@google.com \
    --cc=arnd@arndb.de \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=charlebm@gmail.com \
    --cc=dianders@chromium.org \
    --cc=forney@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mka@chromium.org \
    --cc=sam@ravnborg.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).