Commit 6316fd9535

Alex Rønne Petersen <alex@alexrp.com>
2024-08-11 22:11:35
std.Target: Add goff and xcoff to ObjectFormat.
Also improve the docs a bit, and handle driverkit and dxil in default().
1 parent fc29240
Changed files (5)
lib/std/Target.zig
@@ -760,52 +760,59 @@ pub const Abi = enum {
 };
 
 pub const ObjectFormat = enum {
-    /// Common Object File Format (Windows)
+    /// C source code.
+    c,
+    /// The Common Object File Format used by Windows and UEFI.
     coff,
-    /// DirectX Container
+    /// The DirectX Container format containing either DXIL or DXBC.
     dxcontainer,
-    /// Executable and Linking Format
+    /// The Executable and Linkable Format used by many Unixes.
     elf,
-    /// macOS relocatables
-    macho,
-    /// Standard, Portable Intermediate Representation V
-    spirv,
-    /// WebAssembly
-    wasm,
-    /// C source code
-    c,
-    /// Intel IHEX
+    /// The Generalized Object File Format used by z/OS.
+    goff,
+    /// The Intel HEX format for storing binary code in ASCII text.
     hex,
+    /// The Mach object format used by macOS and other Apple platforms.
+    macho,
+    /// Nvidia's PTX (Parallel Thread Execution) assembly language.
+    nvptx,
+    /// The a.out format used by Plan 9 from Bell Labs.
+    plan9,
     /// Machine code with no metadata.
     raw,
-    /// Plan 9 from Bell Labs
-    plan9,
-    /// Nvidia PTX format
-    nvptx,
+    /// The Khronos Group's Standard Portable Intermediate Representation V.
+    spirv,
+    /// The WebAssembly binary format.
+    wasm,
+    /// The eXtended Common Object File Format used by AIX.
+    xcoff,
 
     pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8 {
         return switch (of) {
-            .coff => ".obj",
-            .elf, .macho, .wasm => ".o",
             .c => ".c",
-            .spirv => ".spv",
+            .coff => ".obj",
+            .dxcontainer => ".dxil",
+            .elf, .goff, .macho, .wasm, .xcoff => ".o",
             .hex => ".ihex",
-            .raw => ".bin",
-            .plan9 => arch.plan9Ext(),
             .nvptx => ".ptx",
-            .dxcontainer => ".dxil",
+            .plan9 => arch.plan9Ext(),
+            .raw => ".bin",
+            .spirv => ".spv",
         };
     }
 
     pub fn default(os_tag: Os.Tag, arch: Cpu.Arch) ObjectFormat {
         return switch (os_tag) {
-            .windows, .uefi => .coff,
-            .ios, .macos, .watchos, .tvos, .visionos => .macho,
+            .aix => .xcoff,
+            .driverkit, .ios, .macos, .tvos, .visionos, .watchos => .macho,
             .plan9 => .plan9,
+            .uefi, .windows => .coff,
+            .zos => .goff,
             else => switch (arch) {
-                .wasm32, .wasm64 => .wasm,
-                .spirv32, .spirv64 => .spirv,
+                .dxil => .dxcontainer,
                 .nvptx, .nvptx64 => .nvptx,
+                .spirv, .spirv32, .spirv64 => .spirv,
+                .wasm32, .wasm64 => .wasm,
                 else => .elf,
             },
         };
lib/std/zig.zig
@@ -163,7 +163,7 @@ pub fn binNameAlloc(allocator: Allocator, options: BinNameOptions) error{OutOfMe
             },
             .Obj => return std.fmt.allocPrint(allocator, "{s}.obj", .{root_name}),
         },
-        .elf => switch (options.output_mode) {
+        .elf, .goff, .xcoff => switch (options.output_mode) {
             .Exe => return allocator.dupe(u8, root_name),
             .Lib => {
                 switch (options.link_mode orelse .static) {
src/Compilation/Config.zig
@@ -434,7 +434,7 @@ pub fn resolve(options: Options) ResolveError!Config {
     const debug_format: DebugFormat = b: {
         if (root_strip and !options.any_non_stripped) break :b .strip;
         break :b switch (target.ofmt) {
-            .elf, .macho, .wasm => .{ .dwarf = .@"32" },
+            .elf, .goff, .macho, .wasm, .xcoff => .{ .dwarf = .@"32" },
             .coff => .code_view,
             .c => switch (target.os.tag) {
                 .windows, .uefi => .code_view,
src/link.zig
@@ -902,6 +902,8 @@ pub const File = struct {
                 .c => .c,
                 .spirv => .spirv,
                 .nvptx => .nvptx,
+                .goff => @panic("TODO implement goff object format"),
+                .xcoff => @panic("TODO implement xcoff object format"),
                 .hex => @panic("TODO implement hex object format"),
                 .raw => @panic("TODO implement raw object format"),
                 .dxcontainer => @panic("TODO implement dxcontainer object format"),
src/target.zig
@@ -98,14 +98,16 @@ pub fn hasLlvmSupport(target: std.Target, ofmt: std.Target.ObjectFormat) bool {
         => return false,
 
         .coff,
+        .dxcontainer,
         .elf,
+        .goff,
+        .hex,
         .macho,
-        .wasm,
+        .nvptx,
         .spirv,
-        .hex,
         .raw,
-        .nvptx,
-        .dxcontainer,
+        .wasm,
+        .xcoff,
         => {},
     }