authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2023-12-15 18:39:53+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-08 23:53:24-08:00
logf12ec02bd780f58d8c35b1fe80e0955c2591e0a4
treea2e8d86f140b3e820ebb2fc86412c93325828c5e
parent2f8e4347b1f9c2bf093ac48a636576c22359c1ff

stage2 AArch64: get empty file compiling again


4 files changed, 37 insertions(+), 23 deletions(-)

lib/std/start.zig+1-1
...@@ -105,7 +105,7 @@ fn main2() callconv(.C) c_int {...@@ -105,7 +105,7 @@ fn main2() callconv(.C) c_int {
105 return 0;105 return 0;
106}106}
107107
108fn _start2() noreturn {108fn _start2() callconv(.C) noreturn {
109 callMain2();109 callMain2();
110}110}
111111
src/arch/aarch64/Emit.zig+34-20
...@@ -438,39 +438,50 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -438,39 +438,50 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
438 return error.EmitFail;438 return error.EmitFail;
439}439}
440440
441fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {441fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) InnerError!void {
442 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(self.prev_di_line));442 const delta_line = @as(i33, line) - @as(i33, emit.prev_di_line);
443 const delta_pc: usize = self.code.items.len - self.prev_di_pc;443 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
444 switch (self.debug_output) {444 log.debug(" (advance pc={d} and line={d})", .{ delta_pc, delta_line });
445 switch (emit.debug_output) {
445 .dwarf => |dw| {446 .dwarf => |dw| {
447 if (column != emit.prev_di_column) try dw.setColumn(column);
446 try dw.advancePCAndLine(delta_line, delta_pc);448 try dw.advancePCAndLine(delta_line, delta_pc);
447 self.prev_di_line = line;449 emit.prev_di_line = line;
448 self.prev_di_column = column;450 emit.prev_di_column = column;
449 self.prev_di_pc = self.code.items.len;451 emit.prev_di_pc = emit.code.items.len;
450 },452 },
451 .plan9 => |dbg_out| {453 .plan9 => |dbg_out| {
452 if (delta_pc <= 0) return; // only do this when the pc changes454 if (delta_pc <= 0) return; // only do this when the pc changes
453455
454 // increasing the line number456 // increasing the line number
455 try link.File.Plan9.changeLine(&dbg_out.dbg_line, delta_line);457 try link.File.Plan9.changeLine(&dbg_out.dbg_line, @intCast(delta_line));
456 // increasing the pc458 // increasing the pc
457 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - dbg_out.pc_quanta;459 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - dbg_out.pc_quanta;
458 if (d_pc_p9 > 0) {460 if (d_pc_p9 > 0) {
459 // minus one because if its the last one, we want to leave space to change the line which is one pc quanta461 // minus one because if its the last one, we want to leave space to change the line which is one pc quanta
460 try dbg_out.dbg_line.append(@as(u8, @intCast(@divExact(d_pc_p9, dbg_out.pc_quanta) + 128)) - dbg_out.pc_quanta);462 var diff = @divExact(d_pc_p9, dbg_out.pc_quanta) - dbg_out.pc_quanta;
463 while (diff > 0) {
464 if (diff < 64) {
465 try dbg_out.dbg_line.append(@intCast(diff + 128));
466 diff = 0;
467 } else {
468 try dbg_out.dbg_line.append(@intCast(64 + 128));
469 diff -= 64;
470 }
471 }
461 if (dbg_out.pcop_change_index) |pci|472 if (dbg_out.pcop_change_index) |pci|
462 dbg_out.dbg_line.items[pci] += 1;473 dbg_out.dbg_line.items[pci] += 1;
463 dbg_out.pcop_change_index = @as(u32, @intCast(dbg_out.dbg_line.items.len - 1));474 dbg_out.pcop_change_index = @intCast(dbg_out.dbg_line.items.len - 1);
464 } else if (d_pc_p9 == 0) {475 } else if (d_pc_p9 == 0) {
465 // we don't need to do anything, because adding the pc quanta does it for us476 // we don't need to do anything, because adding the pc quanta does it for us
466 } else unreachable;477 } else unreachable;
467 if (dbg_out.start_line == null)478 if (dbg_out.start_line == null)
468 dbg_out.start_line = self.prev_di_line;479 dbg_out.start_line = emit.prev_di_line;
469 dbg_out.end_line = line;480 dbg_out.end_line = line;
470 // only do this if the pc changed481 // only do this if the pc changed
471 self.prev_di_line = line;482 emit.prev_di_line = line;
472 self.prev_di_column = column;483 emit.prev_di_column = column;
473 self.prev_di_pc = self.code.items.len;484 emit.prev_di_pc = emit.code.items.len;
474 },485 },
475 .none => {},486 .none => {},
476 }487 }
...@@ -638,22 +649,25 @@ fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -638,22 +649,25 @@ fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {
638 }649 }
639}650}
640651
641fn mirDebugPrologueEnd(self: *Emit) !void {652fn mirDebugPrologueEnd(emit: *Emit) !void {
642 switch (self.debug_output) {653 switch (emit.debug_output) {
643 .dwarf => |dw| {654 .dwarf => |dw| {
644 try dw.setPrologueEnd();655 try dw.setPrologueEnd();
645 try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column);656 log.debug("mirDbgPrologueEnd (line={d}, col={d})", .{
657 emit.prev_di_line, emit.prev_di_column,
658 });
659 try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column);
646 },660 },
647 .plan9 => {},661 .plan9 => {},
648 .none => {},662 .none => {},
649 }663 }
650}664}
651665
652fn mirDebugEpilogueBegin(self: *Emit) !void {666fn mirDebugEpilogueBegin(emit: *Emit) !void {
653 switch (self.debug_output) {667 switch (emit.debug_output) {
654 .dwarf => |dw| {668 .dwarf => |dw| {
655 try dw.setEpilogueBegin();669 try dw.setEpilogueBegin();
656 try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column);670 try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column);
657 },671 },
658 .plan9 => {},672 .plan9 => {},
659 .none => {},673 .none => {},
src/arch/x86_64/Emit.zig+1-1
...@@ -309,7 +309,7 @@ fn fixupRelocs(emit: *Emit) Error!void {...@@ -309,7 +309,7 @@ fn fixupRelocs(emit: *Emit) Error!void {
309fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {309fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {
310 const delta_line = @as(i33, line) - @as(i33, emit.prev_di_line);310 const delta_line = @as(i33, line) - @as(i33, emit.prev_di_line);
311 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;311 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
312 log.debug(" (advance pc={d} and line={d})", .{ delta_line, delta_pc });312 log.debug(" (advance pc={d} and line={d})", .{ delta_pc, delta_line });
313 switch (emit.debug_output) {313 switch (emit.debug_output) {
314 .dwarf => |dw| {314 .dwarf => |dw| {
315 if (column != emit.prev_di_column) try dw.setColumn(column);315 if (column != emit.prev_di_column) try dw.setColumn(column);
src/link/Dwarf.zig+1-1
...@@ -1037,7 +1037,7 @@ pub fn init(lf: *File, format: Format) Dwarf {...@@ -1037,7 +1037,7 @@ pub fn init(lf: *File, format: Format) Dwarf {
1037 .format = format,1037 .format = format,
1038 .ptr_width = ptr_width,1038 .ptr_width = ptr_width,
1039 .dbg_line_header = switch (target.cpu.arch) {1039 .dbg_line_header = switch (target.cpu.arch) {
1040 .x86_64 => .{1040 .x86_64, .aarch64 => .{
1041 .minimum_instruction_length = 1,1041 .minimum_instruction_length = 1,
1042 .maximum_operations_per_instruction = 1,1042 .maximum_operations_per_instruction = 1,
1043 .default_is_stmt = true,1043 .default_is_stmt = true,