Skip to content

Allow COFF output for freestanding target #3182

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

Open
jayschwa opened this issue Sep 6, 2019 · 7 comments
Open

Allow COFF output for freestanding target #3182

jayschwa opened this issue Sep 6, 2019 · 7 comments
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@jayschwa
Copy link
Contributor

jayschwa commented Sep 6, 2019

I am experimenting with linking Zig libraries into DOS executables using the Open Watcom toolchain. The Watcom linker seems to require COFF because it does not understand ELF. When building the Zig library, I cannot figure out how to target freestanding and get COFF output. For now, I am using i386-uefi-none as my target.

@andrewrk andrewrk added accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Sep 6, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Sep 6, 2019
@andrewrk
Copy link
Member

andrewrk commented Sep 6, 2019

I think we can add this as a DOS OS. That should be a pretty straightforward modification. Then you could use -target i386-dos as your target.

@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Sep 6, 2019
@Tetralux
Copy link
Contributor

Tetralux commented Sep 9, 2019

Another option here is something like:

// main.zig

pub const debug_info_type = .COFF; // or .ELF, .Auto

pub fn main() void {}

@ikskuh
Copy link
Contributor

ikskuh commented Nov 21, 2019

If it's possible, add support for allowing arbitrary overrides of the output format for the user. The linker could output PE, COFF, ECOFF, ELF, flat binaries, ihex, ....

This would allow something like x86_64-windows-elf or aarch64-linux-coff.

This is especially interesting for freestanding targets if you write plugins/modules for custom/embedded systems.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 11, 2020
@daurnimator
Copy link
Contributor

Same as #2826 (but add COFF?)

@jayschwa
Copy link
Contributor Author

My original use-case for this issue has been obsoleted. I am now using a linker script to produce a MZ executable that subsequently loads and runs an ELF executable. That said, making output format configurable is probably still desirable.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 9, 2020
@Ronsor
Copy link

Ronsor commented Mar 1, 2021

After some investigation, I've found LLVM will never output COFF objects unless the target triple is *-windows-msvc.

This seems to leave three options: (1) change LLVM's behavior, (2) add a separate freestanding-coff OS target that tells LLVM to target *-windows-msvc (in a similar way to the UEFI target), or (3) add a special case for *-freestanding-msvc that does the same as (2).

@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 20, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jun 29, 2023
@alexrp
Copy link
Member

alexrp commented Sep 5, 2024

LLVM target triples can actually encode the object format in all cases. For this use case, x86-unknown-unknown-coff would be the thing to use. (More generally, the environment component can be of the form <abi>...anything...<ofmt>.) Unfortunately, the MC layer won't accept that. It would be interesting to investigate why that is; the same limitation does not exist for Mach-O and ELF. Maybe this limitation can be lifted.

@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

7 participants