Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alexrp opened this issue Jul 24, 2024 · 0 comments · Fixed by #21177
Closed

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

alexrp opened this issue Jul 24, 2024 · 0 comments · Fixed by #21177
Labels
standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@alexrp
Copy link
Contributor

alexrp commented Jul 24, 2024

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.

@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Jul 26, 2024
@andrewrk andrewrk added this to the unplanned milestone Jul 26, 2024
alexrp added a commit to alexrp/zig that referenced this issue Aug 10, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 12, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 12, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 12, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 13, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 13, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 15, 2024
This enables them to give more correct results.

Contributes to ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 19, 2024
These are fundamentally incapable of producing accurate information for reasons
I've laid out in ziglang#20771. Since our only use of these functions is to check that
object files have the correct machine type, and since ziglang#21020 made
`std.Target.to{Coff,Elf}Machine()` more accurate, just switch these checks over
to that and compare the machine type tags instead.

Closes ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 23, 2024
These are fundamentally incapable of producing accurate information for reasons
I've laid out in ziglang#20771. Since our only use of these functions is to check that
object files have the correct machine type, and since ziglang#21020 made
`std.Target.to{Coff,Elf}Machine()` more accurate, just switch these checks over
to that and compare the machine type tags instead.

Closes ziglang#20771.
alexrp added a commit to alexrp/zig that referenced this issue Aug 23, 2024
These are fundamentally incapable of producing accurate information for reasons
I've laid out in ziglang#20771. Since our only use of these functions is to check that
object files have the correct machine type, and since ziglang#21020 made
`std.Target.to{Coff,Elf}Machine()` more accurate, just switch these checks over
to that and compare the machine type tags instead.

Closes ziglang#20771.
@andrewrk andrewrk modified the milestones: unplanned, 0.14.0 Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants