authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-12-21 10:21:30+01:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-12-28 21:20:49+01:00
log6b8d28312ccca56d652af32bad360e9a5394fb8e
treef68700b2da3329968bc6c17e24ec085a8598d65b
parentb059bb84b85ca7914d617cae7c4960a798412ea5

stage2: fix building self-hosted without llvm-backend enabled.


2 files changed, 17 insertions(+), 20 deletions(-)

src/link/Coff.zig+8-10
...@@ -125,7 +125,7 @@ pub const SrcFn = void;...@@ -125,7 +125,7 @@ pub const SrcFn = void;
125pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Coff {125pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Coff {
126 assert(options.object_format == .coff);126 assert(options.object_format == .coff);
127127
128 if (options.use_llvm) {128 if (build_options.have_llvm and options.use_llvm) {
129 const self = try createEmpty(allocator, options);129 const self = try createEmpty(allocator, options);
130 errdefer self.base.destroy();130 errdefer self.base.destroy();
131131
...@@ -657,10 +657,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {...@@ -657,10 +657,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
657 const tracy = trace(@src());657 const tracy = trace(@src());
658 defer tracy.end();658 defer tracy.end();
659659
660 if (self.llvm_ir_module) |llvm_ir_module| {660 if (build_options.have_llvm)
661 try llvm_ir_module.updateDecl(module, decl);661 if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.updateDecl(module, decl);
662 return;
663 }
664662
665 var code_buffer = std.ArrayList(u8).init(self.base.allocator);663 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
666 defer code_buffer.deinit();664 defer code_buffer.deinit();
...@@ -760,10 +758,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation) !void {...@@ -760,10 +758,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation) !void {
760 const tracy = trace(@src());758 const tracy = trace(@src());
761 defer tracy.end();759 defer tracy.end();
762760
763 if (self.llvm_ir_module) |llvm_ir_module| {761 if (build_options.have_llvm)
764 try llvm_ir_module.flushModule(comp);762 if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.flushModule(comp);
765 return;
766 }
767763
768 if (self.text_section_size_dirty) {764 if (self.text_section_size_dirty) {
769 // Write the new raw size in the .text header765 // Write the new raw size in the .text header
...@@ -1257,7 +1253,9 @@ pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !v...@@ -1257,7 +1253,9 @@ pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !v
1257}1253}
12581254
1259pub fn deinit(self: *Coff) void {1255pub fn deinit(self: *Coff) void {
1260 if (self.llvm_ir_module) |ir_module| ir_module.deinit(self.base.allocator);1256 if (build_options.have_llvm)
1257 if (self.llvm_ir_module) |ir_module| ir_module.deinit(self.base.allocator);
1258
1261 self.text_block_free_list.deinit(self.base.allocator);1259 self.text_block_free_list.deinit(self.base.allocator);
1262 self.offset_table.deinit(self.base.allocator);1260 self.offset_table.deinit(self.base.allocator);
1263 self.offset_table_free_list.deinit(self.base.allocator);1261 self.offset_table_free_list.deinit(self.base.allocator);
src/link/Elf.zig+9-10
...@@ -228,7 +228,7 @@ pub const SrcFn = struct {...@@ -228,7 +228,7 @@ pub const SrcFn = struct {
228pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Elf {228pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Elf {
229 assert(options.object_format == .elf);229 assert(options.object_format == .elf);
230230
231 if (options.use_llvm) {231 if (build_options.have_llvm and options.use_llvm) {
232 const self = try createEmpty(allocator, options);232 const self = try createEmpty(allocator, options);
233 errdefer self.base.destroy();233 errdefer self.base.destroy();
234234
...@@ -298,7 +298,10 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf {...@@ -298,7 +298,10 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf {
298}298}
299299
300pub fn deinit(self: *Elf) void {300pub fn deinit(self: *Elf) void {
301 if (self.llvm_ir_module) |ir_module| ir_module.deinit(self.base.allocator);301 if (build_options.have_llvm)
302 if (self.llvm_ir_module) |ir_module|
303 ir_module.deinit(self.base.allocator);
304
302 self.sections.deinit(self.base.allocator);305 self.sections.deinit(self.base.allocator);
303 self.program_headers.deinit(self.base.allocator);306 self.program_headers.deinit(self.base.allocator);
304 self.shstrtab.deinit(self.base.allocator);307 self.shstrtab.deinit(self.base.allocator);
...@@ -740,10 +743,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {...@@ -740,10 +743,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
740 const tracy = trace(@src());743 const tracy = trace(@src());
741 defer tracy.end();744 defer tracy.end();
742745
743 if (self.llvm_ir_module) |llvm_ir_module| {746 if (build_options.have_llvm)
744 try llvm_ir_module.flushModule(comp);747 if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.flushModule(comp);
745 return;
746 }
747748
748 // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the749 // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the
749 // Zig source code.750 // Zig source code.
...@@ -2149,10 +2150,8 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {...@@ -2149,10 +2150,8 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
2149 const tracy = trace(@src());2150 const tracy = trace(@src());
2150 defer tracy.end();2151 defer tracy.end();
21512152
2152 if (self.llvm_ir_module) |llvm_ir_module| {2153 if (build_options.have_llvm)
2153 try llvm_ir_module.updateDecl(module, decl);2154 if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.updateDecl(module, decl);
2154 return;
2155 }
21562155
2157 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2156 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2158 defer code_buffer.deinit();2157 defer code_buffer.deinit();