authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-10-05 10:13:56+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-05 04:48:58-04:00
log7c5a24e08cd0bffd2a5cce6d1fd592a7d2bee678
tree40b072ebb155f4c487f7c01b009a79d034e7df73
parent9952a072cc120f5dc134bb1070ad02dfab59cefa

Turn zig fmt back on in various src/ files


3 files changed, 86 insertions(+), 71 deletions(-)

src/codegen.zig+12-18
...@@ -17,9 +17,6 @@ const DW = std.dwarf;...@@ -17,9 +17,6 @@ const DW = std.dwarf;
17const leb128 = std.debug.leb;17const leb128 = std.debug.leb;
18const log = std.log.scoped(.codegen);18const log = std.log.scoped(.codegen);
1919
20// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
21// zig fmt: off
22
23/// The codegen-related data that is stored in `ir.Inst.Block` instructions.20/// The codegen-related data that is stored in `ir.Inst.Block` instructions.
24pub const BlockData = struct {21pub const BlockData = struct {
25 relocs: std.ArrayListUnmanaged(Reloc) = undefined,22 relocs: std.ArrayListUnmanaged(Reloc) = undefined,
...@@ -170,7 +167,6 @@ pub fn generateSymbol(...@@ -170,7 +167,6 @@ pub fn generateSymbol(
170 },167 },
171 .Pointer => {168 .Pointer => {
172 // TODO populate .debug_info for the pointer169 // TODO populate .debug_info for the pointer
173
174 if (typed_value.val.cast(Value.Payload.DeclRef)) |payload| {170 if (typed_value.val.cast(Value.Payload.DeclRef)) |payload| {
175 const decl = payload.decl;171 const decl = payload.decl;
176 if (decl.analysis != .complete) return error.AnalysisFail;172 if (decl.analysis != .complete) return error.AnalysisFail;
...@@ -206,7 +202,6 @@ pub fn generateSymbol(...@@ -206,7 +202,6 @@ pub fn generateSymbol(
206 },202 },
207 .Int => {203 .Int => {
208 // TODO populate .debug_info for the integer204 // TODO populate .debug_info for the integer
209
210 const info = typed_value.ty.intInfo(bin_file.options.target);205 const info = typed_value.ty.intInfo(bin_file.options.target);
211 if (info.bits == 8 and !info.signed) {206 if (info.bits == 8 and !info.signed) {
212 const x = typed_value.val.toUnsignedInt();207 const x = typed_value.val.toUnsignedInt();
...@@ -399,7 +394,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -399,7 +394,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
399 self.free_registers &= ~(@as(FreeRegInt, 1) << free_index);394 self.free_registers &= ~(@as(FreeRegInt, 1) << free_index);
400 const reg = callee_preserved_regs[free_index];395 const reg = callee_preserved_regs[free_index];
401 self.registers.putAssumeCapacityNoClobber(reg, inst);396 self.registers.putAssumeCapacityNoClobber(reg, inst);
402 log.debug("alloc {} => {*}", .{reg, inst});397 log.debug("alloc {} => {*}", .{ reg, inst });
403 return reg;398 return reg;
404 }399 }
405400
...@@ -439,7 +434,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -439,7 +434,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
439 }434 }
440 try branch_stack.append(.{});435 try branch_stack.append(.{});
441436
442 const src_data: struct {lbrace_src: usize, rbrace_src: usize, source: []const u8} = blk: {437 const src_data: struct { lbrace_src: usize, rbrace_src: usize, source: []const u8 } = blk: {
443 if (module_fn.owner_decl.scope.cast(Module.Scope.Container)) |container_scope| {438 if (module_fn.owner_decl.scope.cast(Module.Scope.Container)) |container_scope| {
444 const tree = container_scope.file_scope.contents.tree;439 const tree = container_scope.file_scope.contents.tree;
445 const fn_proto = tree.root_node.decls()[module_fn.owner_decl.src_index].castTag(.FnProto).?;440 const fn_proto = tree.root_node.decls()[module_fn.owner_decl.src_index].castTag(.FnProto).?;
...@@ -619,7 +614,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -619,7 +614,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
619614
620 const mcv = try self.genFuncInst(inst);615 const mcv = try self.genFuncInst(inst);
621 if (!inst.isUnused()) {616 if (!inst.isUnused()) {
622 log.debug("{*} => {}", .{inst, mcv});617 log.debug("{*} => {}", .{ inst, mcv });
623 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];618 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
624 try branch.inst_table.putNoClobber(self.gpa, inst, mcv);619 try branch.inst_table.putNoClobber(self.gpa, inst, mcv);
625 }620 }
...@@ -884,7 +879,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -884,7 +879,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
884 // No side effects, so if it's unreferenced, do nothing.879 // No side effects, so if it's unreferenced, do nothing.
885 if (inst.base.isUnused())880 if (inst.base.isUnused())
886 return MCValue.dead;881 return MCValue.dead;
887 882
888 const operand = try self.resolveInst(inst.operand);883 const operand = try self.resolveInst(inst.operand);
889 const info_a = inst.operand.ty.intInfo(self.target.*);884 const info_a = inst.operand.ty.intInfo(self.target.*);
890 const info_b = inst.base.ty.intInfo(self.target.*);885 const info_b = inst.base.ty.intInfo(self.target.*);
...@@ -1005,10 +1000,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1005,10 +1000,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1005 if (self.registers.getEntry(toCanonicalReg(reg))) |entry| {1000 if (self.registers.getEntry(toCanonicalReg(reg))) |entry| {
1006 entry.value = inst;1001 entry.value = inst;
1007 }1002 }
1008 log.debug("reusing {} => {*}", .{reg, inst});1003 log.debug("reusing {} => {*}", .{ reg, inst });
1009 },1004 },
1010 .stack_offset => |off| {1005 .stack_offset => |off| {
1011 log.debug("reusing stack offset {} => {*}", .{off, inst});1006 log.debug("reusing stack offset {} => {*}", .{ off, inst });
1012 return true;1007 return true;
1013 },1008 },
1014 else => return false,1009 else => return false,
...@@ -1307,7 +1302,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1307,7 +1302,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1307 const result = self.args[self.arg_index];1302 const result = self.args[self.arg_index];
1308 self.arg_index += 1;1303 self.arg_index += 1;
13091304
1310 const name_with_null = inst.name[0..mem.lenZ(inst.name) + 1];1305 const name_with_null = inst.name[0 .. mem.lenZ(inst.name) + 1];
1311 switch (result) {1306 switch (result) {
1312 .register => |reg| {1307 .register => |reg| {
1313 self.registers.putAssumeCapacityNoClobber(toCanonicalReg(reg), &inst.base);1308 self.registers.putAssumeCapacityNoClobber(toCanonicalReg(reg), &inst.base);
...@@ -1779,7 +1774,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1779,7 +1774,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1779 self.code.items.len += 4;1774 self.code.items.len += 4;
1780 break :reloc reloc;1775 break :reloc reloc;
1781 },1776 },
1782 else => return self.fail(inst.base.src, "TODO implement condbr {}", .{ self.target.cpu.arch }),1777 else => return self.fail(inst.base.src, "TODO implement condbr {}", .{self.target.cpu.arch}),
1783 };1778 };
17841779
1785 // Capture the state of register and stack allocation state so that we can revert to it.1780 // Capture the state of register and stack allocation state so that we can revert to it.
...@@ -1859,7 +1854,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1859,7 +1854,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1859 }1854 }
1860 }1855 }
1861 };1856 };
1862 log.debug("consolidating else_entry {*} {}=>{}", .{else_entry.key, else_entry.value, canon_mcv});1857 log.debug("consolidating else_entry {*} {}=>{}", .{ else_entry.key, else_entry.value, canon_mcv });
1863 // TODO make sure the destination stack offset / register does not already have something1858 // TODO make sure the destination stack offset / register does not already have something
1864 // going on there.1859 // going on there.
1865 try self.setRegOrMem(inst.base.src, else_entry.key.ty, canon_mcv, else_entry.value);1860 try self.setRegOrMem(inst.base.src, else_entry.key.ty, canon_mcv, else_entry.value);
...@@ -1883,7 +1878,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1883,7 +1878,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1883 }1878 }
1884 }1879 }
1885 };1880 };
1886 log.debug("consolidating then_entry {*} {}=>{}", .{then_entry.key, parent_mcv, then_entry.value});1881 log.debug("consolidating then_entry {*} {}=>{}", .{ then_entry.key, parent_mcv, then_entry.value });
1887 // TODO make sure the destination stack offset / register does not already have something1882 // TODO make sure the destination stack offset / register does not already have something
1888 // going on there.1883 // going on there.
1889 try self.setRegOrMem(inst.base.src, then_entry.key.ty, parent_mcv, then_entry.value);1884 try self.setRegOrMem(inst.base.src, then_entry.key.ty, parent_mcv, then_entry.value);
...@@ -1950,7 +1945,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1950,7 +1945,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1950 // break instruction will choose a MCValue for the block result and overwrite1945 // break instruction will choose a MCValue for the block result and overwrite
1951 // this field. Following break instructions will use that MCValue to put their1946 // this field. Following break instructions will use that MCValue to put their
1952 // block results.1947 // block results.
1953 .mcv = @bitCast(AnyMCValue, MCValue { .none = {} }),1948 .mcv = @bitCast(AnyMCValue, MCValue{ .none = {} }),
1954 };1949 };
1955 defer inst.codegen.relocs.deinit(self.gpa);1950 defer inst.codegen.relocs.deinit(self.gpa);
19561951
...@@ -2232,7 +2227,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2232,7 +2227,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2232 mem.writeIntLittle(u64, &buf, x_big);2227 mem.writeIntLittle(u64, &buf, x_big);
22332228
2234 // mov DWORD PTR [rbp+offset+4], immediate2229 // mov DWORD PTR [rbp+offset+4], immediate
2235 self.code.appendSliceAssumeCapacity(&[_]u8{ 0xc7, 0x45, twos_comp + 4});2230 self.code.appendSliceAssumeCapacity(&[_]u8{ 0xc7, 0x45, twos_comp + 4 });
2236 self.code.appendSliceAssumeCapacity(buf[4..8]);2231 self.code.appendSliceAssumeCapacity(buf[4..8]);
22372232
2238 // mov DWORD PTR [rbp+offset], immediate2233 // mov DWORD PTR [rbp+offset], immediate
...@@ -2288,7 +2283,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2288,7 +2283,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2288 } else if (x <= math.maxInt(u16)) {2283 } else if (x <= math.maxInt(u16)) {
2289 // TODO Use movw Note: Not supported on2284 // TODO Use movw Note: Not supported on
2290 // all ARM targets!2285 // all ARM targets!
2291
2292 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.mov(.al, reg, Instruction.Operand.imm(@truncate(u8, x), 0)).toU32());2286 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.mov(.al, reg, Instruction.Operand.imm(@truncate(u8, x), 0)).toU32());
2293 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.orr(.al, reg, reg, Instruction.Operand.imm(@truncate(u8, x >> 8), 12)).toU32());2287 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.orr(.al, reg, reg, Instruction.Operand.imm(@truncate(u8, x >> 8), 12)).toU32());
2294 } else if (x <= math.maxInt(u32)) {2288 } else if (x <= math.maxInt(u32)) {
src/glibc.zig+18-9
...@@ -689,9 +689,6 @@ pub const BuiltSharedObjects = struct {...@@ -689,9 +689,6 @@ pub const BuiltSharedObjects = struct {
689689
690const all_map_basename = "all.map";690const all_map_basename = "all.map";
691691
692// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
693// zig fmt: off
694
695pub fn buildSharedObjects(comp: *Compilation) !void {692pub fn buildSharedObjects(comp: *Compilation) !void {
696 const tracy = trace(@src());693 const tracy = trace(@src());
697 defer tracy.end();694 defer tracy.end();
...@@ -827,8 +824,9 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -827,8 +824,9 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
827824
828 if (ver.patch == 0) {825 if (ver.patch == 0) {
829 const sym_plus_ver = try std.fmt.allocPrint(826 const sym_plus_ver = try std.fmt.allocPrint(
830 arena, "{s}_{d}_{d}",827 arena,
831 .{sym_name, ver.major, ver.minor},828 "{s}_{d}_{d}",
829 .{ sym_name, ver.major, ver.minor },
832 );830 );
833 try zig_body.writer().print(831 try zig_body.writer().print(
834 \\.globl {s}832 \\.globl {s}
...@@ -840,13 +838,19 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -840,13 +838,19 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
840 , .{838 , .{
841 sym_plus_ver,839 sym_plus_ver,
842 sym_plus_ver,840 sym_plus_ver,
843 sym_plus_ver, sym_name, at_sign_str, ver.major, ver.minor,841 sym_plus_ver,
842 sym_name,
843 at_sign_str,
844 ver.major,
845 ver.minor,
844 sym_plus_ver,846 sym_plus_ver,
845 sym_plus_ver,847 sym_plus_ver,
846 });848 });
847 } else {849 } else {
848 const sym_plus_ver = try std.fmt.allocPrint(arena, "{s}_{d}_{d}_{d}",850 const sym_plus_ver = try std.fmt.allocPrint(
849 .{sym_name, ver.major, ver.minor, ver.patch},851 arena,
852 "{s}_{d}_{d}_{d}",
853 .{ sym_name, ver.major, ver.minor, ver.patch },
850 );854 );
851 try zig_body.writer().print(855 try zig_body.writer().print(
852 \\.globl {s}856 \\.globl {s}
...@@ -858,7 +862,12 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -858,7 +862,12 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
858 , .{862 , .{
859 sym_plus_ver,863 sym_plus_ver,
860 sym_plus_ver,864 sym_plus_ver,
861 sym_plus_ver, sym_name, at_sign_str, ver.major, ver.minor, ver.patch,865 sym_plus_ver,
866 sym_name,
867 at_sign_str,
868 ver.major,
869 ver.minor,
870 ver.patch,
862 sym_plus_ver,871 sym_plus_ver,
863 sym_plus_ver,872 sym_plus_ver,
864 });873 });
src/link/Elf.zig+56-44
...@@ -27,9 +27,6 @@ const Cache = @import("../Cache.zig");...@@ -27,9 +27,6 @@ const Cache = @import("../Cache.zig");
2727
28const default_entry_addr = 0x8000000;28const default_entry_addr = 0x8000000;
2929
30// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
31// zig fmt: off
32
33pub const base_tag: File.Tag = .elf;30pub const base_tag: File.Tag = .elf;
3431
35base: File,32base: File,
...@@ -273,8 +270,8 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio...@@ -273,8 +270,8 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
273270
274pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf {271pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf {
275 const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) {272 const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) {
276 0 ... 32 => .p32,273 0...32 => .p32,
277 33 ... 64 => .p64,274 33...64 => .p64,
278 else => return error.UnsupportedELFArchitecture,275 else => return error.UnsupportedELFArchitecture,
279 };276 };
280 const self = try gpa.create(Elf);277 const self = try gpa.create(Elf);
...@@ -752,40 +749,52 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {...@@ -752,40 +749,52 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
752 // These are LEB encoded but since the values are all less than 127749 // These are LEB encoded but since the values are all less than 127
753 // we can simply append these bytes.750 // we can simply append these bytes.
754 const abbrev_buf = [_]u8{751 const abbrev_buf = [_]u8{
755 abbrev_compile_unit, DW.TAG_compile_unit, DW.CHILDREN_yes, // header752 abbrev_compile_unit, DW.TAG_compile_unit, DW.CHILDREN_yes, // header
756 DW.AT_stmt_list, DW.FORM_sec_offset, DW.AT_low_pc,753 DW.AT_stmt_list, DW.FORM_sec_offset, DW.AT_low_pc,
757 DW.FORM_addr, DW.AT_high_pc, DW.FORM_addr,754 DW.FORM_addr, DW.AT_high_pc, DW.FORM_addr,
758 DW.AT_name, DW.FORM_strp, DW.AT_comp_dir,755 DW.AT_name, DW.FORM_strp, DW.AT_comp_dir,
759 DW.FORM_strp, DW.AT_producer, DW.FORM_strp,756 DW.FORM_strp, DW.AT_producer, DW.FORM_strp,
760 DW.AT_language, DW.FORM_data2, 0,757 DW.AT_language, DW.FORM_data2, 0,
761 0, // table sentinel758 0, // table sentinel
762 abbrev_subprogram, DW.TAG_subprogram,759 abbrev_subprogram,
760 DW.TAG_subprogram,
763 DW.CHILDREN_yes, // header761 DW.CHILDREN_yes, // header
764 DW.AT_low_pc, DW.FORM_addr,762 DW.AT_low_pc,
765 DW.AT_high_pc, DW.FORM_data4, DW.AT_type,763 DW.FORM_addr,
766 DW.FORM_ref4, DW.AT_name, DW.FORM_string,764 DW.AT_high_pc,
767 0, 0, // table sentinel765 DW.FORM_data4,
768 abbrev_subprogram_retvoid,766 DW.AT_type,
769 DW.TAG_subprogram, DW.CHILDREN_yes, // header767 DW.FORM_ref4,
770 DW.AT_low_pc,768 DW.AT_name,
771 DW.FORM_addr, DW.AT_high_pc, DW.FORM_data4,769 DW.FORM_string,
772 DW.AT_name, DW.FORM_string, 0,770 0, 0, // table sentinel
771 abbrev_subprogram_retvoid,
772 DW.TAG_subprogram, DW.CHILDREN_yes, // header
773 DW.AT_low_pc, DW.FORM_addr,
774 DW.AT_high_pc, DW.FORM_data4,
775 DW.AT_name, DW.FORM_string,
776 0,
773 0, // table sentinel777 0, // table sentinel
774 abbrev_base_type, DW.TAG_base_type,778 abbrev_base_type,
779 DW.TAG_base_type,
775 DW.CHILDREN_no, // header780 DW.CHILDREN_no, // header
776 DW.AT_encoding, DW.FORM_data1,781 DW.AT_encoding,
777 DW.AT_byte_size, DW.FORM_data1, DW.AT_name,782 DW.FORM_data1,
778 DW.FORM_string, 0, 0, // table sentinel783 DW.AT_byte_size,
779784 DW.FORM_data1,
780 abbrev_pad1, DW.TAG_unspecified_type, DW.CHILDREN_no, // header785 DW.AT_name,
781 0, 0, // table sentinel786 DW.FORM_string, 0, 0, // table sentinel
782 abbrev_parameter,787 abbrev_pad1, DW.TAG_unspecified_type, DW.CHILDREN_no, // header
788 0, 0, // table sentinel
789 abbrev_parameter,
783 DW.TAG_formal_parameter, DW.CHILDREN_no, // header790 DW.TAG_formal_parameter, DW.CHILDREN_no, // header
784 DW.AT_location,791 DW.AT_location, DW.FORM_exprloc,
785 DW.FORM_exprloc, DW.AT_type, DW.FORM_ref4,792 DW.AT_type, DW.FORM_ref4,
786 DW.AT_name, DW.FORM_string, 0,793 DW.AT_name, DW.FORM_string,
794 0,
787 0, // table sentinel795 0, // table sentinel
788 0, 0,796 0,
797 0,
789 0, // section sentinel798 0, // section sentinel
790 };799 };
791800
...@@ -1021,7 +1030,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {...@@ -1021,7 +1030,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
1021 0, // `DW.LNS_set_prologue_end`1030 0, // `DW.LNS_set_prologue_end`
1022 0, // `DW.LNS_set_epilogue_begin`1031 0, // `DW.LNS_set_epilogue_begin`
1023 1, // `DW.LNS_set_isa`1032 1, // `DW.LNS_set_isa`
1024
1025 0, // include_directories (none except the compilation unit cwd)1033 0, // include_directories (none except the compilation unit cwd)
1026 });1034 });
1027 // file_names[0]1035 // file_names[0]
...@@ -1319,7 +1327,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1319,7 +1327,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13191327
1320 var prev_digest_buf: [digest.len]u8 = undefined;1328 var prev_digest_buf: [digest.len]u8 = undefined;
1321 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {1329 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
1322 log.debug("ELF LLD new_digest={} readlink error: {}", .{digest, @errorName(err)});1330 log.debug("ELF LLD new_digest={} readlink error: {}", .{ digest, @errorName(err) });
1323 // Handle this as a cache miss.1331 // Handle this as a cache miss.
1324 break :blk prev_digest_buf[0..0];1332 break :blk prev_digest_buf[0..0];
1325 };1333 };
...@@ -1329,7 +1337,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1329,7 +1337,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1329 self.base.lock = man.toOwnedLock();1337 self.base.lock = man.toOwnedLock();
1330 return;1338 return;
1331 }1339 }
1332 log.debug("ELF LLD prev_digest={} new_digest={}", .{prev_digest, digest});1340 log.debug("ELF LLD prev_digest={} new_digest={}", .{ prev_digest, digest });
13331341
1334 // We are about to change the output file to be different, so we invalidate the build hash now.1342 // We are about to change the output file to be different, so we invalidate the build hash now.
1335 directory.handle.deleteFile(id_symlink_basename) catch |err| switch (err) {1343 directory.handle.deleteFile(id_symlink_basename) catch |err| switch (err) {
...@@ -1370,7 +1378,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1370,7 +1378,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1370 if (self.base.options.eh_frame_hdr) {1378 if (self.base.options.eh_frame_hdr) {
1371 try argv.append("--eh-frame-hdr");1379 try argv.append("--eh-frame-hdr");
1372 }1380 }
1373 1381
1374 if (self.base.options.emit_relocs) {1382 if (self.base.options.emit_relocs) {
1375 try argv.append("--emit-relocs");1383 try argv.append("--emit-relocs");
1376 }1384 }
...@@ -1491,9 +1499,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1491,9 +1499,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
14911499
1492 if (is_dyn_lib) {1500 if (is_dyn_lib) {
1493 const soname = self.base.options.override_soname orelse if (self.base.options.version) |ver|1501 const soname = self.base.options.override_soname orelse if (self.base.options.version) |ver|
1494 try std.fmt.allocPrint(arena, "lib{}.so.{}", .{self.base.options.root_name, ver.major})1502 try std.fmt.allocPrint(arena, "lib{}.so.{}", .{ self.base.options.root_name, ver.major })
1495 else1503 else
1496 try std.fmt.allocPrint(arena, "lib{}.so", .{self.base.options.root_name});1504 try std.fmt.allocPrint(arena, "lib{}.so", .{self.base.options.root_name});
1497 try argv.append("-soname");1505 try argv.append("-soname");
1498 try argv.append(soname);1506 try argv.append(soname);
14991507
...@@ -1616,7 +1624,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1616,7 +1624,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1616 };1624 };
1617 defer stdout_context.data.deinit();1625 defer stdout_context.data.deinit();
1618 const llvm = @import("../llvm.zig");1626 const llvm = @import("../llvm.zig");
1619 const ok = llvm.Link(.ELF, new_argv.ptr, new_argv.len, append_diagnostic,1627 const ok = llvm.Link(
1628 .ELF,
1629 new_argv.ptr,
1630 new_argv.len,
1631 append_diagnostic,
1620 @ptrToInt(&stdout_context),1632 @ptrToInt(&stdout_context),
1621 @ptrToInt(&stderr_context),1633 @ptrToInt(&stderr_context),
1622 );1634 );
...@@ -1642,7 +1654,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1642,7 +1654,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1642 };1654 };
1643 // Again failure here only means an unnecessary cache miss.1655 // Again failure here only means an unnecessary cache miss.
1644 man.writeManifest() catch |err| {1656 man.writeManifest() catch |err| {
1645 std.log.warn("failed to write cache manifest when linking: {}", .{ @errorName(err) });1657 std.log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});
1646 };1658 };
1647 // We hang on to this lock so that the output file path can be used without1659 // We hang on to this lock so that the output file path can be used without
1648 // other processes clobbering it.1660 // other processes clobbering it.
...@@ -2877,8 +2889,8 @@ fn dbgLineNeededHeaderBytes(self: Elf) u32 {...@@ -2877,8 +2889,8 @@ fn dbgLineNeededHeaderBytes(self: Elf) u32 {
2877 const root_src_dir_path_len = if (self.base.options.module.?.root_pkg.root_src_directory.path) |p| p.len else 1; // "."2889 const root_src_dir_path_len = if (self.base.options.module.?.root_pkg.root_src_directory.path) |p| p.len else 1; // "."
2878 return @intCast(u32, 53 + directory_entry_format_count * 2 + file_name_entry_format_count * 2 +2890 return @intCast(u32, 53 + directory_entry_format_count * 2 + file_name_entry_format_count * 2 +
2879 directory_count * 8 + file_name_count * 8 +2891 directory_count * 8 + file_name_count * 8 +
2880 // These are encoded as DW.FORM_string rather than DW.FORM_strp as we would like2892 // These are encoded as DW.FORM_string rather than DW.FORM_strp as we would like
2881 // because of a workaround for readelf and gdb failing to understand DWARFv5 correctly.2893 // because of a workaround for readelf and gdb failing to understand DWARFv5 correctly.
2882 root_src_dir_path_len +2894 root_src_dir_path_len +
2883 self.base.options.module.?.root_pkg.root_src_path.len);2895 self.base.options.module.?.root_pkg.root_src_path.len);
2884}2896}