std.Target: Add goff and xcoff to ObjectFormat.

Also improve the docs a bit, and handle driverkit and dxil in default().
This commit is contained in:
Alex Rønne Petersen 2024-08-11 22:11:35 +02:00 committed by Andrew Kelley
parent fc29240806
commit 6316fd9535
5 changed files with 49 additions and 38 deletions

View File

@ -760,52 +760,59 @@ pub const Abi = enum {
};
pub const ObjectFormat = enum {
/// Common Object File Format (Windows)
coff,
/// DirectX Container
dxcontainer,
/// Executable and Linking Format
elf,
/// macOS relocatables
macho,
/// Standard, Portable Intermediate Representation V
spirv,
/// WebAssembly
wasm,
/// C source code
/// C source code.
c,
/// Intel IHEX
/// The Common Object File Format used by Windows and UEFI.
coff,
/// The DirectX Container format containing either DXIL or DXBC.
dxcontainer,
/// The Executable and Linkable Format used by many Unixes.
elf,
/// 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",
.hex => ".ihex",
.raw => ".bin",
.plan9 => arch.plan9Ext(),
.nvptx => ".ptx",
.coff => ".obj",
.dxcontainer => ".dxil",
.elf, .goff, .macho, .wasm, .xcoff => ".o",
.hex => ".ihex",
.nvptx => ".ptx",
.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,
},
};

View File

@ -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) {

View File

@ -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,

View File

@ -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"),

View File

@ -98,14 +98,16 @@ pub fn hasLlvmSupport(target: std.Target, ofmt: std.Target.ObjectFormat) bool {
=> return false,
.coff,
.elf,
.macho,
.wasm,
.spirv,
.hex,
.raw,
.nvptx,
.dxcontainer,
.elf,
.goff,
.hex,
.macho,
.nvptx,
.spirv,
.raw,
.wasm,
.xcoff,
=> {},
}