diff mbox series

[v2] Makefile: Add -fuse-ld for merge_objs

Message ID 20251202070724.1229991-1-wxjstz@126.com
State New
Headers show
Series [v2] Makefile: Add -fuse-ld for merge_objs | expand

Commit Message

Xiang W Dec. 2, 2025, 7:05 a.m. UTC
On some platforms, the default linker is `mold`, which can cause the
following error. Adding the `--fuse-ld` option can prevent this problem.

    MERGE     platform/generic/firmware/payloads/test.o
    mold: fatal: unknown command line option: -b elf64-littleriscv

Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
v2 changes:
- s/-no-pie -Wl,-r/-r/
 Makefile | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index eb95164c..794f6f38 100644
--- a/Makefile
+++ b/Makefile
@@ -433,13 +433,15 @@  ELFFLAGS	+=	-Wl,--no-dynamic-linker -Wl,-pie
 ELFFLAGS	+=	$(platform-ldflags-y)
 ELFFLAGS	+=	$(firmware-ldflags-y)
 
+MERGEFLAGS	+=	$(USE_LD_FLAG)
+MERGEFLAGS	+=	-nostdlib
 MERGEFLAGS	+=	-r
 ifeq ($(LD_IS_LLD),y)
-MERGEFLAGS	+=	-b elf
+MERGEFLAGS	+=	-Wl,-b,elf
 else
-MERGEFLAGS	+=	-b elf$(PLATFORM_RISCV_XLEN)-littleriscv
+MERGEFLAGS	+=	-Wl,-b,elf$(PLATFORM_RISCV_XLEN)-littleriscv
 endif
-MERGEFLAGS	+=	-m elf$(PLATFORM_RISCV_XLEN)lriscv
+MERGEFLAGS	+=	-Wl,-m,elf$(PLATFORM_RISCV_XLEN)lriscv
 
 DTSCPPFLAGS	=	$(CPPFLAGS) -nostdinc -nostdlib -fno-builtin -D__DTS__ -x assembler-with-cpp
 
@@ -459,7 +461,7 @@  define dynamic_flags
 endef
 merge_objs = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
 	     echo " MERGE     $(subst $(build_dir)/,,$(1))"; \
-	     $(LD) $(MERGEFLAGS) $(2) -o $(1)
+	     $(CC) $(MERGEFLAGS) $(2) -o $(1)
 merge_deps = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
 	     echo " MERGE-DEP $(subst $(build_dir)/,,$(1))"; \
 	     cat $(2) > $(1)