authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-11 22:11:35+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-11 20:21:28-07:00
log6316fd95351fb207d0680f396123a455a91ea4a2
tree0d65c18c41e4375762a88dc57d265b4814495fb1
parentfc2924080694d68945308d394751a2ec4841b3c0

std.Target: Add goff and xcoff to ObjectFormat.

Also improve the docs a bit, and handle driverkit and dxil in default().

5 files changed, 43 insertions(+), 32 deletions(-)

lib/std/Target.zig+33-26
......@@ -760,52 +760,59 @@ pub const Abi = enum {
760760};
761761
762762pub const ObjectFormat = enum {
763 /// Common Object File Format (Windows)
763 /// C source code.
764 c,
765 /// The Common Object File Format used by Windows and UEFI.
764766 coff,
765 /// DirectX Container
767 /// The DirectX Container format containing either DXIL or DXBC.
766768 dxcontainer,
767 /// Executable and Linking Format
769 /// The Executable and Linkable Format used by many Unixes.
768770 elf,
769 /// macOS relocatables
770 macho,
771 /// Standard, Portable Intermediate Representation V
772 spirv,
773 /// WebAssembly
774 wasm,
775 /// C source code
776 c,
777 /// Intel IHEX
771 /// The Generalized Object File Format used by z/OS.
772 goff,
773 /// The Intel HEX format for storing binary code in ASCII text.
778774 hex,
775 /// The Mach object format used by macOS and other Apple platforms.
776 macho,
777 /// Nvidia's PTX (Parallel Thread Execution) assembly language.
778 nvptx,
779 /// The a.out format used by Plan 9 from Bell Labs.
780 plan9,
779781 /// Machine code with no metadata.
780782 raw,
781 /// Plan 9 from Bell Labs
782 plan9,
783 /// Nvidia PTX format
784 nvptx,
783 /// The Khronos Group's Standard Portable Intermediate Representation V.
784 spirv,
785 /// The WebAssembly binary format.
786 wasm,
787 /// The eXtended Common Object File Format used by AIX.
788 xcoff,
785789
786790 pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8 {
787791 return switch (of) {
788 .coff => ".obj",
789 .elf, .macho, .wasm => ".o",
790792 .c => ".c",
791 .spirv => ".spv",
793 .coff => ".obj",
794 .dxcontainer => ".dxil",
795 .elf, .goff, .macho, .wasm, .xcoff => ".o",
792796 .hex => ".ihex",
793 .raw => ".bin",
794 .plan9 => arch.plan9Ext(),
795797 .nvptx => ".ptx",
796 .dxcontainer => ".dxil",
798 .plan9 => arch.plan9Ext(),
799 .raw => ".bin",
800 .spirv => ".spv",
797801 };
798802 }
799803
800804 pub fn default(os_tag: Os.Tag, arch: Cpu.Arch) ObjectFormat {
801805 return switch (os_tag) {
802 .windows, .uefi => .coff,
803 .ios, .macos, .watchos, .tvos, .visionos => .macho,
806 .aix => .xcoff,
807 .driverkit, .ios, .macos, .tvos, .visionos, .watchos => .macho,
804808 .plan9 => .plan9,
809 .uefi, .windows => .coff,
810 .zos => .goff,
805811 else => switch (arch) {
806 .wasm32, .wasm64 => .wasm,
807 .spirv32, .spirv64 => .spirv,
812 .dxil => .dxcontainer,
808813 .nvptx, .nvptx64 => .nvptx,
814 .spirv, .spirv32, .spirv64 => .spirv,
815 .wasm32, .wasm64 => .wasm,
809816 else => .elf,
810817 },
811818 };
lib/std/zig.zig+1-1
......@@ -163,7 +163,7 @@ pub fn binNameAlloc(allocator: Allocator, options: BinNameOptions) error{OutOfMe
163163 },
164164 .Obj => return std.fmt.allocPrint(allocator, "{s}.obj", .{root_name}),
165165 },
166 .elf => switch (options.output_mode) {
166 .elf, .goff, .xcoff => switch (options.output_mode) {
167167 .Exe => return allocator.dupe(u8, root_name),
168168 .Lib => {
169169 switch (options.link_mode orelse .static) {
src/Compilation/Config.zig+1-1
......@@ -434,7 +434,7 @@ pub fn resolve(options: Options) ResolveError!Config {
434434 const debug_format: DebugFormat = b: {
435435 if (root_strip and !options.any_non_stripped) break :b .strip;
436436 break :b switch (target.ofmt) {
437 .elf, .macho, .wasm => .{ .dwarf = .@"32" },
437 .elf, .goff, .macho, .wasm, .xcoff => .{ .dwarf = .@"32" },
438438 .coff => .code_view,
439439 .c => switch (target.os.tag) {
440440 .windows, .uefi => .code_view,
src/link.zig+2
......@@ -902,6 +902,8 @@ pub const File = struct {
902902 .c => .c,
903903 .spirv => .spirv,
904904 .nvptx => .nvptx,
905 .goff => @panic("TODO implement goff object format"),
906 .xcoff => @panic("TODO implement xcoff object format"),
905907 .hex => @panic("TODO implement hex object format"),
906908 .raw => @panic("TODO implement raw object format"),
907909 .dxcontainer => @panic("TODO implement dxcontainer object format"),
src/target.zig+6-4
......@@ -98,14 +98,16 @@ pub fn hasLlvmSupport(target: std.Target, ofmt: std.Target.ObjectFormat) bool {
9898 => return false,
9999
100100 .coff,
101 .dxcontainer,
101102 .elf,
103 .goff,
104 .hex,
102105 .macho,
103 .wasm,
106 .nvptx,
104107 .spirv,
105 .hex,
106108 .raw,
107 .nvptx,
108 .dxcontainer,
109 .wasm,
110 .xcoff,
109111 => {},
110112 }
111113