Skip to content

Conversion functions to/from ELF/COFF machine types need rethinking #20771

@alexrp

Description

@alexrp

pub fn toElfMachine(arch: Arch) std.elf.EM {

pub fn toCoffMachine(arch: Arch) std.coff.MachineType {

pub fn fromTargetCpuArch(arch: std.Target.Cpu.Arch) MachineType {

These 3 functions are all problematic for the simple reason that an std.Target.Cpu.Arch value is not enough information to do the correct mapping. At the very least, an std.Target.Abi value is also needed. All current call sites in the repo have a full std.Target available, so this should be relatively easy to fix.


pub fn toTargetCpuArch(machine_type: MachineType) ?std.Target.Cpu.Arch {

pub fn toTargetCpuArch(em: EM) ?std.Target.Cpu.Arch {

These suffer from a similar problem: To do a sensible mapping, they also need to return an ABI value. However, while it's possible to go from an Arch + Abi to an ELF or COFF machine type, the reverse is not true; these functions can't possibly decide between glibc and musl Abi values, for example. This is another good argument in favor of #20690 (splitting libc and ABI), but we should probably come up with some sort of interim solution - perhaps an ArchAbi enum that identifies the ABI divorced from libc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions