• Nick Desaulniers's avatar
    kbuild: fix linker feature test macros when cross compiling with Clang · 86a9df59
    Nick Desaulniers authored
    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's avatarMasahiro Yamada <yamada.masahiro@socionext.com>
    Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
    Reviewed-by: default avatarMatthias Kaehlcke <mka@chromium.org>
    Signed-off-by: Masahiro Yamada's avatarMasahiro Yamada <yamada.masahiro@socionext.com>
    86a9df59
Name
Last commit
Last update
Documentation Loading commit data...
arch Loading commit data...
block Loading commit data...
certs Loading commit data...
crypto Loading commit data...
drivers Loading commit data...
firmware Loading commit data...
fs Loading commit data...
include Loading commit data...
init Loading commit data...
ipc Loading commit data...
kernel Loading commit data...
lib Loading commit data...
mm Loading commit data...
net Loading commit data...
samples Loading commit data...
scripts Loading commit data...
security Loading commit data...
sound Loading commit data...
tools Loading commit data...
usr Loading commit data...
virt Loading commit data...
.cocciconfig Loading commit data...
.get_maintainer.ignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
COPYING Loading commit data...
CREDITS Loading commit data...
Kbuild Loading commit data...
Kconfig Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README Loading commit data...