foss-for-synopsys-dwc-arc-processors/linux

ARCv3 loader for 32-bit ARC HS58 won't link if arc64-elf toolchain is used

Closed this issue · 1 comments

If pre-built arc64-elf toolchain is used (for example the one from arc-2022.09 release, see https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2022.09-release/arc_gnu_2022.09_prebuilt_arc64_elf_linux_install.tar.gz) to build so-called loader binary for 32-bit ARCv3 processor (ARC HS58) the following error appears:

make loader
CALL    scripts/checksyscalls.sh
CALL    scripts/atomic/check-atomics.sh
CHK     include/generated/compile.h
AS      arch/arc/boot/loader.o
LDS     arch/arc/boot/loader.lds
arc64-elf-ld: arch/arc/boot/loader.o: ABI is incompatible with the selected emulation:
target emulation 'elf32-littlearc64' does not match 'elf64-littlearc64'
arc64-elf-ld: failed to merge target specific data of file arch/arc/boot/loader.o
make[1]: *** [arch/arc/boot/Makefile:50: arch/arc/boot/loader] Error 1
make: *** [arch/arc/Makefile:147: loader] Error 2

That happens because LD flags are not being passed to the loader link command.
The following change fixes that:

diff --git a/arch/arc/boot/Makefile b/arch/arc/boot/Makefile
index 48633d8b182b..c7b77bf4712c 100644
--- a/arch/arc/boot/Makefile
+++ b/arch/arc/boot/Makefile
@@ -46,5 +46,11 @@ $(obj)/uImage.lzma: $(obj)/vmlinux.bin.lzma FORCE

 $(obj)/loader.o: $(src)/loader.S $(obj)/vmlinux.bin

+ifdef CONFIG_64BIT
+ld_emulation   := -marc64elf64
+else
+ld_emulation   := -marc64elf32
+endif
+
 $(obj)/loader: $(obj)/loader.o $(obj)/vmlinux.bin $(obj)/loader.lds FORCE
-       $(Q)$(LD)  --defsym=_entry_point_virt=$(LINUX_ENTRY_VIRT) -T $(obj)/loader.lds -o $@ $(obj)/loader.o
+       $(Q)$(LD)  --defsym=_entry_point_virt=$(LINUX_ENTRY_VIRT) -T $(obj)/loader.lds -o $@ $(obj)/loader.o $(ld_emulation)

But it's just a fast fix, while I may guess there might be a more elegant solution to that problem like proper passing LDFLAGS to the LD invocation etc.

xxkent commented

Was fixed here:
#126