zig icon indicating copy to clipboard operation
zig copied to clipboard

COFF and ELF: move to-and-from CPU arch logic

Open wooster0 opened this issue 1 year ago • 4 comments

  • Before, std.Target.Cpu.Arch.toCoffMachine was not used anywhere. Instead, std.coff.fromTargetCpuArch was used. After this commit this is still the case but toCoffMachine is removed and merged into std.coff.fromTargetCpuArch, making it more complete, too.
  • After this commit std.elf.toTargetCpuArch and std.coff.toTargetCpuArch are still not used anywhere and weren't before this commit either. Can we remove them? @kubkon
  • toCoffMachine and toElfMachine are removed and their logic is moved to std.coff and std.elf, respectively. I thought they belong there more than in std.Target.

wooster0 avatar May 28 '23 17:05 wooster0

I am not using std.elf.toTargetCpuArch anywhere in zld either. I am using toElfMachine to flag up errors to the users though, but those calls can be replaced with std.elf.EM.fromTargetCpuArch. Next step would be to either flag up use of toElfMachine as a compile error with deprecation message, or re-implement it as inlined call to std.elf.EM.fromTargetCpuArch.

kubkon avatar May 28 '23 18:05 kubkon

https://github.com/search?q=toTargetCpuArch+language%3AZig&type=code&l=Zig

I can't see any real-world usage of toTargetCpuArch (except in zld but you said you don't use that anymore so I assume that's just outdated). Do you think we can remove both of those toTargetCpuArch functions then (and still deprecate those too probably)? Or else we can just leave them here for now.

Alright, I added two deprecation declarations for toElfMachine and toCoffMachine.

wooster0 avatar May 28 '23 18:05 wooster0

Oh so this thing is causing the problem here:

test {
    std.testing.refAllDecls(Target.Cpu.Arch);
}

Fixed that now hopefully.

wooster0 avatar May 28 '23 19:05 wooster0

Sorry are you suggesting that the current std.Target.Cpu.Arch.toElfMachine and std.Target.Cpu.Arch.toCoffMachine were good and instead I could just remove std.coff.MachineType.fromTargetCpuArch and merge the logic into std.Target.Cpu.Arch.toCoffMachine? I think that'd be good too but just want to make sure I'm understanding it right.

wooster0 avatar Jun 15 '23 07:06 wooster0

I'm sorry, I don't see the purpose of this patch. Closing.

andrewrk avatar Oct 19 '23 00:10 andrewrk