diff options
| author | Tom Maenan Read Cutting <readcuttingt@gmail.com> | 2022-03-10 22:17:07 +0000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-15 13:48:42 -0400 |
| commit | 9bb19a090ea1d1d47b214974d5e18e11ef4adb85 (patch) | |
| tree | bc1d9837eeb21afdb0a80ae355e671ad54b8151a /lib/std/elf.zig | |
| parent | c64279b15b527749420e0e79fcc6dbfbfeb02812 (diff) | |
| download | zig-9bb19a090ea1d1d47b214974d5e18e11ef4adb85.tar.gz zig-9bb19a090ea1d1d47b214974d5e18e11ef4adb85.zip | |
std: Add elf.EM, coff.MachineType to Target.CPU.Arch conversions
target.Arch already supports finding the correct encoding for either
target, so being able to do the inverse has use cases for when parsing
files of an unknown target (i.e. for zar).
Diffstat (limited to 'lib/std/elf.zig')
| -rw-r--r-- | lib/std/elf.zig | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 6c3b748c58..84001ec1c9 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -1481,6 +1481,36 @@ pub const EM = enum(u16) { _BPF = 247, _, + + pub fn toTargetCpuArch(em: EM) ?std.Target.Cpu.Arch { + return switch (em) { + ._AVR => .avr, + ._MSP430 => .msp430, + ._ARC => .arc, + ._ARM => .arm, + ._HEXAGON => .hexagon, + ._68K => .m68k, + ._MIPS => .mips, + ._MIPS_RS3_LE => .mipsel, + ._PPC => .powerpc, + ._SPARC => .sparc, + ._386 => .i386, + ._XCORE => .xcore, + ._CSR_KALIMBA => .kalimba, + ._LANAI => .lanai, + ._AARCH64 => .aarch64, + ._PPC64 => .powerpc64, + ._RISCV => .riscv64, + ._X86_64 => .x86_64, + ._BPF => .bpfel, + ._SPARCV9 => .sparcv9, + ._S390 => .s390x, + ._SPU_2 => .spu_2, + // there's many cases we don't (yet) handle, or will never have a + // zig target cpu arch equivalent (such as null). + else => null, + }; + } }; /// Section data should be writable during execution. @@ -1681,7 +1711,7 @@ pub const R_X86_64_TLSDESC = 36; pub const R_X86_64_IRELATIVE = 37; /// 64-bit adjust by program base pub const R_X86_64_RELATIVE64 = 38; -/// 39 Reserved was R_X86_64_PC32_BND +/// 39 Reserved was R_X86_64_PC32_BND /// 40 Reserved was R_X86_64_PLT32_BND /// Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable pub const R_X86_64_GOTPCRELX = 41; |
