In Zig 0.15.1, I am trying to build my toy OS using the x86-64 native backend.
It builds and runs without issues using the LLVM backend, but when using the native backend, the generated image cannot be loaded by UEFI.
I am not very familiar with PE, but for example, the subsystem field in the PE header is set to WINDOWS_CUI instead of EFI_APPLICATION, which causes UEFI (OVMF) to treat it as unsupported. Looking at the relevant code in Zig, it seems that the subsystem is always fixed to .WINDOWS_CUI:
const subsystem: coff_util.Subsystem = .WINDOWS_CUI;
Does the native backend not support building UEFI applications? Has anyone been able to build and run a UEFI application using the native backend?
FYI, here’s my build.zig:
const surtr = b.addExecutable(.{
.name = "BOOTX64.EFI",
.root_module = b.createModule(.{
.root_source_file = b.path("surtr/main.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .x86_64,
.os_tag = .uefi,
}),
.optimize = optimize,
}),
.linkage = .static,
.use_llvm = false,
});
surtr.entry = .{ .symbol_name = "main" };
surtr.subsystem = .EfiApplication;
b.installArtifact(surtr);