I would start with understanding what cosmocc does under the hood (e.g. which target-triple it is using):
…and then try to replicate those exact compilation settings in the Zig compiler (my uneducated guess is that it’s mainly about making sure that the Zig-compiled code uses the same target triple expected by the cosmo-linker).
PS: also this ‘fixupobj’ command in the link above seems kinda important…, don’t know what this does though.
PS: this older thread might also be relevant: Actually Portable Executable (APE) with Zig