authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-06-01 16:07:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-08 14:10:49-07:00
log34c21affa2429cf07042eb2f225ee59194998802
treeb75283e0215fa3e5de31c1995e71a56f35942c28
parent1f0b77b3b88112ef458f62c23df72003c843e7cc

initial plan9 boilerplate

The code now compiles and fails with Plan9ObjectFormatUnimplemented

10 files changed, 114 insertions(+), 3 deletions(-)

CMakeLists.txt+2
......@@ -573,6 +573,8 @@ set(ZIG_STAGE2_SOURCES
573573 "${CMAKE_SOURCE_DIR}/src/link/C.zig"
574574 "${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
575575 "${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
576 "${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
577 "${CMAKE_SOURCE_DIR}/src/link/plan9/a.out.zig"
576578 "${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
577579 "${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
578580 "${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"
lib/std/target.zig+9
......@@ -60,6 +60,7 @@ pub const Target = struct {
6060 opencl,
6161 glsl450,
6262 vulkan,
63 plan9,
6364 other,
6465
6566 pub fn isDarwin(tag: Tag) bool {
......@@ -262,6 +263,7 @@ pub const Target = struct {
262263 .opencl, // TODO: OpenCL versions
263264 .glsl450, // TODO: GLSL versions
264265 .vulkan,
266 .plan9,
265267 .other,
266268 => return .{ .none = {} },
267269
......@@ -420,6 +422,7 @@ pub const Target = struct {
420422 .opencl,
421423 .glsl450,
422424 .vulkan,
425 .plan9,
423426 .other,
424427 => false,
425428 };
......@@ -515,6 +518,7 @@ pub const Target = struct {
515518 .opencl, // TODO: SPIR-V ABIs with Linkage capability
516519 .glsl450,
517520 .vulkan,
521 .plan9, // TODO specify abi
518522 => return .none,
519523 }
520524 }
......@@ -554,6 +558,7 @@ pub const Target = struct {
554558 spirv,
555559 hex,
556560 raw,
561 plan9,
557562 };
558563
559564 pub const SubSystem = enum {
......@@ -1359,6 +1364,8 @@ pub const Target = struct {
13591364 if (cpu_arch.isSPIRV()) {
13601365 return .spirv;
13611366 }
1367 if (os_tag == .plan9)
1368 return .plan9;
13621369 return .elf;
13631370 }
13641371
......@@ -1432,6 +1439,7 @@ pub const Target = struct {
14321439 .opencl,
14331440 .glsl450,
14341441 .vulkan,
1442 .plan9,
14351443 .other,
14361444 => return false,
14371445 else => return true,
......@@ -1616,6 +1624,7 @@ pub const Target = struct {
16161624 .glsl450,
16171625 .vulkan,
16181626 .other,
1627 .plan9,
16191628 => return result,
16201629
16211630 // TODO revisit when multi-arch for Haiku is available
lib/std/zig.zig+2
......@@ -181,6 +181,8 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
181181 .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}),
182182 .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}),
183183 .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}),
184 // TODO change this to the arbitrary character for plan9 output, eg '6' for amd64
185 .plan9 => return std.fmt.allocPrint(allocator, "{s}.out.p9", .{root_name}),
184186 }
185187}
186188
lib/std/zig/cross_target.zig+2
......@@ -133,6 +133,7 @@ pub const CrossTarget = struct {
133133 .opencl,
134134 .glsl450,
135135 .vulkan,
136 .plan9,
136137 .other,
137138 => {
138139 self.os_version_min = .{ .none = {} };
......@@ -746,6 +747,7 @@ pub const CrossTarget = struct {
746747 .opencl,
747748 .glsl450,
748749 .vulkan,
750 .plan9,
749751 .other,
750752 => return error.InvalidOperatingSystemVersion,
751753
src/Module.zig+8
......@@ -3437,6 +3437,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
34373437 // in `Decl` to notice that the line number did not change.
34383438 mod.comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl });
34393439 },
3440 .plan9 => {
3441 // TODO implement for plan9
3442 },
34403443 .c, .wasm, .spirv => {},
34413444 }
34423445 }
......@@ -3514,6 +3517,7 @@ pub fn clearDecl(
35143517 .coff => .{ .coff = link.File.Coff.TextBlock.empty },
35153518 .elf => .{ .elf = link.File.Elf.TextBlock.empty },
35163519 .macho => .{ .macho = link.File.MachO.TextBlock.empty },
3520 .plan9 => @panic("plan9 link"),
35173521 .c => .{ .c = link.File.C.DeclBlock.empty },
35183522 .wasm => .{ .wasm = link.File.Wasm.DeclBlock.empty },
35193523 .spirv => .{ .spirv = {} },
......@@ -3522,6 +3526,7 @@ pub fn clearDecl(
35223526 .coff => .{ .coff = {} },
35233527 .elf => .{ .elf = link.File.Elf.SrcFn.empty },
35243528 .macho => .{ .macho = link.File.MachO.SrcFn.empty },
3529 .plan9 => @panic("plan9 fn_link"),
35253530 .c => .{ .c = link.File.C.FnBlock.empty },
35263531 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
35273532 .spirv => .{ .spirv = .{} },
......@@ -3689,6 +3694,7 @@ fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node
36893694 .coff => .{ .coff = link.File.Coff.TextBlock.empty },
36903695 .elf => .{ .elf = link.File.Elf.TextBlock.empty },
36913696 .macho => .{ .macho = link.File.MachO.TextBlock.empty },
3697 .plan9 => @panic("PLan9 export"),
36923698 .c => .{ .c = link.File.C.DeclBlock.empty },
36933699 .wasm => .{ .wasm = link.File.Wasm.DeclBlock.empty },
36943700 .spirv => .{ .spirv = {} },
......@@ -3697,6 +3703,7 @@ fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node
36973703 .coff => .{ .coff = {} },
36983704 .elf => .{ .elf = link.File.Elf.SrcFn.empty },
36993705 .macho => .{ .macho = link.File.MachO.SrcFn.empty },
3706 .plan9 => .{ .plan9 = link.File.Plan9.SrcFn.empty },
37003707 .c => .{ .c = link.File.C.FnBlock.empty },
37013708 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
37023709 .spirv => .{ .spirv = .{} },
......@@ -3766,6 +3773,7 @@ pub fn analyzeExport(
37663773 .coff => .{ .coff = {} },
37673774 .elf => .{ .elf = link.File.Elf.Export{} },
37683775 .macho => .{ .macho = link.File.MachO.Export{} },
3776 .plan9 => @panic("plan9 link"),
37693777 .c => .{ .c = {} },
37703778 .wasm => .{ .wasm = {} },
37713779 .spirv => .{ .spirv = {} },
src/codegen/llvm.zig+1
......@@ -117,6 +117,7 @@ pub fn targetTriple(allocator: *Allocator, target: std.Target) ![:0]u8 {
117117 .opencl => return error.LLVMBackendDoesNotSupportOpenCL,
118118 .glsl450 => return error.LLVMBackendDoesNotSupportGLSL450,
119119 .vulkan => return error.LLVMBackendDoesNotSupportVulkan,
120 .plan9 => return error.LLVMBackendDoesNotSupportPlan9,
120121 .other => "unknown",
121122 };
122123
src/link.zig+23-2
......@@ -150,6 +150,7 @@ pub const File = struct {
150150 elf: Elf.SrcFn,
151151 coff: Coff.SrcFn,
152152 macho: MachO.SrcFn,
153 plan9: Plan9.SrcFn,
153154 c: C.FnBlock,
154155 wasm: Wasm.FnData,
155156 spirv: SpirV.FnData,
......@@ -159,6 +160,7 @@ pub const File = struct {
159160 elf: Elf.Export,
160161 coff: void,
161162 macho: MachO.Export,
163 plan9: Plan9.Export,
162164 c: void,
163165 wasm: void,
164166 spirv: void,
......@@ -189,6 +191,7 @@ pub const File = struct {
189191 .elf => &(try Elf.createEmpty(allocator, options)).base,
190192 .macho => &(try MachO.createEmpty(allocator, options)).base,
191193 .wasm => &(try Wasm.createEmpty(allocator, options)).base,
194 .plan9 => return &(try Plan9.createEmpty(allocator, options)).base,
192195 .c => unreachable, // Reported error earlier.
193196 .spirv => &(try SpirV.createEmpty(allocator, options)).base,
194197 .hex => return error.HexObjectFormatUnimplemented,
......@@ -209,6 +212,7 @@ pub const File = struct {
209212 .spirv => &(try SpirV.createEmpty(allocator, options)).base,
210213 .hex => return error.HexObjectFormatUnimplemented,
211214 .raw => return error.RawObjectFormatUnimplemented,
215 .plan9 => return error.Plan9ObjectFormatUnimplemented,
212216 };
213217 }
214218 // 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 {
225229 .spirv => &(try SpirV.openPath(allocator, sub_path, options)).base,
226230 .hex => return error.HexObjectFormatUnimplemented,
227231 .raw => return error.RawObjectFormatUnimplemented,
232 .plan9 => return error.Plan9ObjectFormatUnimplemented,
228233 };
229234
230235 if (use_lld) {
......@@ -243,7 +248,7 @@ pub const File = struct {
243248
244249 pub fn makeWritable(base: *File) !void {
245250 switch (base.tag) {
246 .coff, .elf, .macho => {
251 .coff, .elf, .macho, .plan9 => {
247252 if (base.file != null) return;
248253 const emit = base.options.emit orelse return;
249254 base.file = try emit.directory.handle.createFile(emit.sub_path, .{
......@@ -288,7 +293,7 @@ pub const File = struct {
288293 f.close();
289294 base.file = null;
290295 },
291 .coff, .elf => if (base.file) |f| {
296 .coff, .elf, .plan9 => if (base.file) |f| {
292297 if (base.intermediary_basename != null) {
293298 // The file we have open is not the final file that we want to
294299 // make executable, so we don't have to close it.
......@@ -313,6 +318,7 @@ pub const File = struct {
313318 .c => return @fieldParentPtr(C, "base", base).updateDecl(module, decl),
314319 .wasm => return @fieldParentPtr(Wasm, "base", base).updateDecl(module, decl),
315320 .spirv => return @fieldParentPtr(SpirV, "base", base).updateDecl(module, decl),
321 .plan9 => return @fieldParentPtr(Plan9, "base", base).updateDecl(module, decl),
316322 }
317323 }
318324
......@@ -326,6 +332,7 @@ pub const File = struct {
326332 .elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl),
327333 .macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl),
328334 .c => return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl),
335 .plan9 => @panic("PLAN 9 DEBUG INFO"),
329336 .wasm, .spirv => {},
330337 }
331338 }
......@@ -340,6 +347,7 @@ pub const File = struct {
340347 .macho => return @fieldParentPtr(MachO, "base", base).allocateDeclIndexes(decl),
341348 .c => return @fieldParentPtr(C, "base", base).allocateDeclIndexes(decl),
342349 .wasm => return @fieldParentPtr(Wasm, "base", base).allocateDeclIndexes(decl),
350 .plan9 => return @fieldParentPtr(Plan9, "base", base).allocateDeclIndexes(decl),
343351 .spirv => {},
344352 }
345353 }
......@@ -393,6 +401,11 @@ pub const File = struct {
393401 parent.deinit();
394402 base.allocator.destroy(parent);
395403 },
404 .plan9 => {
405 const parent = @fieldParentPtr(Plan9, "base", base);
406 parent.deinit();
407 base.allocator.destroy(parent);
408 },
396409 }
397410 }
398411
......@@ -425,6 +438,7 @@ pub const File = struct {
425438 .c => return @fieldParentPtr(C, "base", base).flush(comp),
426439 .wasm => return @fieldParentPtr(Wasm, "base", base).flush(comp),
427440 .spirv => return @fieldParentPtr(SpirV, "base", base).flush(comp),
441 .plan9 => return @fieldParentPtr(Plan9, "base", base).flush(comp),
428442 }
429443 }
430444
......@@ -438,6 +452,7 @@ pub const File = struct {
438452 .c => return @fieldParentPtr(C, "base", base).flushModule(comp),
439453 .wasm => return @fieldParentPtr(Wasm, "base", base).flushModule(comp),
440454 .spirv => return @fieldParentPtr(SpirV, "base", base).flushModule(comp),
455 .plan9 => return @fieldParentPtr(Plan9, "base", base).flushModule(comp),
441456 }
442457 }
443458
......@@ -451,6 +466,7 @@ pub const File = struct {
451466 .c => @fieldParentPtr(C, "base", base).freeDecl(decl),
452467 .wasm => @fieldParentPtr(Wasm, "base", base).freeDecl(decl),
453468 .spirv => @fieldParentPtr(SpirV, "base", base).freeDecl(decl),
469 .plan9 => @fieldParentPtr(Plan9, "base", base).freeDecl(decl),
454470 }
455471 }
456472
......@@ -459,6 +475,7 @@ pub const File = struct {
459475 .coff => return @fieldParentPtr(Coff, "base", base).error_flags,
460476 .elf => return @fieldParentPtr(Elf, "base", base).error_flags,
461477 .macho => return @fieldParentPtr(MachO, "base", base).error_flags,
478 .plan9 => return @fieldParentPtr(Plan9, "base", base).error_flags,
462479 .c => return .{ .no_entry_point_found = false },
463480 .wasm, .spirv => return ErrorFlags{},
464481 }
......@@ -481,6 +498,7 @@ pub const File = struct {
481498 .c => return @fieldParentPtr(C, "base", base).updateDeclExports(module, decl, exports),
482499 .wasm => return @fieldParentPtr(Wasm, "base", base).updateDeclExports(module, decl, exports),
483500 .spirv => return @fieldParentPtr(SpirV, "base", base).updateDeclExports(module, decl, exports),
501 .plan9 => return @fieldParentPtr(Plan9, "base", base).updateDeclExports(module, decl, exports),
484502 }
485503 }
486504
......@@ -489,6 +507,7 @@ pub const File = struct {
489507 .coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl),
490508 .elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl),
491509 .macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl),
510 .plan9 => @panic("GET VADDR"),
492511 .c => unreachable,
493512 .wasm => unreachable,
494513 .spirv => unreachable,
......@@ -633,6 +652,7 @@ pub const File = struct {
633652 c,
634653 wasm,
635654 spirv,
655 plan9,
636656 };
637657
638658 pub const ErrorFlags = struct {
......@@ -641,6 +661,7 @@ pub const File = struct {
641661
642662 pub const C = @import("link/C.zig");
643663 pub const Coff = @import("link/Coff.zig");
664 pub const Plan9 = @import("link/Plan9.zig");
644665 pub const Elf = @import("link/Elf.zig");
645666 pub const MachO = @import("link/MachO.zig");
646667 pub const SpirV = @import("link/SpirV.zig");
src/link/Plan9.zig created+65
......@@ -0,0 +1,65 @@
1const Plan9 = @This();
2
3const std = @import("std");
4const link = @import("../link.zig");
5const Module = @import("../Module.zig");
6const Compilation = @import("../Compilation.zig");
7const File = link.File;
8const Allocator = std.mem.Allocator;
9
10const log = std.log.scoped(.link);
11
12base: link.File,
13error_flags: File.ErrorFlags = File.ErrorFlags{},
14
15pub const SrcFn = struct {
16 /// Offset from the beginning of the Debug Line Program header that contains this function.
17 off: u32,
18 /// Size of the line number program component belonging to this function, not
19 /// including padding.
20 len: u32,
21
22 /// Points to the previous and next neighbors, based on the offset from .debug_line.
23 /// This can be used to find, for example, the capacity of this `SrcFn`.
24 prev: ?*SrcFn,
25 next: ?*SrcFn,
26
27 pub const empty: SrcFn = .{
28 .off = 0,
29 .len = 0,
30 .prev = null,
31 .next = null,
32 };
33};
34
35pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Plan9 {
36 const self = try gpa.create(Plan9);
37 self.* = .{
38 .base = .{
39 .tag = .plan9,
40 .options = options,
41 .allocator = gpa,
42 .file = null,
43 },
44 };
45 return self;
46}
47
48pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {}
49
50pub fn allocateDeclIndexes(self: *Plan9, decl: *Module.Decl) !void {}
51
52pub fn flush(self: *Plan9, comp: *Compilation) !void {}
53pub fn flushModule(self: *Plan9, comp: *Compilation) !void {}
54pub fn freeDecl(self: *Plan9, decl: *Module.Decl) void {}
55pub fn updateDeclExports(
56 self: *Plan9,
57 module: *Module,
58 decl: *Module.Decl,
59 exports: []const *Module.Export,
60) !void {}
61pub fn deinit(self: *Plan9) void {}
62
63pub const Export = struct {
64 sym_index: ?u32 = null,
65};
src/target.zig+1-1
......@@ -244,7 +244,7 @@ pub fn supportsStackProbing(target: std.Target) bool {
244244
245245pub fn osToLLVM(os_tag: std.Target.Os.Tag) llvm.OSType {
246246 return switch (os_tag) {
247 .freestanding, .other, .opencl, .glsl450, .vulkan => .UnknownOS,
247 .freestanding, .other, .opencl, .glsl450, .vulkan, .plan9 => .UnknownOS,
248248 .windows, .uefi => .Win32,
249249 .ananas => .Ananas,
250250 .cloudabi => .CloudABI,
src/type.zig+1
......@@ -3290,6 +3290,7 @@ pub const CType = enum {
32903290 .openbsd,
32913291 .wasi,
32923292 .emscripten,
3293 .plan9,
32933294 => switch (self) {
32943295 .short,
32953296 .ushort,