Hi,
I am facing a very confusing issue with transpiling for aarch64 on x86_64 an .so I am building with Zig:
RUN zig build -Dcpu-arch=arm64 --summary all
Illegal instruction at address 0x1132dbc
/usr/lib/zig/std/zig/system/linux.zig:378:5: 0x1132dbc in detectNativeCpuAndFeatures (build)
return asm ("mrs %[ret], " ++ feat_reg
^
???:?:?: 0x6 in ??? (???)
Unwind information for `???:0x6` was not available, trace may be incomplete
error: the following build command crashed:
/dash0-init-container/.zig-cache/o/9113463d4c682793112c832addf67fad/build /usr/bin/zig /dash0-init-container /dash0-init-container/.zig-cache /root/.cache/zig --seed 0x53e0a585 -Z02f207386de8d26a -Dcpu-arch=arm64 --summary all
(Output cleaned for readability. The link to the failed build and the associated source code is here: feat(injector): zig-based injector · dash0hq/dash0-operator@e7f9199 · GitHub .)
The failure is the same whether I let the build system use for CpuModel .baseline
, .native
or the generic option:
var targetCpuArch = std.Target.Cpu.Arch.aarch64;
var targetCpuModel = std.Target.Cpu.Model.generic(std.Target.Cpu.Arch.aarch64);
if (b.option([]const u8, "cpu-arch", "The system architecture to compile the injector for; valid options are 'amd64' and 'arch64' (default)")) |val| {
if (std.mem.eql(u8, "arm64", val)) {
// Nothing to do
} else if (std.mem.eql(u8, "amd64", val)) {
targetCpuArch = std.Target.Cpu.Arch.x86_64;
targetCpuModel = std.Target.Cpu.Model.generic(std.Target.Cpu.Arch.x86_64);
} else {
return error.UnsupportedArchitecturError;
}
}
const target = b.resolveTargetQuery(.{
.cpu_arch = targetCpuArch,
.cpu_model = .{ .explicit = targetCpuModel },
.os_tag = .linux,
});
The .so is a pretty simple object: it is meant to run in containerized runtimes, and should not make any assumptions on CPU features beyond the minimum baseline found in common container runtimes.