linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kbuild: fix linker feature test macros when cross compiling with Clang
@ 2017-10-26 20:17 Nick Desaulniers
  2017-10-27 11:20 ` Masahiro Yamada
  0 siblings, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2017-10-26 20:17 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: md, ghackmann, pirama, Nick Desaulniers, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Mark Charlebois, Cao jin,
	Marcin Nowakowski, Josh Poimboeuf, linux-kernel

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.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
 scripts/Kbuild.include | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 9ffd3dda3889..23c4df90e8ff 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -160,12 +160,12 @@ 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,\
-	$(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) $(CLANG_TARGET) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
 
 # ld-option
 # Usage: LDFLAGS += $(call ld-option, -X)
 ld-option = $(call try-run,\
-	$(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
+	$(CC) $(CLANG_TARGET) -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

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

* Re: [PATCH] kbuild: fix linker feature test macros when cross compiling with Clang
  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:13   ` [PATCH v2] " Nick Desaulniers
  0 siblings, 2 replies; 15+ messages in thread
From: Masahiro Yamada @ 2017-10-27 11:20 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Michael Davidson, Greg Hackmann, pirama, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Mark Charlebois, Cao jin,
	Marcin Nowakowski, Josh Poimboeuf, Linux Kernel Mailing List

Hi Nick

2017-10-27 5:17 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.
>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  scripts/Kbuild.include | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 9ffd3dda3889..23c4df90e8ff 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -160,12 +160,12 @@ 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,\
> -       $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
> +       $(CC) $(CLANG_TARGET) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
>
>  # ld-option
>  # Usage: LDFLAGS += $(call ld-option, -X)
>  ld-option = $(call try-run,\
> -       $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
> +       $(CC) $(CLANG_TARGET) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
>
>  # ar-option
>  # Usage: KBUILD_ARFLAGS := $(call ar-option,D)
> --

I do not like to add $(CLANG_TARGET) to a place for common helpers.


Instead of $(CLANG_TARGET), please add

$(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS)

to cc-ldoption and ld-option.



I have two requests next time:
  - please include  linux-kbuild@vger.kernel.org in your To list
  - please base your patch on linux-kbuild/kbuild branch


The URL of the tree is described in MAINTAINERS.


Thanks.


-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH] kbuild: fix linker feature test macros when cross compiling with Clang
  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
  1 sibling, 2 replies; 15+ messages in thread
From: Nick Desaulniers @ 2017-10-27 18:28 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild
  Cc: Michael Davidson, Greg Hackmann, Pirama Arumuga Nainar,
	Ingo Molnar, Matthias Kaehlcke, Arnd Bergmann, Mark Charlebois,
	Cao jin, Marcin Nowakowski, Josh Poimboeuf,
	Linux Kernel Mailing List

+ linux-kbuild@vger.kernel.org

On Fri, Oct 27, 2017 at 4:20 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> I do not like to add $(CLANG_TARGET) to a place for common helpers.
> Instead of $(CLANG_TARGET), please add
> $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS)
> to cc-ldoption and ld-option.

Thanks for the review.  I agree that sounds like a better option.

> I have two requests next time:
>   - please include  linux-kbuild@vger.kernel.org in your To list

Sure thing. scripts/get_maintainer.pl does not recommend that list for
this file; is there a way to explicitly add that list to the
recommendation for that source file?

>   - please base your patch on linux-kbuild/kbuild branch

Will do. Do I need to note it's based off that branch? Otherwise wont
0-day bot complain that my patch doesn't apply/build on torvalds/linux
?

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

* Re: [PATCH] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-27 18:28   ` Nick Desaulniers
@ 2017-10-27 20:10     ` Nick Desaulniers
  2017-10-28 14:59     ` Masahiro Yamada
  1 sibling, 0 replies; 15+ messages in thread
From: Nick Desaulniers @ 2017-10-27 20:10 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild
  Cc: Michael Davidson, Greg Hackmann, Pirama Arumuga Nainar,
	Ingo Molnar, Matthias Kaehlcke, Arnd Bergmann, Mark Charlebois,
	Cao jin, Marcin Nowakowski, Josh Poimboeuf,
	Linux Kernel Mailing List, Badhri Jagan Sridharan, Todd Kjos,
	arve

On Fri, Oct 27, 2017 at 11:28 AM, Nick Desaulniers
<ndesaulniers@google.com> wrote:
> On Fri, Oct 27, 2017 at 4:20 AM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>>   - please base your patch on linux-kbuild/kbuild branch
>
> Will do. Do I need to note it's based off that branch? Otherwise wont
> 0-day bot complain that my patch doesn't apply/build on torvalds/linux
> ?

Talked to some teammates about this, sounds like it's not a problem,
so I'll just send v2 with a note to the reviewer.

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

* [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-27 11:20 ` Masahiro Yamada
  2017-10-27 18:28   ` Nick Desaulniers
@ 2017-10-27 20:13   ` Nick Desaulniers
  2017-10-28 15:00     ` Masahiro Yamada
  1 sibling, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2017-10-27 20:13 UTC (permalink / raw)
  To: linux-kbuild, Masahiro Yamada
  Cc: md, ghackmann, pirama, Nick Desaulniers, Douglas Anderson,
	Ingo Molnar, Matthias Kaehlcke, Arnd Bergmann, Marcin Nowakowski,
	Mark Charlebois, Josh Poimboeuf, Cao jin, linux-kernel

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

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

* Re: [PATCH] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-27 18:28   ` Nick Desaulniers
  2017-10-27 20:10     ` Nick Desaulniers
@ 2017-10-28 14:59     ` Masahiro Yamada
  1 sibling, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2017-10-28 14:59 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Ingo Molnar, Matthias Kaehlcke,
	Arnd Bergmann, Mark Charlebois, Cao jin, Marcin Nowakowski,
	Josh Poimboeuf, Linux Kernel Mailing List

2017-10-28 3:28 GMT+09:00 Nick Desaulniers <ndesaulniers@google.com>:
> + linux-kbuild@vger.kernel.org
>
> On Fri, Oct 27, 2017 at 4:20 AM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>> I do not like to add $(CLANG_TARGET) to a place for common helpers.
>> Instead of $(CLANG_TARGET), please add
>> $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS)
>> to cc-ldoption and ld-option.
>
> Thanks for the review.  I agree that sounds like a better option.
>
>> I have two requests next time:
>>   - please include  linux-kbuild@vger.kernel.org in your To list
>
> Sure thing. scripts/get_maintainer.pl does not recommend that list for
> this file; is there a way to explicitly add that list to the
> recommendation for that source file?

Ah, I realized MAINTAINERS does not claim the maintainership
of this file.

There are so many misc scripts
in scripts/, so I hesitate to add
scripts/* pattern to MAINTAINERS.




>>   - please base your patch on linux-kbuild/kbuild branch
>
> Will do. Do I need to note it's based off that branch? Otherwise wont
> 0-day bot complain that my patch doesn't apply/build on torvalds/linux
> ?

I am not sure in which case the 0-day bot complain about it.

Now, I applied v2.
If the bot find a problem, it will send us a report.


-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-27 20:13   ` [PATCH v2] " Nick Desaulniers
@ 2017-10-28 15:00     ` Masahiro Yamada
  2017-10-30  6:50       ` Masahiro Yamada
  0 siblings, 1 reply; 15+ messages in thread
From: Masahiro Yamada @ 2017-10-28 15:00 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Douglas Anderson, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Marcin Nowakowski,
	Mark Charlebois, Josh Poimboeuf, Cao jin,
	Linux Kernel Mailing List

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!


-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-28 15:00     ` Masahiro Yamada
@ 2017-10-30  6:50       ` Masahiro Yamada
  2017-10-30 15:46         ` Masahiro Yamada
  0 siblings, 1 reply; 15+ messages in thread
From: Masahiro Yamada @ 2017-10-30  6:50 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Douglas Anderson, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Marcin Nowakowski,
	Mark Charlebois, Josh Poimboeuf, Cao jin,
	Linux Kernel Mailing List

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

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

* Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-30  6:50       ` Masahiro Yamada
@ 2017-10-30 15:46         ` Masahiro Yamada
  2017-10-30 16:13           ` Nick Desaulniers
  0 siblings, 1 reply; 15+ messages in thread
From: Masahiro Yamada @ 2017-10-30 15:46 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Douglas Anderson, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Marcin Nowakowski,
	Mark Charlebois, Josh Poimboeuf, Cao jin,
	Linux Kernel Mailing List

2017-10-30 15:50 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.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))
>
>


I dropped this patch for now.

-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-30 15:46         ` Masahiro Yamada
@ 2017-10-30 16:13           ` Nick Desaulniers
  2017-11-06 18:47             ` Nick Desaulniers
  0 siblings, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2017-10-30 16:13 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Douglas Anderson, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Marcin Nowakowski,
	Mark Charlebois, Josh Poimboeuf, Cao jin,
	Linux Kernel Mailing List

That's safe to do for now.  Here's the 0-day failure thread:
https://lists.01.org/pipermail/lkp/2017-October/007427.html  If I can
sort out the issue, I'll submit a v3.

On Mon, Oct 30, 2017 at 8:46 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> 2017-10-30 15:50 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.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))
>>
>>
>
>
> I dropped this patch for now.
>
> --
> Best Regards
> Masahiro Yamada



-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-10-30 16:13           ` Nick Desaulniers
@ 2017-11-06 18:47             ` Nick Desaulniers
  2017-11-06 18:47               ` [PATCH v3] " Nick Desaulniers
  0 siblings, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2017-11-06 18:47 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Douglas Anderson, Ingo Molnar,
	Matthias Kaehlcke, Arnd Bergmann, Marcin Nowakowski,
	Mark Charlebois, Josh Poimboeuf, Cao jin,
	Linux Kernel Mailing List

Comparing make V=1 with the suggested config before my patch, after my
patch, and after Masahiro's suggestion to add $(LDFLAGS):

before:
...
ld -m elf_i386  -pie    -T arch/x86/boot/compressed/vmlinux.lds ...
...

after my:
...
ld -m elf_i386     -T arch/x86/boot/compressed/vmlinux.lds ...
...

after my+Masahiro:
...
ld -m elf_i386 -pie    -T arch/x86/boot/compressed/vmlinux.lds ...
...

:)

Just to dig into this a little more (though I suspect we've found the issue):

Next is to debug what we're passing to try-run and see what errors
it's masking.  Adding to arch/x86/boot/compressed/Makefile:
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -44,6 +44,10 @@ LDFLAGS := -m elf_$(UTS_MACHINE)
 # Compressed kernel should be built as PIE since it may be loaded at any
 # address by the bootloader.
 ifeq ($(CONFIG_X86_32),y)
+$(info "XXX")
+$(info "KBUILD_CPPFLAGS: ${KBUILD_CPPFLAGS}")
+$(info "CC_OPTION_CFLAGS: ${CC_OPTION_CFLAGS}")
+$(info "LDFLAGS: ${LDFLAGS}")
 LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
 else
 # To build 64-bit compressed kernel as PIE, we disable relocation

then grepping for XXX in a build output:
"XXX"
"KBUILD_CPPFLAGS: -D__KERNEL__  "
"CC_OPTION_CFLAGS: -m32 -D__KERNEL__ -O2 -fno-strict-aliasing -fPIE
-DDISABLE_BRANCH_PROFILING -march=i386 -mno-mmx -mno-sse
-ffreestanding -fno-stack-protector"
"LD_FLAGS: "

then trying this on the command line:
➜  kernel-all git:(kbuild) ✗ cc -pie -D__KERNEL__ -m32 -D__KERNEL__
-O2 -fno-strict-aliasing -fPIE -DDISABLE_BRANCH_PROFILING -march=i386
-mno-mmx -mno-sse -ffreestanding -fno-stack-protector -x c /dev/null
-c -o temp.o
➜  kernel-all git:(kbuild) ✗ ld -pie temp.o -o temp
ld: i386 architecture of input file `temp.o' is incompatible with
i386:x86-64 output
ld: warning: cannot find entry symbol _start; defaulting to 0000000000000078
➜  kernel-all git:(kbuild) ✗ echo $?
1
➜  kernel-all git:(kbuild) ✗ file temp.o
temp.o: ELF 32-bit LSB  relocatable, Intel 80386, version 1 (SYSV), not stripped

So it looks like without LDFLAGS, we don't tell the linker to link as
32b, causing ld-option to fail to add -pie to LDFLAGS.

➜  kernel-all git:(kbuild) ✗ ld -pie -m elf_i386 temp.o -o temp
ld: warning: cannot find entry symbol _start; defaulting to 0000000000000185
➜  kernel-all git:(kbuild) ✗ echo $?
0

sure enough, just before the call to ld-option from
arch/x86/boot/compressed/Makefile:

 43 LDFLAGS := -m elf_$(UTS_MACHINE)

so looks like Masahiro's suggestion is correct.  Will send a v3.

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

* [PATCH v3] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-11-06 18:47             ` Nick Desaulniers
@ 2017-11-06 18:47               ` Nick Desaulniers
  2017-11-07  3:41                 ` Masahiro Yamada
  2017-12-11 10:17                 ` Arnd Bergmann
  0 siblings, 2 replies; 15+ messages in thread
From: Nick Desaulniers @ 2017-11-06 18:47 UTC (permalink / raw)
  To: linux-kbuild, Masahiro Yamada
  Cc: md, ghackmann, pirama, Nick Desaulniers, Matthias Kaehlcke,
	Arnd Bergmann, Ingo Molnar, Douglas Anderson, Cao jin,
	Josh Poimboeuf, Mark Charlebois, linux-kernel

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 v2:
* Add LDFLAGS to ld-option, as per Masahiro, and spotted by 0-day bot:
  https://lists.01.org/pipermail/lkp/2017-October/007427.html

 scripts/Kbuild.include | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 064f477dfdca..be1c9d65eaf4 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) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
 
 # ar-option
 # Usage: KBUILD_ARFLAGS := $(call ar-option,D)
-- 
2.15.0.403.gc27cc4dac6-goog

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

* Re: [PATCH v3] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-11-06 18:47               ` [PATCH v3] " Nick Desaulniers
@ 2017-11-07  3:41                 ` Masahiro Yamada
  2017-12-11 10:17                 ` Arnd Bergmann
  1 sibling, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2017-11-07  3:41 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Linux Kbuild mailing list, Michael Davidson, Greg Hackmann,
	Pirama Arumuga Nainar, Matthias Kaehlcke, Arnd Bergmann,
	Ingo Molnar, Douglas Anderson, Cao jin, Josh Poimboeuf,
	Mark Charlebois, Linux Kernel Mailing List

2017-11-07 3:47 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 v2:
> * Add LDFLAGS to ld-option, as per Masahiro, and spotted by 0-day bot:
>   https://lists.01.org/pipermail/lkp/2017-October/007427.html
>
>  scripts/Kbuild.include | 5 +++--


Applied to linux-kbuild/kbuild.


-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v3] kbuild: fix linker feature test macros when cross compiling with Clang
  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
  1 sibling, 1 reply; 15+ messages in thread
From: Arnd Bergmann @ 2017-12-11 10:17 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Linux Kbuild mailing list, Masahiro Yamada, Michael Davidson,
	Greg Hackmann, pirama, Matthias Kaehlcke, Ingo Molnar,
	Douglas Anderson, Cao jin, Josh Poimboeuf, Mark Charlebois,
	Linux Kernel Mailing List

On Mon, Nov 6, 2017 at 7:47 PM, Nick Desaulniers
<ndesaulniers@google.com> wrote:
> 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>

After this patch, I get the following warning in arm64 kernel builds
with CONFIG_ARM64_ERRATUM_843419:

arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419;
kernel may be susceptible to erratum

This only happens on the first build though, when the cached variable
is being set. On the second build we get the contents from the cache
and the warning disappears.

I've tried debugging it further but did not get anywhere with that.

        Arnd

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

* Re: [PATCH v3] kbuild: fix linker feature test macros when cross compiling with Clang
  2017-12-11 10:17                 ` Arnd Bergmann
@ 2017-12-11 11:47                   ` Masahiro Yamada
  0 siblings, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2017-12-11 11:47 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nick Desaulniers, Linux Kbuild mailing list, Michael Davidson,
	Greg Hackmann, Pirama Arumuga Nainar, Matthias Kaehlcke,
	Ingo Molnar, Douglas Anderson, Cao jin, Josh Poimboeuf,
	Mark Charlebois, Linux Kernel Mailing List

2017-12-11 19:17 GMT+09:00 Arnd Bergmann <arnd@arndb.de>:
> On Mon, Nov 6, 2017 at 7:47 PM, Nick Desaulniers
> <ndesaulniers@google.com> wrote:
>> 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>
>
> After this patch, I get the following warning in arm64 kernel builds
> with CONFIG_ARM64_ERRATUM_843419:
>
> arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419;
> kernel may be susceptible to erratum
>
> This only happens on the first build though, when the cached variable
> is being set. On the second build we get the contents from the cache
> and the warning disappears.
>
> I've tried debugging it further but did not get anywhere with that.
>
>         Arnd


Hmm.  I cannot reproduce this issue.



With Linaro 4.9 compiler,
I got "Detected assembler with broken .inst",
which is I think expected behavior.


With Linaro 7.2 compiler,
I did not get the warning,
which is also I think expected behavior.



$ make clean
  CLEAN   .
  CLEAN   .tmp_versions
$ make ARCH=arm64
CROSS_COMPILE=~/toolchains/aarch64-linaro-4.9/bin/aarch64-linux-gnu-
arch/arm64/Makefile:48: Detected assembler with broken .inst;
disassembly will be unreliable
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/bin2c
  CC      kernel/bounds.s
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
   ...

$ make ARCH=arm64
CROSS_COMPILE=~/toolchains/aarch64-linaro-7.2/bin/aarch64-linux-gnu-
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CHK     scripts/mod/devicetable-offsets.h
  CHK     include/generated/compile.h
    ...


Can you provide detailed steps to reproduce the problem?



-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2017-12-11 11:48 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).