linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Michael Davidson <md@google.com>,
	Greg Hackmann <ghackmann@google.com>,
	Pirama Arumuga Nainar <pirama@google.com>,
	Douglas Anderson <dianders@chromium.org>,
	Ingo Molnar <mingo@kernel.org>,
	Matthias Kaehlcke <mka@chromium.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Marcin Nowakowski <marcin.nowakowski@imgtec.com>,
	Mark Charlebois <charlebm@gmail.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Cao jin <caoj.fnst@cn.fujitsu.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
Date: Mon, 30 Oct 2017 15:50:44 +0900	[thread overview]
Message-ID: <CAK7LNAQuZ3iWB+_RSh5hCTundm4-rfCP2WzmnkdzLNSQYzaG0w@mail.gmail.com> (raw)
In-Reply-To: <CAK7LNAT56EEHbQguD1pbFiurU9MMa55WAUptX16KWhpOOF_BHg@mail.gmail.com>

2017-10-29 0:00 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> 2017-10-28 5:13 GMT+09:00 Nick Desaulniers <ndesaulniers@google.com>:
>> I was not seeing my linker flags getting added when using ld-option when
>> cross compiling with Clang. Upon investigation, this seems to be due to
>> a difference in how GCC vs Clang handle cross compilation.
>>
>> GCC is configured at build time to support one backend, that is implicit
>> when compiling.  Clang is explicit via the use of `-target <triple>` and
>> ships with all supported backends by default.
>>
>> GNU Make feature test macros that compile then link will always fail
>> when cross compiling with Clang unless Clang's triple is passed along to
>> the compiler. For example:
>>
>> $ clang -x c /dev/null -c -o temp.o
>> $ aarch64-linux-android/bin/ld -E temp.o
>> aarch64-linux-android/bin/ld:
>> unknown architecture of input file `temp.o' is incompatible with
>> aarch64 output
>> aarch64-linux-android/bin/ld:
>> warning: cannot find entry symbol _start; defaulting to
>> 0000000000400078
>> $ echo $?
>> 1
>>
>> $ clang -target aarch64-linux-android- -x c /dev/null -c -o temp.o
>> $ aarch64-linux-android/bin/ld -E temp.o
>> aarch64-linux-android/bin/ld:
>> warning: cannot find entry symbol _start; defaulting to 00000000004002e4
>> $ echo $?
>> 0
>>
>> This causes conditional checks that invoke $(CC) without the target
>> triple, then $(LD) on the result, to always fail.
>>
>> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
>> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
>> ---
>> Changes since v1:
>> * base patch off of
>>   git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git
>>   kbuild branch, per Masahiro.
>> * Use $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) rather than $(CLANG_TRIPLE), per
>>   Masahiro.
>>
>>  scripts/Kbuild.include | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
>> index 064f477dfdca..0f09e4508554 100644
>> --- a/scripts/Kbuild.include
>> +++ b/scripts/Kbuild.include
>> @@ -228,12 +228,13 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo
>>  # cc-ldoption
>>  # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
>>  cc-ldoption = $(call try-run-cached,\
>> -       $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
>> +       $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
>>
>>  # ld-option
>>  # Usage: LDFLAGS += $(call ld-option, -X)
>>  ld-option = $(call try-run-cached,\
>> -       $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
>> +       $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \
>> +       $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
>>
>>  # ar-option
>>  # Usage: KBUILD_ARFLAGS := $(call ar-option,D)
>> --
>> 2.15.0.rc2.357.g7e34df9404-goog
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
> Applied to linux-kbuild/kbuild.  Thanks!



I do not know the cause of the problem reported by the 0-day bot, but
if the problem happens in the following line,

ifeq ($(CONFIG_X86_32),y)
LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
else



Does the following solve the issue?    (adding $(LDFLAGS))

ld-option = $(call try-run,\
        $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c
-o "$$TMPO"; \
        $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))




-- 
Best Regards
Masahiro Yamada

  reply	other threads:[~2017-10-30  6:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-26 20:17 [PATCH] kbuild: fix linker feature test macros when cross compiling with Clang Nick Desaulniers
2017-10-27 11:20 ` Masahiro Yamada
2017-10-27 18:28   ` Nick Desaulniers
2017-10-27 20:10     ` Nick Desaulniers
2017-10-28 14:59     ` Masahiro Yamada
2017-10-27 20:13   ` [PATCH v2] " Nick Desaulniers
2017-10-28 15:00     ` Masahiro Yamada
2017-10-30  6:50       ` Masahiro Yamada [this message]
2017-10-30 15:46         ` Masahiro Yamada
2017-10-30 16:13           ` Nick Desaulniers
2017-11-06 18:47             ` Nick Desaulniers
2017-11-06 18:47               ` [PATCH v3] " Nick Desaulniers
2017-11-07  3:41                 ` Masahiro Yamada
2017-12-11 10:17                 ` Arnd Bergmann
2017-12-11 11:47                   ` Masahiro Yamada

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=CAK7LNAQuZ3iWB+_RSh5hCTundm4-rfCP2WzmnkdzLNSQYzaG0w@mail.gmail.com \
    --to=yamada.masahiro@socionext.com \
    --cc=arnd@arndb.de \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=charlebm@gmail.com \
    --cc=dianders@chromium.org \
    --cc=ghackmann@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcin.nowakowski@imgtec.com \
    --cc=md@google.com \
    --cc=mingo@kernel.org \
    --cc=mka@chromium.org \
    --cc=ndesaulniers@google.com \
    --cc=pirama@google.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).