| // TODO: Add the rest of the AUDIT defines? |
| pubconstAUDIT=struct { |
| pubconstARCH=enum(u32) { |
| const @"64BIT"=0x80000000; |
| constLE=0x40000000; |
| |
| pubconstcurrent: AUDIT.ARCH=switch (native_arch) { |
| .x86=>.X86, |
| .x86_64=>.X86_64, |
| .aarch64=>.AARCH64, |
| .arm, .thumb=>.ARM, |
| .riscv64=>.RISCV64, |
| .sparc64=>.SPARC64, |
| .mips=>.MIPS, |
| .mipsel=>.MIPSEL, |
| .powerpc=>.PPC, |
| .powerpc64=>.PPC64, |
| .powerpc64le=>.PPC64LE, |
| else=>@compileError("unsupported architecture"), |
| }; |
| |
| AARCH64=toAudit(.aarch64), |
| ARM=toAudit(.arm), |
| ARMEB=toAudit(.armeb), |
| CSKY=toAudit(.csky), |
| HEXAGON=@intFromEnum(std.elf.EM.HEXAGON), |
| X86=toAudit(.x86), |
| M68K=toAudit(.m68k), |
| MIPS=toAudit(.mips), |
| MIPSEL=toAudit(.mips) |LE, |
| MIPS64=toAudit(.mips64), |
| MIPSEL64=toAudit(.mips64) |LE, |
| PPC=toAudit(.powerpc), |
| PPC64=toAudit(.powerpc64), |
| PPC64LE=toAudit(.powerpc64le), |
| RISCV32=toAudit(.riscv32), |
| RISCV64=toAudit(.riscv64), |
| S390X=toAudit(.s390x), |
| SPARC=toAudit(.sparc), |
| SPARC64=toAudit(.sparc64), |
| X86_64=toAudit(.x86_64), |
| |
| fntoAudit(arch: std.Target.Cpu.Arch) u32 { |
| varres: u32=@intFromEnum(arch.toElfMachine()); |
| if (arch.endian() ==.little) res|=LE; |
| switch (arch) { |
| .aarch64, |
| .mips64, |
| .mips64el, |
| .powerpc64, |
| .powerpc64le, |
| .riscv64, |
| .sparc64, |
| .x86_64, |
| =>res|= @"64BIT", |
| else=> {}, |
| } |
| returnres; |
| } |
| }; |
| }; |
There are two problems with this code:
- Implementing the bindings in terms of
std.Target.Cpu.Arch mapped to std.elf.EM is too clever. There is not a 1:1 mapping here; it would at least need to take an std.Target.Abi too. But really, just use std.elf.EM. - Detection for
current is broken for cases where the ABI affects the decision. It's also missing some architectures.
zig/lib/std/os/linux.zig
Lines 7271 to 7331 in eac7fd4
There are two problems with this code:
std.Target.Cpu.Archmapped tostd.elf.EMis too clever. There is not a 1:1 mapping here; it would at least need to take anstd.Target.Abitoo. But really, just usestd.elf.EM.currentis broken for cases where the ABI affects the decision. It's also missing some architectures.