From f1e3b67b1fae868fed3f13a18642607c777fc087 Mon Sep 17 00:00:00 2001 From: xtex Date: Sun, 21 Jun 2026 21:56:00 +0800 Subject: [PATCH] link.Elf2: write LoongArch e_flags The base ABI modifier is determined by the target features of the root module. However, ideally, it should be determined by the superset of the feature sets of all linked modules. Setting ABI version to v1. Both the LLVM backend and the self-hosted backend in my branch supports only ABI v1 ("new world"). --- src/link/Elf2.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/link/Elf2.zig b/src/link/Elf2.zig index 91aefff2092172b4a320a1f24c052d68a1cb3844..a2f13bd06742315e192fe96da21974561d75eb04 100644 --- a/src/link/Elf2.zig +++ b/src/link/Elf2.zig @@ -2958,7 +2958,24 @@ fn initHeaders( ehdr.entry = 0; ehdr.phoff = 0; ehdr.shoff = 0; - ehdr.flags = 0; + ehdr.flags = switch (machine) { + .X86_64 => 0, + .LOONGARCH => e_flags: { + const target_cpu = &elf.base.comp.getTarget().cpu; + const e_flags: std.elf.loongarch.EFlags = .{ + .base_abi_modifier = if (target_cpu.has(.loongarch, .d)) + .d + else if (target_cpu.has(.loongarch, .f)) + .f + else + .s, + .abi_extension = .base, + .abi_version = 1, + }; + break :e_flags @bitCast(e_flags); + }, + else => @panic(@tagName(machine)), + }; ehdr.ehsize = @sizeOf(ElfN.Ehdr); ehdr.phentsize = @sizeOf(ElfN.Phdr); ehdr.phnum = @min(phnum, std.elf.PN_XNUM); -- 2.54.0