initial plan9 boilerplate

The code now compiles and fails with Plan9ObjectFormatUnimplemented
This commit is contained in:
jacob gw 2021-06-01 16:07:08 -04:00 committed by Andrew Kelley
parent 1f0b77b3b8
commit 34c21affa2
10 changed files with 114 additions and 3 deletions

View File

@ -573,6 +573,8 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/link/C.zig"
"${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
"${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
"${CMAKE_SOURCE_DIR}/src/link/plan9/a.out.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"

View File

@ -60,6 +60,7 @@ pub const Target = struct {
opencl,
glsl450,
vulkan,
plan9,
other,
pub fn isDarwin(tag: Tag) bool {
@ -262,6 +263,7 @@ pub const Target = struct {
.opencl, // TODO: OpenCL versions
.glsl450, // TODO: GLSL versions
.vulkan,
.plan9,
.other,
=> return .{ .none = {} },
@ -420,6 +422,7 @@ pub const Target = struct {
.opencl,
.glsl450,
.vulkan,
.plan9,
.other,
=> false,
};
@ -515,6 +518,7 @@ pub const Target = struct {
.opencl, // TODO: SPIR-V ABIs with Linkage capability
.glsl450,
.vulkan,
.plan9, // TODO specify abi
=> return .none,
}
}
@ -554,6 +558,7 @@ pub const Target = struct {
spirv,
hex,
raw,
plan9,
};
pub const SubSystem = enum {
@ -1359,6 +1364,8 @@ pub const Target = struct {
if (cpu_arch.isSPIRV()) {
return .spirv;
}
if (os_tag == .plan9)
return .plan9;
return .elf;
}
@ -1432,6 +1439,7 @@ pub const Target = struct {
.opencl,
.glsl450,
.vulkan,
.plan9,
.other,
=> return false,
else => return true,
@ -1616,6 +1624,7 @@ pub const Target = struct {
.glsl450,
.vulkan,
.other,
.plan9,
=> return result,
// TODO revisit when multi-arch for Haiku is available

View File

@ -181,6 +181,8 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
.spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}),
.hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}),
.raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}),
// TODO change this to the arbitrary character for plan9 output, eg '6' for amd64
.plan9 => return std.fmt.allocPrint(allocator, "{s}.out.p9", .{root_name}),
}
}

View File

@ -133,6 +133,7 @@ pub const CrossTarget = struct {
.opencl,
.glsl450,
.vulkan,
.plan9,
.other,
=> {
self.os_version_min = .{ .none = {} };
@ -746,6 +747,7 @@ pub const CrossTarget = struct {
.opencl,
.glsl450,
.vulkan,
.plan9,
.other,
=> return error.InvalidOperatingSystemVersion,

View File

@ -3437,6 +3437,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
// in `Decl` to notice that the line number did not change.
mod.comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl });
},
.plan9 => {
// TODO implement for plan9
},
.c, .wasm, .spirv => {},
}
}
@ -3514,6 +3517,7 @@ pub fn clearDecl(
.coff => .{ .coff = link.File.Coff.TextBlock.empty },
.elf => .{ .elf = link.File.Elf.TextBlock.empty },
.macho => .{ .macho = link.File.MachO.TextBlock.empty },
.plan9 => @panic("plan9 link"),
.c => .{ .c = link.File.C.DeclBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.DeclBlock.empty },
.spirv => .{ .spirv = {} },
@ -3522,6 +3526,7 @@ pub fn clearDecl(
.coff => .{ .coff = {} },
.elf => .{ .elf = link.File.Elf.SrcFn.empty },
.macho => .{ .macho = link.File.MachO.SrcFn.empty },
.plan9 => @panic("plan9 fn_link"),
.c => .{ .c = link.File.C.FnBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.FnData.empty },
.spirv => .{ .spirv = .{} },
@ -3689,6 +3694,7 @@ fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node
.coff => .{ .coff = link.File.Coff.TextBlock.empty },
.elf => .{ .elf = link.File.Elf.TextBlock.empty },
.macho => .{ .macho = link.File.MachO.TextBlock.empty },
.plan9 => @panic("PLan9 export"),
.c => .{ .c = link.File.C.DeclBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.DeclBlock.empty },
.spirv => .{ .spirv = {} },
@ -3697,6 +3703,7 @@ fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node
.coff => .{ .coff = {} },
.elf => .{ .elf = link.File.Elf.SrcFn.empty },
.macho => .{ .macho = link.File.MachO.SrcFn.empty },
.plan9 => .{ .plan9 = link.File.Plan9.SrcFn.empty },
.c => .{ .c = link.File.C.FnBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.FnData.empty },
.spirv => .{ .spirv = .{} },
@ -3766,6 +3773,7 @@ pub fn analyzeExport(
.coff => .{ .coff = {} },
.elf => .{ .elf = link.File.Elf.Export{} },
.macho => .{ .macho = link.File.MachO.Export{} },
.plan9 => @panic("plan9 link"),
.c => .{ .c = {} },
.wasm => .{ .wasm = {} },
.spirv => .{ .spirv = {} },

View File

@ -117,6 +117,7 @@ pub fn targetTriple(allocator: *Allocator, target: std.Target) ![:0]u8 {
.opencl => return error.LLVMBackendDoesNotSupportOpenCL,
.glsl450 => return error.LLVMBackendDoesNotSupportGLSL450,
.vulkan => return error.LLVMBackendDoesNotSupportVulkan,
.plan9 => return error.LLVMBackendDoesNotSupportPlan9,
.other => "unknown",
};

View File

@ -150,6 +150,7 @@ pub const File = struct {
elf: Elf.SrcFn,
coff: Coff.SrcFn,
macho: MachO.SrcFn,
plan9: Plan9.SrcFn,
c: C.FnBlock,
wasm: Wasm.FnData,
spirv: SpirV.FnData,
@ -159,6 +160,7 @@ pub const File = struct {
elf: Elf.Export,
coff: void,
macho: MachO.Export,
plan9: Plan9.Export,
c: void,
wasm: void,
spirv: void,
@ -189,6 +191,7 @@ pub const File = struct {
.elf => &(try Elf.createEmpty(allocator, options)).base,
.macho => &(try MachO.createEmpty(allocator, options)).base,
.wasm => &(try Wasm.createEmpty(allocator, options)).base,
.plan9 => return &(try Plan9.createEmpty(allocator, options)).base,
.c => unreachable, // Reported error earlier.
.spirv => &(try SpirV.createEmpty(allocator, options)).base,
.hex => return error.HexObjectFormatUnimplemented,
@ -209,6 +212,7 @@ pub const File = struct {
.spirv => &(try SpirV.createEmpty(allocator, options)).base,
.hex => return error.HexObjectFormatUnimplemented,
.raw => return error.RawObjectFormatUnimplemented,
.plan9 => return error.Plan9ObjectFormatUnimplemented,
};
}
// Open a temporary object file, not the final output file because we want to link with LLD.
@ -225,6 +229,7 @@ pub const File = struct {
.spirv => &(try SpirV.openPath(allocator, sub_path, options)).base,
.hex => return error.HexObjectFormatUnimplemented,
.raw => return error.RawObjectFormatUnimplemented,
.plan9 => return error.Plan9ObjectFormatUnimplemented,
};
if (use_lld) {
@ -243,7 +248,7 @@ pub const File = struct {
pub fn makeWritable(base: *File) !void {
switch (base.tag) {
.coff, .elf, .macho => {
.coff, .elf, .macho, .plan9 => {
if (base.file != null) return;
const emit = base.options.emit orelse return;
base.file = try emit.directory.handle.createFile(emit.sub_path, .{
@ -288,7 +293,7 @@ pub const File = struct {
f.close();
base.file = null;
},
.coff, .elf => if (base.file) |f| {
.coff, .elf, .plan9 => if (base.file) |f| {
if (base.intermediary_basename != null) {
// The file we have open is not the final file that we want to
// make executable, so we don't have to close it.
@ -313,6 +318,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).updateDecl(module, decl),
.wasm => return @fieldParentPtr(Wasm, "base", base).updateDecl(module, decl),
.spirv => return @fieldParentPtr(SpirV, "base", base).updateDecl(module, decl),
.plan9 => return @fieldParentPtr(Plan9, "base", base).updateDecl(module, decl),
}
}
@ -326,6 +332,7 @@ pub const File = struct {
.elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl),
.macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl),
.c => return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl),
.plan9 => @panic("PLAN 9 DEBUG INFO"),
.wasm, .spirv => {},
}
}
@ -340,6 +347,7 @@ pub const File = struct {
.macho => return @fieldParentPtr(MachO, "base", base).allocateDeclIndexes(decl),
.c => return @fieldParentPtr(C, "base", base).allocateDeclIndexes(decl),
.wasm => return @fieldParentPtr(Wasm, "base", base).allocateDeclIndexes(decl),
.plan9 => return @fieldParentPtr(Plan9, "base", base).allocateDeclIndexes(decl),
.spirv => {},
}
}
@ -393,6 +401,11 @@ pub const File = struct {
parent.deinit();
base.allocator.destroy(parent);
},
.plan9 => {
const parent = @fieldParentPtr(Plan9, "base", base);
parent.deinit();
base.allocator.destroy(parent);
},
}
}
@ -425,6 +438,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).flush(comp),
.wasm => return @fieldParentPtr(Wasm, "base", base).flush(comp),
.spirv => return @fieldParentPtr(SpirV, "base", base).flush(comp),
.plan9 => return @fieldParentPtr(Plan9, "base", base).flush(comp),
}
}
@ -438,6 +452,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).flushModule(comp),
.wasm => return @fieldParentPtr(Wasm, "base", base).flushModule(comp),
.spirv => return @fieldParentPtr(SpirV, "base", base).flushModule(comp),
.plan9 => return @fieldParentPtr(Plan9, "base", base).flushModule(comp),
}
}
@ -451,6 +466,7 @@ pub const File = struct {
.c => @fieldParentPtr(C, "base", base).freeDecl(decl),
.wasm => @fieldParentPtr(Wasm, "base", base).freeDecl(decl),
.spirv => @fieldParentPtr(SpirV, "base", base).freeDecl(decl),
.plan9 => @fieldParentPtr(Plan9, "base", base).freeDecl(decl),
}
}
@ -459,6 +475,7 @@ pub const File = struct {
.coff => return @fieldParentPtr(Coff, "base", base).error_flags,
.elf => return @fieldParentPtr(Elf, "base", base).error_flags,
.macho => return @fieldParentPtr(MachO, "base", base).error_flags,
.plan9 => return @fieldParentPtr(Plan9, "base", base).error_flags,
.c => return .{ .no_entry_point_found = false },
.wasm, .spirv => return ErrorFlags{},
}
@ -481,6 +498,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).updateDeclExports(module, decl, exports),
.wasm => return @fieldParentPtr(Wasm, "base", base).updateDeclExports(module, decl, exports),
.spirv => return @fieldParentPtr(SpirV, "base", base).updateDeclExports(module, decl, exports),
.plan9 => return @fieldParentPtr(Plan9, "base", base).updateDeclExports(module, decl, exports),
}
}
@ -489,6 +507,7 @@ pub const File = struct {
.coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl),
.elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl),
.macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl),
.plan9 => @panic("GET VADDR"),
.c => unreachable,
.wasm => unreachable,
.spirv => unreachable,
@ -633,6 +652,7 @@ pub const File = struct {
c,
wasm,
spirv,
plan9,
};
pub const ErrorFlags = struct {
@ -641,6 +661,7 @@ pub const File = struct {
pub const C = @import("link/C.zig");
pub const Coff = @import("link/Coff.zig");
pub const Plan9 = @import("link/Plan9.zig");
pub const Elf = @import("link/Elf.zig");
pub const MachO = @import("link/MachO.zig");
pub const SpirV = @import("link/SpirV.zig");

65
src/link/Plan9.zig Normal file
View File

@ -0,0 +1,65 @@
const Plan9 = @This();
const std = @import("std");
const link = @import("../link.zig");
const Module = @import("../Module.zig");
const Compilation = @import("../Compilation.zig");
const File = link.File;
const Allocator = std.mem.Allocator;
const log = std.log.scoped(.link);
base: link.File,
error_flags: File.ErrorFlags = File.ErrorFlags{},
pub const SrcFn = struct {
/// Offset from the beginning of the Debug Line Program header that contains this function.
off: u32,
/// Size of the line number program component belonging to this function, not
/// including padding.
len: u32,
/// Points to the previous and next neighbors, based on the offset from .debug_line.
/// This can be used to find, for example, the capacity of this `SrcFn`.
prev: ?*SrcFn,
next: ?*SrcFn,
pub const empty: SrcFn = .{
.off = 0,
.len = 0,
.prev = null,
.next = null,
};
};
pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Plan9 {
const self = try gpa.create(Plan9);
self.* = .{
.base = .{
.tag = .plan9,
.options = options,
.allocator = gpa,
.file = null,
},
};
return self;
}
pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {}
pub fn allocateDeclIndexes(self: *Plan9, decl: *Module.Decl) !void {}
pub fn flush(self: *Plan9, comp: *Compilation) !void {}
pub fn flushModule(self: *Plan9, comp: *Compilation) !void {}
pub fn freeDecl(self: *Plan9, decl: *Module.Decl) void {}
pub fn updateDeclExports(
self: *Plan9,
module: *Module,
decl: *Module.Decl,
exports: []const *Module.Export,
) !void {}
pub fn deinit(self: *Plan9) void {}
pub const Export = struct {
sym_index: ?u32 = null,
};

View File

@ -244,7 +244,7 @@ pub fn supportsStackProbing(target: std.Target) bool {
pub fn osToLLVM(os_tag: std.Target.Os.Tag) llvm.OSType {
return switch (os_tag) {
.freestanding, .other, .opencl, .glsl450, .vulkan => .UnknownOS,
.freestanding, .other, .opencl, .glsl450, .vulkan, .plan9 => .UnknownOS,
.windows, .uefi => .Win32,
.ananas => .Ananas,
.cloudabi => .CloudABI,

View File

@ -3290,6 +3290,7 @@ pub const CType = enum {
.openbsd,
.wasi,
.emscripten,
.plan9,
=> switch (self) {
.short,
.ushort,