From 522ae4cb3f9032e7a2f092932a2c49277ddc2bec Mon Sep 17 00:00:00 2001 From: Ansh Rai Date: Sun, 19 Jul 2026 06:58:36 +0000 Subject: [PATCH] tools/Zig.defs: Fix Zig builds on sim:x86_64 Building Zig applications on sim:x86_64 with Zig 0.13.0 fails because the generated target "x86_64-freestanding-sysv" is not recognized by Zig. Introduce a Zig-specific ABI mapping that translates "sysv" to "gnu" without affecting other toolchains. After correcting the target ABI, linking still fails due to unresolved references to __zig_probe_stack. Add -fcompiler-rt so Zig includes the required compiler runtime during linking. Verified on sim:nsh with CONFIG_EXAMPLES_HELLO_ZIG=y: nsh> hello_zig [sim]: Hello, Zig! Fixes #19475 Signed-off-by: Ansh Rai --- tools/Zig.defs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/Zig.defs b/tools/Zig.defs index 6feabe72e22..18f7424c995 100644 --- a/tools/Zig.defs +++ b/tools/Zig.defs @@ -36,7 +36,13 @@ else ifeq ($(CONFIG_ARCH_RISCV),y) ZIGFLAGS += -mcmodel=medium else - ZIGFLAGS := -target $(LLVM_ARCHTYPE)-freestanding-$(LLVM_ABITYPE) + ifeq ($(LLVM_ABITYPE),sysv) + ZIG_ABITYPE := gnu + else + ZIG_ABITYPE := $(LLVM_ABITYPE) + endif + + ZIGFLAGS := -target $(LLVM_ARCHTYPE)-freestanding-$(ZIG_ABITYPE) endif # Convert cortex-xxx/sifive-exx to cortex_xxx/sifive_exx @@ -44,3 +50,5 @@ endif ifneq ($(LLVM_CPUTYPE),) ZIGFLAGS += -mcpu $(subst -,_,$(LLVM_CPUTYPE)) endif + +ZIGFLAGS += -fcompiler-rt