arm64: build with baremetal linker target instead of Linux when available
authorOlof Johansson <olof@lixom.net>
Fri, 13 Jul 2018 15:30:33 +0000 (08:30 -0700)
committerBruno Martins <bgcngm@gmail.com>
Sun, 22 Oct 2023 14:12:33 +0000 (15:12 +0100)
Not all toolchains have the baremetal elf targets, RedHat/Fedora ones
in particular. So, probe for whether it's available and use the previous
(linux) targets if it isn't.

Reported-by: Laura Abbott <labbott@redhat.com>
Tested-by: Laura Abbott <labbott@redhat.com>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Paul Kocialkowski <contact@paulk.fr>
Signed-off-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Change-Id: Icf5462a8318b347cf11559c1654886c48c7a62b5

arch/arm64/Makefile
scripts/Kbuild.include

index a9369fe1688eb12672db1f7e425ad3f16cca28ab..7c153840faf2586e44731775da854362f2e04c48 100644 (file)
@@ -100,12 +100,14 @@ KBUILD_AFLAGS     += $(lseinstr) $(vdso32)
 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
 KBUILD_CPPFLAGS        += -mbig-endian
 AS             += -EB
-LDFLAGS                += -EB -maarch64elfb
+# Prefer the baremetal ELF build target, but not all toolchains include
+LDFLAGS                += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb)
 UTS_MACHINE    := aarch64_be
 else
 KBUILD_CPPFLAGS        += -mlittle-endian
 AS             += -EL
-LDFLAGS                += -EL -maarch64elf
+# Same as above, prefer ELF but fall back to linux target if needed.
+LDFLAGS                += -EL $(call ld-option, -maarch64elf, -maarch64linux)
 UTS_MACHINE    := aarch64
 endif
 
index a45ea93a01a70ef18fcecb76f5a18c5f6a7d505c..c24c2ccfd52c984843b7d3236a5f921c0f404056 100644 (file)
@@ -197,8 +197,8 @@ cc-ldoption = $(call try-run,\
        $(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, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2))
+# Usage: LDFLAGS += $(call ld-option, -X, -Y)
+ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2),$(3))
 
 # ar-option
 # Usage: KBUILD_ARFLAGS := $(call ar-option,D)