| author | |
| committer | |
| log | b3ecdb21eedeb8be099cf1ef43ceff68592593ed |
| tree | f5fb9a8412cf2b652e5d501c201064fdb219a7b5 |
| parent | bf20a4aa9eeca3c1911709bf48a8c476106042dc |
17 files changed, 135 insertions(+), 131 deletions(-)
src/arch/aarch64/CodeGen.zig+1-1| ... | @@ -323,7 +323,7 @@ pub fn generate( | ... | @@ -323,7 +323,7 @@ pub fn generate( |
| 323 | func_index: InternPool.Index, | 323 | func_index: InternPool.Index, |
| 324 | air: Air, | 324 | air: Air, |
| 325 | liveness: Liveness, | 325 | liveness: Liveness, |
| 326 | code: *std.ArrayList(u8), | 326 | code: *std.ArrayListUnmanaged(u8), |
| 327 | debug_output: link.File.DebugInfoOutput, | 327 | debug_output: link.File.DebugInfoOutput, |
| 328 | ) CodeGenError!void { | 328 | ) CodeGenError!void { |
| 329 | const zcu = pt.zcu; | 329 | const zcu = pt.zcu; |
src/arch/aarch64/Emit.zig+4-2| ... | @@ -20,7 +20,7 @@ debug_output: link.File.DebugInfoOutput, | ... | @@ -20,7 +20,7 @@ debug_output: link.File.DebugInfoOutput, |
| 20 | target: *const std.Target, | 20 | target: *const std.Target, |
| 21 | err_msg: ?*ErrorMsg = null, | 21 | err_msg: ?*ErrorMsg = null, |
| 22 | src_loc: Zcu.LazySrcLoc, | 22 | src_loc: Zcu.LazySrcLoc, |
| 23 | code: *std.ArrayList(u8), | 23 | code: *std.ArrayListUnmanaged(u8), |
| 24 | 24 | ||
| 25 | prev_di_line: u32, | 25 | prev_di_line: u32, |
| 26 | prev_di_column: u32, | 26 | prev_di_column: u32, |
| ... | @@ -424,8 +424,10 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -424,8 +424,10 @@ fn lowerBranches(emit: *Emit) !void { |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | 426 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 427 | const comp = emit.bin_file.comp; | ||
| 428 | const gpa = comp.gpa; | ||
| 427 | const endian = emit.target.cpu.arch.endian(); | 429 | const endian = emit.target.cpu.arch.endian(); |
| 428 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | 430 | std.mem.writeInt(u32, try emit.code.addManyAsArray(gpa, 4), instruction.toU32(), endian); |
| 429 | } | 431 | } |
| 430 | 432 | ||
| 431 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 433 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
src/arch/arm/CodeGen.zig+1-1| ... | @@ -332,7 +332,7 @@ pub fn generate( | ... | @@ -332,7 +332,7 @@ pub fn generate( |
| 332 | func_index: InternPool.Index, | 332 | func_index: InternPool.Index, |
| 333 | air: Air, | 333 | air: Air, |
| 334 | liveness: Liveness, | 334 | liveness: Liveness, |
| 335 | code: *std.ArrayList(u8), | 335 | code: *std.ArrayListUnmanaged(u8), |
| 336 | debug_output: link.File.DebugInfoOutput, | 336 | debug_output: link.File.DebugInfoOutput, |
| 337 | ) CodeGenError!void { | 337 | ) CodeGenError!void { |
| 338 | const zcu = pt.zcu; | 338 | const zcu = pt.zcu; |
src/arch/arm/Emit.zig+4-2| ... | @@ -24,7 +24,7 @@ debug_output: link.File.DebugInfoOutput, | ... | @@ -24,7 +24,7 @@ debug_output: link.File.DebugInfoOutput, |
| 24 | target: *const std.Target, | 24 | target: *const std.Target, |
| 25 | err_msg: ?*ErrorMsg = null, | 25 | err_msg: ?*ErrorMsg = null, |
| 26 | src_loc: Zcu.LazySrcLoc, | 26 | src_loc: Zcu.LazySrcLoc, |
| 27 | code: *std.ArrayList(u8), | 27 | code: *std.ArrayListUnmanaged(u8), |
| 28 | 28 | ||
| 29 | prev_di_line: u32, | 29 | prev_di_line: u32, |
| 30 | prev_di_column: u32, | 30 | prev_di_column: u32, |
| ... | @@ -342,8 +342,10 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -342,8 +342,10 @@ fn lowerBranches(emit: *Emit) !void { |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | 344 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 345 | const comp = emit.bin_file.comp; | ||
| 346 | const gpa = comp.gpa; | ||
| 345 | const endian = emit.target.cpu.arch.endian(); | 347 | const endian = emit.target.cpu.arch.endian(); |
| 346 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | 348 | std.mem.writeInt(u32, try emit.code.addManyAsArray(gpa, 4), instruction.toU32(), endian); |
| 347 | } | 349 | } |
| 348 | 350 | ||
| 349 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 351 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
src/arch/riscv64/CodeGen.zig+2-2| ... | @@ -757,7 +757,7 @@ pub fn generate( | ... | @@ -757,7 +757,7 @@ pub fn generate( |
| 757 | func_index: InternPool.Index, | 757 | func_index: InternPool.Index, |
| 758 | air: Air, | 758 | air: Air, |
| 759 | liveness: Liveness, | 759 | liveness: Liveness, |
| 760 | code: *std.ArrayList(u8), | 760 | code: *std.ArrayListUnmanaged(u8), |
| 761 | debug_output: link.File.DebugInfoOutput, | 761 | debug_output: link.File.DebugInfoOutput, |
| 762 | ) CodeGenError!void { | 762 | ) CodeGenError!void { |
| 763 | const zcu = pt.zcu; | 763 | const zcu = pt.zcu; |
| ... | @@ -898,7 +898,7 @@ pub fn generateLazy( | ... | @@ -898,7 +898,7 @@ pub fn generateLazy( |
| 898 | pt: Zcu.PerThread, | 898 | pt: Zcu.PerThread, |
| 899 | src_loc: Zcu.LazySrcLoc, | 899 | src_loc: Zcu.LazySrcLoc, |
| 900 | lazy_sym: link.File.LazySymbol, | 900 | lazy_sym: link.File.LazySymbol, |
| 901 | code: *std.ArrayList(u8), | 901 | code: *std.ArrayListUnmanaged(u8), |
| 902 | debug_output: link.File.DebugInfoOutput, | 902 | debug_output: link.File.DebugInfoOutput, |
| 903 | ) CodeGenError!void { | 903 | ) CodeGenError!void { |
| 904 | const comp = bin_file.comp; | 904 | const comp = bin_file.comp; |
src/arch/riscv64/Emit.zig+9-8| ... | @@ -3,7 +3,7 @@ | ... | @@ -3,7 +3,7 @@ |
| 3 | bin_file: *link.File, | 3 | bin_file: *link.File, |
| 4 | lower: Lower, | 4 | lower: Lower, |
| 5 | debug_output: link.File.DebugInfoOutput, | 5 | debug_output: link.File.DebugInfoOutput, |
| 6 | code: *std.ArrayList(u8), | 6 | code: *std.ArrayListUnmanaged(u8), |
| 7 | 7 | ||
| 8 | prev_di_line: u32, | 8 | prev_di_line: u32, |
| 9 | prev_di_column: u32, | 9 | prev_di_column: u32, |
| ... | @@ -18,6 +18,7 @@ pub const Error = Lower.Error || error{ | ... | @@ -18,6 +18,7 @@ pub const Error = Lower.Error || error{ |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | pub fn emitMir(emit: *Emit) Error!void { | 20 | pub fn emitMir(emit: *Emit) Error!void { |
| 21 | const gpa = emit.bin_file.comp.gpa; | ||
| 21 | log.debug("mir instruction len: {}", .{emit.lower.mir.instructions.len}); | 22 | log.debug("mir instruction len: {}", .{emit.lower.mir.instructions.len}); |
| 22 | for (0..emit.lower.mir.instructions.len) |mir_i| { | 23 | for (0..emit.lower.mir.instructions.len) |mir_i| { |
| 23 | const mir_index: Mir.Inst.Index = @intCast(mir_i); | 24 | const mir_index: Mir.Inst.Index = @intCast(mir_i); |
| ... | @@ -30,7 +31,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -30,7 +31,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 30 | var lowered_relocs = lowered.relocs; | 31 | var lowered_relocs = lowered.relocs; |
| 31 | for (lowered.insts, 0..) |lowered_inst, lowered_index| { | 32 | for (lowered.insts, 0..) |lowered_inst, lowered_index| { |
| 32 | const start_offset: u32 = @intCast(emit.code.items.len); | 33 | const start_offset: u32 = @intCast(emit.code.items.len); |
| 33 | try lowered_inst.encode(emit.code.writer()); | 34 | try lowered_inst.encode(emit.code.writer(gpa)); |
| 34 | 35 | ||
| 35 | while (lowered_relocs.len > 0 and | 36 | while (lowered_relocs.len > 0 and |
| 36 | lowered_relocs[0].lowered_inst_index == lowered_index) : ({ | 37 | lowered_relocs[0].lowered_inst_index == lowered_index) : ({ |
| ... | @@ -56,13 +57,13 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -56,13 +57,13 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 56 | const hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20); | 57 | const hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20); |
| 57 | const lo_r_type: u32 = @intFromEnum(std.elf.R_RISCV.LO12_I); | 58 | const lo_r_type: u32 = @intFromEnum(std.elf.R_RISCV.LO12_I); |
| 58 | 59 | ||
| 59 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 60 | try atom_ptr.addReloc(gpa, .{ |
| 60 | .r_offset = start_offset, | 61 | .r_offset = start_offset, |
| 61 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | hi_r_type, | 62 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | hi_r_type, |
| 62 | .r_addend = 0, | 63 | .r_addend = 0, |
| 63 | }, zo); | 64 | }, zo); |
| 64 | 65 | ||
| 65 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 66 | try atom_ptr.addReloc(gpa, .{ |
| 66 | .r_offset = start_offset + 4, | 67 | .r_offset = start_offset + 4, |
| 67 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | lo_r_type, | 68 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | lo_r_type, |
| 68 | .r_addend = 0, | 69 | .r_addend = 0, |
| ... | @@ -76,19 +77,19 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -76,19 +77,19 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 76 | 77 | ||
| 77 | const R_RISCV = std.elf.R_RISCV; | 78 | const R_RISCV = std.elf.R_RISCV; |
| 78 | 79 | ||
| 79 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 80 | try atom_ptr.addReloc(gpa, .{ |
| 80 | .r_offset = start_offset, | 81 | .r_offset = start_offset, |
| 81 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_HI20), | 82 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_HI20), |
| 82 | .r_addend = 0, | 83 | .r_addend = 0, |
| 83 | }, zo); | 84 | }, zo); |
| 84 | 85 | ||
| 85 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 86 | try atom_ptr.addReloc(gpa, .{ |
| 86 | .r_offset = start_offset + 4, | 87 | .r_offset = start_offset + 4, |
| 87 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_ADD), | 88 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_ADD), |
| 88 | .r_addend = 0, | 89 | .r_addend = 0, |
| 89 | }, zo); | 90 | }, zo); |
| 90 | 91 | ||
| 91 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 92 | try atom_ptr.addReloc(gpa, .{ |
| 92 | .r_offset = start_offset + 8, | 93 | .r_offset = start_offset + 8, |
| 93 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_LO12_I), | 94 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_LO12_I), |
| 94 | .r_addend = 0, | 95 | .r_addend = 0, |
| ... | @@ -101,7 +102,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -101,7 +102,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 101 | 102 | ||
| 102 | const r_type: u32 = @intFromEnum(std.elf.R_RISCV.CALL_PLT); | 103 | const r_type: u32 = @intFromEnum(std.elf.R_RISCV.CALL_PLT); |
| 103 | 104 | ||
| 104 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 105 | try atom_ptr.addReloc(gpa, .{ |
| 105 | .r_offset = start_offset, | 106 | .r_offset = start_offset, |
| 106 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | r_type, | 107 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | r_type, |
| 107 | .r_addend = 0, | 108 | .r_addend = 0, |
src/arch/sparc64/CodeGen.zig+4-4| ... | @@ -54,7 +54,7 @@ liveness: Liveness, | ... | @@ -54,7 +54,7 @@ liveness: Liveness, |
| 54 | bin_file: *link.File, | 54 | bin_file: *link.File, |
| 55 | target: *const std.Target, | 55 | target: *const std.Target, |
| 56 | func_index: InternPool.Index, | 56 | func_index: InternPool.Index, |
| 57 | code: *std.ArrayList(u8), | 57 | code: *std.ArrayListUnmanaged(u8), |
| 58 | debug_output: link.File.DebugInfoOutput, | 58 | debug_output: link.File.DebugInfoOutput, |
| 59 | err_msg: ?*ErrorMsg, | 59 | err_msg: ?*ErrorMsg, |
| 60 | args: []MCValue, | 60 | args: []MCValue, |
| ... | @@ -265,7 +265,7 @@ pub fn generate( | ... | @@ -265,7 +265,7 @@ pub fn generate( |
| 265 | func_index: InternPool.Index, | 265 | func_index: InternPool.Index, |
| 266 | air: Air, | 266 | air: Air, |
| 267 | liveness: Liveness, | 267 | liveness: Liveness, |
| 268 | code: *std.ArrayList(u8), | 268 | code: *std.ArrayListUnmanaged(u8), |
| 269 | debug_output: link.File.DebugInfoOutput, | 269 | debug_output: link.File.DebugInfoOutput, |
| 270 | ) CodeGenError!void { | 270 | ) CodeGenError!void { |
| 271 | const zcu = pt.zcu; | 271 | const zcu = pt.zcu; |
| ... | @@ -283,7 +283,7 @@ pub fn generate( | ... | @@ -283,7 +283,7 @@ pub fn generate( |
| 283 | } | 283 | } |
| 284 | try branch_stack.append(.{}); | 284 | try branch_stack.append(.{}); |
| 285 | 285 | ||
| 286 | var function = Self{ | 286 | var function: Self = .{ |
| 287 | .gpa = gpa, | 287 | .gpa = gpa, |
| 288 | .pt = pt, | 288 | .pt = pt, |
| 289 | .air = air, | 289 | .air = air, |
| ... | @@ -331,7 +331,7 @@ pub fn generate( | ... | @@ -331,7 +331,7 @@ pub fn generate( |
| 331 | }; | 331 | }; |
| 332 | defer mir.deinit(gpa); | 332 | defer mir.deinit(gpa); |
| 333 | 333 | ||
| 334 | var emit = Emit{ | 334 | var emit: Emit = .{ |
| 335 | .mir = mir, | 335 | .mir = mir, |
| 336 | .bin_file = lf, | 336 | .bin_file = lf, |
| 337 | .debug_output = debug_output, | 337 | .debug_output = debug_output, |
src/arch/sparc64/Emit.zig+6-3| ... | @@ -22,7 +22,7 @@ debug_output: link.File.DebugInfoOutput, | ... | @@ -22,7 +22,7 @@ debug_output: link.File.DebugInfoOutput, |
| 22 | target: *const std.Target, | 22 | target: *const std.Target, |
| 23 | err_msg: ?*ErrorMsg = null, | 23 | err_msg: ?*ErrorMsg = null, |
| 24 | src_loc: Zcu.LazySrcLoc, | 24 | src_loc: Zcu.LazySrcLoc, |
| 25 | code: *std.ArrayList(u8), | 25 | code: *std.ArrayListUnmanaged(u8), |
| 26 | 26 | ||
| 27 | prev_di_line: u32, | 27 | prev_di_line: u32, |
| 28 | prev_di_column: u32, | 28 | prev_di_column: u32, |
| ... | @@ -678,10 +678,13 @@ fn optimalBranchType(emit: *Emit, tag: Mir.Inst.Tag, offset: i64) !BranchType { | ... | @@ -678,10 +678,13 @@ fn optimalBranchType(emit: *Emit, tag: Mir.Inst.Tag, offset: i64) !BranchType { |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | 680 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 681 | const comp = emit.bin_file.comp; | ||
| 682 | const gpa = comp.gpa; | ||
| 683 | |||
| 681 | // SPARCv9 instructions are always arranged in BE regardless of the | 684 | // SPARCv9 instructions are always arranged in BE regardless of the |
| 682 | // endianness mode the CPU is running in (Section 3.1 of the ISA specification). | 685 | // endianness mode the CPU is running in (Section 3.1 of the ISA specification). |
| 683 | // This is to ease porting in case someone wants to do a LE SPARCv9 backend. | 686 | // This is to ease porting in case someone wants to do a LE SPARCv9 backend. |
| 684 | const endian = Endian.big; | 687 | const endian: Endian = .big; |
| 685 | 688 | ||
| 686 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | 689 | std.mem.writeInt(u32, try emit.code.addManyAsArray(gpa, 4), instruction.toU32(), endian); |
| 687 | } | 690 | } |
src/arch/x86_64/CodeGen.zig+2-2| ... | @@ -817,7 +817,7 @@ pub fn generate( | ... | @@ -817,7 +817,7 @@ pub fn generate( |
| 817 | func_index: InternPool.Index, | 817 | func_index: InternPool.Index, |
| 818 | air: Air, | 818 | air: Air, |
| 819 | liveness: Liveness, | 819 | liveness: Liveness, |
| 820 | code: *std.ArrayList(u8), | 820 | code: *std.ArrayListUnmanaged(u8), |
| 821 | debug_output: link.File.DebugInfoOutput, | 821 | debug_output: link.File.DebugInfoOutput, |
| 822 | ) CodeGenError!void { | 822 | ) CodeGenError!void { |
| 823 | const zcu = pt.zcu; | 823 | const zcu = pt.zcu; |
| ... | @@ -970,7 +970,7 @@ pub fn generateLazy( | ... | @@ -970,7 +970,7 @@ pub fn generateLazy( |
| 970 | pt: Zcu.PerThread, | 970 | pt: Zcu.PerThread, |
| 971 | src_loc: Zcu.LazySrcLoc, | 971 | src_loc: Zcu.LazySrcLoc, |
| 972 | lazy_sym: link.File.LazySymbol, | 972 | lazy_sym: link.File.LazySymbol, |
| 973 | code: *std.ArrayList(u8), | 973 | code: *std.ArrayListUnmanaged(u8), |
| 974 | debug_output: link.File.DebugInfoOutput, | 974 | debug_output: link.File.DebugInfoOutput, |
| 975 | ) CodeGenError!void { | 975 | ) CodeGenError!void { |
| 976 | const comp = bin_file.comp; | 976 | const comp = bin_file.comp; |
src/arch/x86_64/Emit.zig+8-7| ... | @@ -4,7 +4,7 @@ air: Air, | ... | @@ -4,7 +4,7 @@ air: Air, |
| 4 | lower: Lower, | 4 | lower: Lower, |
| 5 | atom_index: u32, | 5 | atom_index: u32, |
| 6 | debug_output: link.File.DebugInfoOutput, | 6 | debug_output: link.File.DebugInfoOutput, |
| 7 | code: *std.ArrayList(u8), | 7 | code: *std.ArrayListUnmanaged(u8), |
| 8 | 8 | ||
| 9 | prev_di_loc: Loc, | 9 | prev_di_loc: Loc, |
| 10 | /// Relative to the beginning of `code`. | 10 | /// Relative to the beginning of `code`. |
| ... | @@ -18,6 +18,7 @@ pub const Error = Lower.Error || error{ | ... | @@ -18,6 +18,7 @@ pub const Error = Lower.Error || error{ |
| 18 | } || link.File.UpdateDebugInfoError; | 18 | } || link.File.UpdateDebugInfoError; |
| 19 | 19 | ||
| 20 | pub fn emitMir(emit: *Emit) Error!void { | 20 | pub fn emitMir(emit: *Emit) Error!void { |
| 21 | const gpa = emit.lower.bin_file.comp.gpa; | ||
| 21 | for (0..emit.lower.mir.instructions.len) |mir_i| { | 22 | for (0..emit.lower.mir.instructions.len) |mir_i| { |
| 22 | const mir_index: Mir.Inst.Index = @intCast(mir_i); | 23 | const mir_index: Mir.Inst.Index = @intCast(mir_i); |
| 23 | try emit.code_offset_mapping.putNoClobber( | 24 | try emit.code_offset_mapping.putNoClobber( |
| ... | @@ -82,7 +83,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -82,7 +83,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 82 | } | 83 | } |
| 83 | continue; | 84 | continue; |
| 84 | } | 85 | } |
| 85 | try lowered_inst.encode(emit.code.writer(), .{}); | 86 | try lowered_inst.encode(emit.code.writer(gpa), .{}); |
| 86 | const end_offset: u32 = @intCast(emit.code.items.len); | 87 | const end_offset: u32 = @intCast(emit.code.items.len); |
| 87 | while (lowered_relocs.len > 0 and | 88 | while (lowered_relocs.len > 0 and |
| 88 | lowered_relocs[0].lowered_inst_index == lowered_index) : ({ | 89 | lowered_relocs[0].lowered_inst_index == lowered_index) : ({ |
| ... | @@ -100,7 +101,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -100,7 +101,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 100 | const zo = elf_file.zigObjectPtr().?; | 101 | const zo = elf_file.zigObjectPtr().?; |
| 101 | const atom_ptr = zo.symbol(emit.atom_index).atom(elf_file).?; | 102 | const atom_ptr = zo.symbol(emit.atom_index).atom(elf_file).?; |
| 102 | const r_type = @intFromEnum(std.elf.R_X86_64.PLT32); | 103 | const r_type = @intFromEnum(std.elf.R_X86_64.PLT32); |
| 103 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | 104 | try atom_ptr.addReloc(gpa, .{ |
| 104 | .r_offset = end_offset - 4, | 105 | .r_offset = end_offset - 4, |
| 105 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | 106 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 106 | .r_addend = lowered_relocs[0].off - 4, | 107 | .r_addend = lowered_relocs[0].off - 4, |
| ... | @@ -147,7 +148,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -147,7 +148,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 147 | const zo = elf_file.zigObjectPtr().?; | 148 | const zo = elf_file.zigObjectPtr().?; |
| 148 | const atom = zo.symbol(emit.atom_index).atom(elf_file).?; | 149 | const atom = zo.symbol(emit.atom_index).atom(elf_file).?; |
| 149 | const r_type = @intFromEnum(std.elf.R_X86_64.TLSLD); | 150 | const r_type = @intFromEnum(std.elf.R_X86_64.TLSLD); |
| 150 | try atom.addReloc(elf_file.base.comp.gpa, .{ | 151 | try atom.addReloc(gpa, .{ |
| 151 | .r_offset = end_offset - 4, | 152 | .r_offset = end_offset - 4, |
| 152 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | 153 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 153 | .r_addend = lowered_relocs[0].off - 4, | 154 | .r_addend = lowered_relocs[0].off - 4, |
| ... | @@ -158,7 +159,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -158,7 +159,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 158 | const zo = elf_file.zigObjectPtr().?; | 159 | const zo = elf_file.zigObjectPtr().?; |
| 159 | const atom = zo.symbol(emit.atom_index).atom(elf_file).?; | 160 | const atom = zo.symbol(emit.atom_index).atom(elf_file).?; |
| 160 | const r_type = @intFromEnum(std.elf.R_X86_64.DTPOFF32); | 161 | const r_type = @intFromEnum(std.elf.R_X86_64.DTPOFF32); |
| 161 | try atom.addReloc(elf_file.base.comp.gpa, .{ | 162 | try atom.addReloc(gpa, .{ |
| 162 | .r_offset = end_offset - 4, | 163 | .r_offset = end_offset - 4, |
| 163 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | 164 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 164 | .r_addend = lowered_relocs[0].off, | 165 | .r_addend = lowered_relocs[0].off, |
| ... | @@ -173,7 +174,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -173,7 +174,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 173 | @intFromEnum(std.elf.R_X86_64.GOTPCREL) | 174 | @intFromEnum(std.elf.R_X86_64.GOTPCREL) |
| 174 | else | 175 | else |
| 175 | @intFromEnum(std.elf.R_X86_64.PC32); | 176 | @intFromEnum(std.elf.R_X86_64.PC32); |
| 176 | try atom.addReloc(elf_file.base.comp.gpa, .{ | 177 | try atom.addReloc(gpa, .{ |
| 177 | .r_offset = end_offset - 4, | 178 | .r_offset = end_offset - 4, |
| 178 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | 179 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 179 | .r_addend = lowered_relocs[0].off - 4, | 180 | .r_addend = lowered_relocs[0].off - 4, |
| ... | @@ -183,7 +184,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -183,7 +184,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 183 | @intFromEnum(std.elf.R_X86_64.TPOFF32) | 184 | @intFromEnum(std.elf.R_X86_64.TPOFF32) |
| 184 | else | 185 | else |
| 185 | @intFromEnum(std.elf.R_X86_64.@"32"); | 186 | @intFromEnum(std.elf.R_X86_64.@"32"); |
| 186 | try atom.addReloc(elf_file.base.comp.gpa, .{ | 187 | try atom.addReloc(gpa, .{ |
| 187 | .r_offset = end_offset - 4, | 188 | .r_offset = end_offset - 4, |
| 188 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | 189 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 189 | .r_addend = lowered_relocs[0].off, | 190 | .r_addend = lowered_relocs[0].off, |
src/codegen.zig+53-51| ... | @@ -55,7 +55,7 @@ pub fn generateFunction( | ... | @@ -55,7 +55,7 @@ pub fn generateFunction( |
| 55 | func_index: InternPool.Index, | 55 | func_index: InternPool.Index, |
| 56 | air: Air, | 56 | air: Air, |
| 57 | liveness: Liveness, | 57 | liveness: Liveness, |
| 58 | code: *std.ArrayList(u8), | 58 | code: *std.ArrayListUnmanaged(u8), |
| 59 | debug_output: link.File.DebugInfoOutput, | 59 | debug_output: link.File.DebugInfoOutput, |
| 60 | ) CodeGenError!void { | 60 | ) CodeGenError!void { |
| 61 | const zcu = pt.zcu; | 61 | const zcu = pt.zcu; |
| ... | @@ -80,7 +80,7 @@ pub fn generateLazyFunction( | ... | @@ -80,7 +80,7 @@ pub fn generateLazyFunction( |
| 80 | pt: Zcu.PerThread, | 80 | pt: Zcu.PerThread, |
| 81 | src_loc: Zcu.LazySrcLoc, | 81 | src_loc: Zcu.LazySrcLoc, |
| 82 | lazy_sym: link.File.LazySymbol, | 82 | lazy_sym: link.File.LazySymbol, |
| 83 | code: *std.ArrayList(u8), | 83 | code: *std.ArrayListUnmanaged(u8), |
| 84 | debug_output: link.File.DebugInfoOutput, | 84 | debug_output: link.File.DebugInfoOutput, |
| 85 | ) CodeGenError!void { | 85 | ) CodeGenError!void { |
| 86 | const zcu = pt.zcu; | 86 | const zcu = pt.zcu; |
| ... | @@ -110,7 +110,7 @@ pub fn generateLazySymbol( | ... | @@ -110,7 +110,7 @@ pub fn generateLazySymbol( |
| 110 | lazy_sym: link.File.LazySymbol, | 110 | lazy_sym: link.File.LazySymbol, |
| 111 | // TODO don't use an "out" parameter like this; put it in the result instead | 111 | // TODO don't use an "out" parameter like this; put it in the result instead |
| 112 | alignment: *Alignment, | 112 | alignment: *Alignment, |
| 113 | code: *std.ArrayList(u8), | 113 | code: *std.ArrayListUnmanaged(u8), |
| 114 | debug_output: link.File.DebugInfoOutput, | 114 | debug_output: link.File.DebugInfoOutput, |
| 115 | reloc_parent: link.File.RelocInfo.Parent, | 115 | reloc_parent: link.File.RelocInfo.Parent, |
| 116 | ) CodeGenError!void { | 116 | ) CodeGenError!void { |
| ... | @@ -120,6 +120,7 @@ pub fn generateLazySymbol( | ... | @@ -120,6 +120,7 @@ pub fn generateLazySymbol( |
| 120 | defer tracy.end(); | 120 | defer tracy.end(); |
| 121 | 121 | ||
| 122 | const comp = bin_file.comp; | 122 | const comp = bin_file.comp; |
| 123 | const gpa = comp.gpa; | ||
| 123 | const zcu = pt.zcu; | 124 | const zcu = pt.zcu; |
| 124 | const ip = &zcu.intern_pool; | 125 | const ip = &zcu.intern_pool; |
| 125 | const target = comp.root_mod.resolved_target.result; | 126 | const target = comp.root_mod.resolved_target.result; |
| ... | @@ -140,7 +141,7 @@ pub fn generateLazySymbol( | ... | @@ -140,7 +141,7 @@ pub fn generateLazySymbol( |
| 140 | const err_names = ip.global_error_set.getNamesFromMainThread(); | 141 | const err_names = ip.global_error_set.getNamesFromMainThread(); |
| 141 | var offset_index: u32 = @intCast(code.items.len); | 142 | var offset_index: u32 = @intCast(code.items.len); |
| 142 | var string_index: u32 = @intCast(4 * (1 + err_names.len + @intFromBool(err_names.len > 0))); | 143 | var string_index: u32 = @intCast(4 * (1 + err_names.len + @intFromBool(err_names.len > 0))); |
| 143 | try code.resize(offset_index + string_index); | 144 | try code.resize(gpa, offset_index + string_index); |
| 144 | mem.writeInt(u32, code.items[offset_index..][0..4], @intCast(err_names.len), endian); | 145 | mem.writeInt(u32, code.items[offset_index..][0..4], @intCast(err_names.len), endian); |
| 145 | if (err_names.len == 0) return .ok; | 146 | if (err_names.len == 0) return .ok; |
| 146 | offset_index += 4; | 147 | offset_index += 4; |
| ... | @@ -148,7 +149,7 @@ pub fn generateLazySymbol( | ... | @@ -148,7 +149,7 @@ pub fn generateLazySymbol( |
| 148 | const err_name = err_name_nts.toSlice(ip); | 149 | const err_name = err_name_nts.toSlice(ip); |
| 149 | mem.writeInt(u32, code.items[offset_index..][0..4], string_index, endian); | 150 | mem.writeInt(u32, code.items[offset_index..][0..4], string_index, endian); |
| 150 | offset_index += 4; | 151 | offset_index += 4; |
| 151 | try code.ensureUnusedCapacity(err_name.len + 1); | 152 | try code.ensureUnusedCapacity(gpa, err_name.len + 1); |
| 152 | code.appendSliceAssumeCapacity(err_name); | 153 | code.appendSliceAssumeCapacity(err_name); |
| 153 | code.appendAssumeCapacity(0); | 154 | code.appendAssumeCapacity(0); |
| 154 | string_index += @intCast(err_name.len + 1); | 155 | string_index += @intCast(err_name.len + 1); |
| ... | @@ -160,7 +161,7 @@ pub fn generateLazySymbol( | ... | @@ -160,7 +161,7 @@ pub fn generateLazySymbol( |
| 160 | const tag_names = enum_ty.enumFields(zcu); | 161 | const tag_names = enum_ty.enumFields(zcu); |
| 161 | for (0..tag_names.len) |tag_index| { | 162 | for (0..tag_names.len) |tag_index| { |
| 162 | const tag_name = tag_names.get(ip)[tag_index].toSlice(ip); | 163 | const tag_name = tag_names.get(ip)[tag_index].toSlice(ip); |
| 163 | try code.ensureUnusedCapacity(tag_name.len + 1); | 164 | try code.ensureUnusedCapacity(gpa, tag_name.len + 1); |
| 164 | code.appendSliceAssumeCapacity(tag_name); | 165 | code.appendSliceAssumeCapacity(tag_name); |
| 165 | code.appendAssumeCapacity(0); | 166 | code.appendAssumeCapacity(0); |
| 166 | } | 167 | } |
| ... | @@ -182,13 +183,14 @@ pub fn generateSymbol( | ... | @@ -182,13 +183,14 @@ pub fn generateSymbol( |
| 182 | pt: Zcu.PerThread, | 183 | pt: Zcu.PerThread, |
| 183 | src_loc: Zcu.LazySrcLoc, | 184 | src_loc: Zcu.LazySrcLoc, |
| 184 | val: Value, | 185 | val: Value, |
| 185 | code: *std.ArrayList(u8), | 186 | code: *std.ArrayListUnmanaged(u8), |
| 186 | reloc_parent: link.File.RelocInfo.Parent, | 187 | reloc_parent: link.File.RelocInfo.Parent, |
| 187 | ) GenerateSymbolError!void { | 188 | ) GenerateSymbolError!void { |
| 188 | const tracy = trace(@src()); | 189 | const tracy = trace(@src()); |
| 189 | defer tracy.end(); | 190 | defer tracy.end(); |
| 190 | 191 | ||
| 191 | const zcu = pt.zcu; | 192 | const zcu = pt.zcu; |
| 193 | const gpa = zcu.gpa; | ||
| 192 | const ip = &zcu.intern_pool; | 194 | const ip = &zcu.intern_pool; |
| 193 | const ty = val.typeOf(zcu); | 195 | const ty = val.typeOf(zcu); |
| 194 | 196 | ||
| ... | @@ -199,7 +201,7 @@ pub fn generateSymbol( | ... | @@ -199,7 +201,7 @@ pub fn generateSymbol( |
| 199 | 201 | ||
| 200 | if (val.isUndefDeep(zcu)) { | 202 | if (val.isUndefDeep(zcu)) { |
| 201 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; | 203 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 202 | try code.appendNTimes(0xaa, abi_size); | 204 | try code.appendNTimes(gpa, 0xaa, abi_size); |
| 203 | return; | 205 | return; |
| 204 | } | 206 | } |
| 205 | 207 | ||
| ... | @@ -231,7 +233,7 @@ pub fn generateSymbol( | ... | @@ -231,7 +233,7 @@ pub fn generateSymbol( |
| 231 | .@"unreachable", | 233 | .@"unreachable", |
| 232 | .generic_poison, | 234 | .generic_poison, |
| 233 | => unreachable, // non-runtime values | 235 | => unreachable, // non-runtime values |
| 234 | .false, .true => try code.append(switch (simple_value) { | 236 | .false, .true => try code.append(gpa, switch (simple_value) { |
| 235 | .false => 0, | 237 | .false => 0, |
| 236 | .true => 1, | 238 | .true => 1, |
| 237 | else => unreachable, | 239 | else => unreachable, |
| ... | @@ -247,11 +249,11 @@ pub fn generateSymbol( | ... | @@ -247,11 +249,11 @@ pub fn generateSymbol( |
| 247 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; | 249 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 248 | var space: Value.BigIntSpace = undefined; | 250 | var space: Value.BigIntSpace = undefined; |
| 249 | const int_val = val.toBigInt(&space, zcu); | 251 | const int_val = val.toBigInt(&space, zcu); |
| 250 | int_val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian); | 252 | int_val.writeTwosComplement(try code.addManyAsSlice(gpa, abi_size), endian); |
| 251 | }, | 253 | }, |
| 252 | .err => |err| { | 254 | .err => |err| { |
| 253 | const int = try pt.getErrorValue(err.name); | 255 | const int = try pt.getErrorValue(err.name); |
| 254 | try code.writer().writeInt(u16, @intCast(int), endian); | 256 | try code.writer(gpa).writeInt(u16, @intCast(int), endian); |
| 255 | }, | 257 | }, |
| 256 | .error_union => |error_union| { | 258 | .error_union => |error_union| { |
| 257 | const payload_ty = ty.errorUnionPayload(zcu); | 259 | const payload_ty = ty.errorUnionPayload(zcu); |
| ... | @@ -261,7 +263,7 @@ pub fn generateSymbol( | ... | @@ -261,7 +263,7 @@ pub fn generateSymbol( |
| 261 | }; | 263 | }; |
| 262 | 264 | ||
| 263 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 265 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 264 | try code.writer().writeInt(u16, err_val, endian); | 266 | try code.writer(gpa).writeInt(u16, err_val, endian); |
| 265 | return; | 267 | return; |
| 266 | } | 268 | } |
| 267 | 269 | ||
| ... | @@ -271,7 +273,7 @@ pub fn generateSymbol( | ... | @@ -271,7 +273,7 @@ pub fn generateSymbol( |
| 271 | 273 | ||
| 272 | // error value first when its type is larger than the error union's payload | 274 | // error value first when its type is larger than the error union's payload |
| 273 | if (error_align.order(payload_align) == .gt) { | 275 | if (error_align.order(payload_align) == .gt) { |
| 274 | try code.writer().writeInt(u16, err_val, endian); | 276 | try code.writer(gpa).writeInt(u16, err_val, endian); |
| 275 | } | 277 | } |
| 276 | 278 | ||
| 277 | // emit payload part of the error union | 279 | // emit payload part of the error union |
| ... | @@ -286,20 +288,20 @@ pub fn generateSymbol( | ... | @@ -286,20 +288,20 @@ pub fn generateSymbol( |
| 286 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; | 288 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; |
| 287 | 289 | ||
| 288 | if (padding > 0) { | 290 | if (padding > 0) { |
| 289 | try code.appendNTimes(0, padding); | 291 | try code.appendNTimes(gpa, 0, padding); |
| 290 | } | 292 | } |
| 291 | } | 293 | } |
| 292 | 294 | ||
| 293 | // Payload size is larger than error set, so emit our error set last | 295 | // Payload size is larger than error set, so emit our error set last |
| 294 | if (error_align.compare(.lte, payload_align)) { | 296 | if (error_align.compare(.lte, payload_align)) { |
| 295 | const begin = code.items.len; | 297 | const begin = code.items.len; |
| 296 | try code.writer().writeInt(u16, err_val, endian); | 298 | try code.writer(gpa).writeInt(u16, err_val, endian); |
| 297 | const unpadded_end = code.items.len - begin; | 299 | const unpadded_end = code.items.len - begin; |
| 298 | const padded_end = abi_align.forward(unpadded_end); | 300 | const padded_end = abi_align.forward(unpadded_end); |
| 299 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; | 301 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; |
| 300 | 302 | ||
| 301 | if (padding > 0) { | 303 | if (padding > 0) { |
| 302 | try code.appendNTimes(0, padding); | 304 | try code.appendNTimes(gpa, 0, padding); |
| 303 | } | 305 | } |
| 304 | } | 306 | } |
| 305 | }, | 307 | }, |
| ... | @@ -308,15 +310,15 @@ pub fn generateSymbol( | ... | @@ -308,15 +310,15 @@ pub fn generateSymbol( |
| 308 | try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, reloc_parent); | 310 | try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, reloc_parent); |
| 309 | }, | 311 | }, |
| 310 | .float => |float| switch (float.storage) { | 312 | .float => |float| switch (float.storage) { |
| 311 | .f16 => |f16_val| writeFloat(f16, f16_val, target, endian, try code.addManyAsArray(2)), | 313 | .f16 => |f16_val| writeFloat(f16, f16_val, target, endian, try code.addManyAsArray(gpa, 2)), |
| 312 | .f32 => |f32_val| writeFloat(f32, f32_val, target, endian, try code.addManyAsArray(4)), | 314 | .f32 => |f32_val| writeFloat(f32, f32_val, target, endian, try code.addManyAsArray(gpa, 4)), |
| 313 | .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(8)), | 315 | .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(gpa, 8)), |
| 314 | .f80 => |f80_val| { | 316 | .f80 => |f80_val| { |
| 315 | writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(10)); | 317 | writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(gpa, 10)); |
| 316 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; | 318 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 317 | try code.appendNTimes(0, abi_size - 10); | 319 | try code.appendNTimes(gpa, 0, abi_size - 10); |
| 318 | }, | 320 | }, |
| 319 | .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)), | 321 | .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(gpa, 16)), |
| 320 | }, | 322 | }, |
| 321 | .ptr => try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, reloc_parent, 0), | 323 | .ptr => try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, reloc_parent, 0), |
| 322 | .slice => |slice| { | 324 | .slice => |slice| { |
| ... | @@ -332,7 +334,7 @@ pub fn generateSymbol( | ... | @@ -332,7 +334,7 @@ pub fn generateSymbol( |
| 332 | if (payload_val) |value| { | 334 | if (payload_val) |value| { |
| 333 | try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent); | 335 | try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent); |
| 334 | } else { | 336 | } else { |
| 335 | try code.appendNTimes(0, abi_size); | 337 | try code.appendNTimes(gpa, 0, abi_size); |
| 336 | } | 338 | } |
| 337 | } else { | 339 | } else { |
| 338 | const padding = abi_size - (math.cast(usize, payload_type.abiSize(zcu)) orelse return error.Overflow) - 1; | 340 | const padding = abi_size - (math.cast(usize, payload_type.abiSize(zcu)) orelse return error.Overflow) - 1; |
| ... | @@ -342,13 +344,13 @@ pub fn generateSymbol( | ... | @@ -342,13 +344,13 @@ pub fn generateSymbol( |
| 342 | })); | 344 | })); |
| 343 | try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent); | 345 | try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent); |
| 344 | } | 346 | } |
| 345 | try code.writer().writeByte(@intFromBool(payload_val != null)); | 347 | try code.writer(gpa).writeByte(@intFromBool(payload_val != null)); |
| 346 | try code.appendNTimes(0, padding); | 348 | try code.appendNTimes(gpa, 0, padding); |
| 347 | } | 349 | } |
| 348 | }, | 350 | }, |
| 349 | .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) { | 351 | .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) { |
| 350 | .array_type => |array_type| switch (aggregate.storage) { | 352 | .array_type => |array_type| switch (aggregate.storage) { |
| 351 | .bytes => |bytes| try code.appendSlice(bytes.toSlice(array_type.lenIncludingSentinel(), ip)), | 353 | .bytes => |bytes| try code.appendSlice(gpa, bytes.toSlice(array_type.lenIncludingSentinel(), ip)), |
| 352 | .elems, .repeated_elem => { | 354 | .elems, .repeated_elem => { |
| 353 | var index: u64 = 0; | 355 | var index: u64 = 0; |
| 354 | while (index < array_type.lenIncludingSentinel()) : (index += 1) { | 356 | while (index < array_type.lenIncludingSentinel()) : (index += 1) { |
| ... | @@ -366,7 +368,7 @@ pub fn generateSymbol( | ... | @@ -366,7 +368,7 @@ pub fn generateSymbol( |
| 366 | .vector_type => |vector_type| { | 368 | .vector_type => |vector_type| { |
| 367 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; | 369 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 368 | if (vector_type.child == .bool_type) { | 370 | if (vector_type.child == .bool_type) { |
| 369 | const bytes = try code.addManyAsSlice(abi_size); | 371 | const bytes = try code.addManyAsSlice(gpa, abi_size); |
| 370 | @memset(bytes, 0xaa); | 372 | @memset(bytes, 0xaa); |
| 371 | var index: usize = 0; | 373 | var index: usize = 0; |
| 372 | const len = math.cast(usize, vector_type.len) orelse return error.Overflow; | 374 | const len = math.cast(usize, vector_type.len) orelse return error.Overflow; |
| ... | @@ -405,7 +407,7 @@ pub fn generateSymbol( | ... | @@ -405,7 +407,7 @@ pub fn generateSymbol( |
| 405 | } | 407 | } |
| 406 | } else { | 408 | } else { |
| 407 | switch (aggregate.storage) { | 409 | switch (aggregate.storage) { |
| 408 | .bytes => |bytes| try code.appendSlice(bytes.toSlice(vector_type.len, ip)), | 410 | .bytes => |bytes| try code.appendSlice(gpa, bytes.toSlice(vector_type.len, ip)), |
| 409 | .elems, .repeated_elem => { | 411 | .elems, .repeated_elem => { |
| 410 | var index: u64 = 0; | 412 | var index: u64 = 0; |
| 411 | while (index < vector_type.len) : (index += 1) { | 413 | while (index < vector_type.len) : (index += 1) { |
| ... | @@ -423,7 +425,7 @@ pub fn generateSymbol( | ... | @@ -423,7 +425,7 @@ pub fn generateSymbol( |
| 423 | const padding = abi_size - | 425 | const padding = abi_size - |
| 424 | (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse | 426 | (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse |
| 425 | return error.Overflow); | 427 | return error.Overflow); |
| 426 | if (padding > 0) try code.appendNTimes(0, padding); | 428 | if (padding > 0) try code.appendNTimes(gpa, 0, padding); |
| 427 | } | 429 | } |
| 428 | }, | 430 | }, |
| 429 | .tuple_type => |tuple| { | 431 | .tuple_type => |tuple| { |
| ... | @@ -454,7 +456,7 @@ pub fn generateSymbol( | ... | @@ -454,7 +456,7 @@ pub fn generateSymbol( |
| 454 | return error.Overflow; | 456 | return error.Overflow; |
| 455 | 457 | ||
| 456 | if (padding > 0) { | 458 | if (padding > 0) { |
| 457 | try code.appendNTimes(0, padding); | 459 | try code.appendNTimes(gpa, 0, padding); |
| 458 | } | 460 | } |
| 459 | } | 461 | } |
| 460 | }, | 462 | }, |
| ... | @@ -464,7 +466,7 @@ pub fn generateSymbol( | ... | @@ -464,7 +466,7 @@ pub fn generateSymbol( |
| 464 | .@"packed" => { | 466 | .@"packed" => { |
| 465 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; | 467 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 466 | const current_pos = code.items.len; | 468 | const current_pos = code.items.len; |
| 467 | try code.appendNTimes(0, abi_size); | 469 | try code.appendNTimes(gpa, 0, abi_size); |
| 468 | var bits: u16 = 0; | 470 | var bits: u16 = 0; |
| 469 | 471 | ||
| 470 | for (struct_type.field_types.get(ip), 0..) |field_ty, index| { | 472 | for (struct_type.field_types.get(ip), 0..) |field_ty, index| { |
| ... | @@ -482,8 +484,8 @@ pub fn generateSymbol( | ... | @@ -482,8 +484,8 @@ pub fn generateSymbol( |
| 482 | if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .pointer) { | 484 | if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .pointer) { |
| 483 | const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(zcu)) orelse | 485 | const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(zcu)) orelse |
| 484 | return error.Overflow; | 486 | return error.Overflow; |
| 485 | var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size); | 487 | var tmp_list = try std.ArrayListUnmanaged(u8).initCapacity(gpa, field_size); |
| 486 | defer tmp_list.deinit(); | 488 | defer tmp_list.deinit(gpa); |
| 487 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, reloc_parent); | 489 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, reloc_parent); |
| 488 | @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items); | 490 | @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items); |
| 489 | } else { | 491 | } else { |
| ... | @@ -515,7 +517,7 @@ pub fn generateSymbol( | ... | @@ -515,7 +517,7 @@ pub fn generateSymbol( |
| 515 | usize, | 517 | usize, |
| 516 | offsets[field_index] - (code.items.len - struct_begin), | 518 | offsets[field_index] - (code.items.len - struct_begin), |
| 517 | ) orelse return error.Overflow; | 519 | ) orelse return error.Overflow; |
| 518 | if (padding > 0) try code.appendNTimes(0, padding); | 520 | if (padding > 0) try code.appendNTimes(gpa, 0, padding); |
| 519 | 521 | ||
| 520 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent); | 522 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent); |
| 521 | } | 523 | } |
| ... | @@ -528,7 +530,7 @@ pub fn generateSymbol( | ... | @@ -528,7 +530,7 @@ pub fn generateSymbol( |
| 528 | std.mem.alignForward(u64, size, @max(alignment, 1)) - | 530 | std.mem.alignForward(u64, size, @max(alignment, 1)) - |
| 529 | (code.items.len - struct_begin), | 531 | (code.items.len - struct_begin), |
| 530 | ) orelse return error.Overflow; | 532 | ) orelse return error.Overflow; |
| 531 | if (padding > 0) try code.appendNTimes(0, padding); | 533 | if (padding > 0) try code.appendNTimes(gpa, 0, padding); |
| 532 | }, | 534 | }, |
| 533 | } | 535 | } |
| 534 | }, | 536 | }, |
| ... | @@ -551,13 +553,13 @@ pub fn generateSymbol( | ... | @@ -551,13 +553,13 @@ pub fn generateSymbol( |
| 551 | const field_index = ty.unionTagFieldIndex(Value.fromInterned(un.tag), zcu).?; | 553 | const field_index = ty.unionTagFieldIndex(Value.fromInterned(un.tag), zcu).?; |
| 552 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]); | 554 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]); |
| 553 | if (!field_ty.hasRuntimeBits(zcu)) { | 555 | if (!field_ty.hasRuntimeBits(zcu)) { |
| 554 | try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); | 556 | try code.appendNTimes(gpa, 0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); |
| 555 | } else { | 557 | } else { |
| 556 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent); | 558 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent); |
| 557 | 559 | ||
| 558 | const padding = math.cast(usize, layout.payload_size - field_ty.abiSize(zcu)) orelse return error.Overflow; | 560 | const padding = math.cast(usize, layout.payload_size - field_ty.abiSize(zcu)) orelse return error.Overflow; |
| 559 | if (padding > 0) { | 561 | if (padding > 0) { |
| 560 | try code.appendNTimes(0, padding); | 562 | try code.appendNTimes(gpa, 0, padding); |
| 561 | } | 563 | } |
| 562 | } | 564 | } |
| 563 | } else { | 565 | } else { |
| ... | @@ -568,7 +570,7 @@ pub fn generateSymbol( | ... | @@ -568,7 +570,7 @@ pub fn generateSymbol( |
| 568 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent); | 570 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent); |
| 569 | 571 | ||
| 570 | if (layout.padding > 0) { | 572 | if (layout.padding > 0) { |
| 571 | try code.appendNTimes(0, layout.padding); | 573 | try code.appendNTimes(gpa, 0, layout.padding); |
| 572 | } | 574 | } |
| 573 | } | 575 | } |
| 574 | }, | 576 | }, |
| ... | @@ -581,7 +583,7 @@ fn lowerPtr( | ... | @@ -581,7 +583,7 @@ fn lowerPtr( |
| 581 | pt: Zcu.PerThread, | 583 | pt: Zcu.PerThread, |
| 582 | src_loc: Zcu.LazySrcLoc, | 584 | src_loc: Zcu.LazySrcLoc, |
| 583 | ptr_val: InternPool.Index, | 585 | ptr_val: InternPool.Index, |
| 584 | code: *std.ArrayList(u8), | 586 | code: *std.ArrayListUnmanaged(u8), |
| 585 | reloc_parent: link.File.RelocInfo.Parent, | 587 | reloc_parent: link.File.RelocInfo.Parent, |
| 586 | prev_offset: u64, | 588 | prev_offset: u64, |
| 587 | ) GenerateSymbolError!void { | 589 | ) GenerateSymbolError!void { |
| ... | @@ -634,7 +636,7 @@ fn lowerUavRef( | ... | @@ -634,7 +636,7 @@ fn lowerUavRef( |
| 634 | pt: Zcu.PerThread, | 636 | pt: Zcu.PerThread, |
| 635 | src_loc: Zcu.LazySrcLoc, | 637 | src_loc: Zcu.LazySrcLoc, |
| 636 | uav: InternPool.Key.Ptr.BaseAddr.Uav, | 638 | uav: InternPool.Key.Ptr.BaseAddr.Uav, |
| 637 | code: *std.ArrayList(u8), | 639 | code: *std.ArrayListUnmanaged(u8), |
| 638 | reloc_parent: link.File.RelocInfo.Parent, | 640 | reloc_parent: link.File.RelocInfo.Parent, |
| 639 | offset: u64, | 641 | offset: u64, |
| 640 | ) GenerateSymbolError!void { | 642 | ) GenerateSymbolError!void { |
| ... | @@ -649,7 +651,7 @@ fn lowerUavRef( | ... | @@ -649,7 +651,7 @@ fn lowerUavRef( |
| 649 | log.debug("lowerUavRef: ty = {}", .{uav_ty.fmt(pt)}); | 651 | log.debug("lowerUavRef: ty = {}", .{uav_ty.fmt(pt)}); |
| 650 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; | 652 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; |
| 651 | if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) { | 653 | if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) { |
| 652 | try code.appendNTimes(0xaa, ptr_width_bytes); | 654 | try code.appendNTimes(gpa, 0xaa, ptr_width_bytes); |
| 653 | return; | 655 | return; |
| 654 | } | 656 | } |
| 655 | 657 | ||
| ... | @@ -667,7 +669,7 @@ fn lowerUavRef( | ... | @@ -667,7 +669,7 @@ fn lowerUavRef( |
| 667 | .offset = @intCast(code.items.len), | 669 | .offset = @intCast(code.items.len), |
| 668 | .pointee = .{ .uav_index = uav.val }, | 670 | .pointee = .{ .uav_index = uav.val }, |
| 669 | }); | 671 | }); |
| 670 | try code.appendNTimes(0, ptr_width_bytes); | 672 | try code.appendNTimes(gpa, 0, ptr_width_bytes); |
| 671 | return; | 673 | return; |
| 672 | }, | 674 | }, |
| 673 | else => {}, | 675 | else => {}, |
| ... | @@ -686,9 +688,9 @@ fn lowerUavRef( | ... | @@ -686,9 +688,9 @@ fn lowerUavRef( |
| 686 | }); | 688 | }); |
| 687 | const endian = target.cpu.arch.endian(); | 689 | const endian = target.cpu.arch.endian(); |
| 688 | switch (ptr_width_bytes) { | 690 | switch (ptr_width_bytes) { |
| 689 | 2 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(vaddr), endian), | 691 | 2 => mem.writeInt(u16, try code.addManyAsArray(gpa, 2), @intCast(vaddr), endian), |
| 690 | 4 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(vaddr), endian), | 692 | 4 => mem.writeInt(u32, try code.addManyAsArray(gpa, 4), @intCast(vaddr), endian), |
| 691 | 8 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian), | 693 | 8 => mem.writeInt(u64, try code.addManyAsArray(gpa, 8), vaddr, endian), |
| 692 | else => unreachable, | 694 | else => unreachable, |
| 693 | } | 695 | } |
| 694 | } | 696 | } |
| ... | @@ -698,7 +700,7 @@ fn lowerNavRef( | ... | @@ -698,7 +700,7 @@ fn lowerNavRef( |
| 698 | pt: Zcu.PerThread, | 700 | pt: Zcu.PerThread, |
| 699 | src_loc: Zcu.LazySrcLoc, | 701 | src_loc: Zcu.LazySrcLoc, |
| 700 | nav_index: InternPool.Nav.Index, | 702 | nav_index: InternPool.Nav.Index, |
| 701 | code: *std.ArrayList(u8), | 703 | code: *std.ArrayListUnmanaged(u8), |
| 702 | reloc_parent: link.File.RelocInfo.Parent, | 704 | reloc_parent: link.File.RelocInfo.Parent, |
| 703 | offset: u64, | 705 | offset: u64, |
| 704 | ) GenerateSymbolError!void { | 706 | ) GenerateSymbolError!void { |
| ... | @@ -712,7 +714,7 @@ fn lowerNavRef( | ... | @@ -712,7 +714,7 @@ fn lowerNavRef( |
| 712 | const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip)); | 714 | const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip)); |
| 713 | const is_fn_body = nav_ty.zigTypeTag(zcu) == .@"fn"; | 715 | const is_fn_body = nav_ty.zigTypeTag(zcu) == .@"fn"; |
| 714 | if (!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) { | 716 | if (!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) { |
| 715 | try code.appendNTimes(0xaa, ptr_width_bytes); | 717 | try code.appendNTimes(gpa, 0xaa, ptr_width_bytes); |
| 716 | return; | 718 | return; |
| 717 | } | 719 | } |
| 718 | 720 | ||
| ... | @@ -730,7 +732,7 @@ fn lowerNavRef( | ... | @@ -730,7 +732,7 @@ fn lowerNavRef( |
| 730 | .offset = @intCast(code.items.len), | 732 | .offset = @intCast(code.items.len), |
| 731 | .pointee = .{ .nav_index = nav_index }, | 733 | .pointee = .{ .nav_index = nav_index }, |
| 732 | }); | 734 | }); |
| 733 | try code.appendNTimes(0, ptr_width_bytes); | 735 | try code.appendNTimes(gpa, 0, ptr_width_bytes); |
| 734 | return; | 736 | return; |
| 735 | }, | 737 | }, |
| 736 | else => {}, | 738 | else => {}, |
| ... | @@ -743,9 +745,9 @@ fn lowerNavRef( | ... | @@ -743,9 +745,9 @@ fn lowerNavRef( |
| 743 | }) catch @panic("TODO rework getNavVAddr"); | 745 | }) catch @panic("TODO rework getNavVAddr"); |
| 744 | const endian = target.cpu.arch.endian(); | 746 | const endian = target.cpu.arch.endian(); |
| 745 | switch (ptr_width_bytes) { | 747 | switch (ptr_width_bytes) { |
| 746 | 2 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(vaddr), endian), | 748 | 2 => mem.writeInt(u16, try code.addManyAsArray(gpa, 2), @intCast(vaddr), endian), |
| 747 | 4 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(vaddr), endian), | 749 | 4 => mem.writeInt(u32, try code.addManyAsArray(gpa, 4), @intCast(vaddr), endian), |
| 748 | 8 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian), | 750 | 8 => mem.writeInt(u64, try code.addManyAsArray(gpa, 8), vaddr, endian), |
| 749 | else => unreachable, | 751 | else => unreachable, |
| 750 | } | 752 | } |
| 751 | } | 753 | } |
src/link/Coff.zig+8-8| ... | @@ -1119,8 +1119,8 @@ pub fn updateFunc( | ... | @@ -1119,8 +1119,8 @@ pub fn updateFunc( |
| 1119 | 1119 | ||
| 1120 | coff.navs.getPtr(func.owner_nav).?.section = coff.text_section_index.?; | 1120 | coff.navs.getPtr(func.owner_nav).?.section = coff.text_section_index.?; |
| 1121 | 1121 | ||
| 1122 | var code_buffer = std.ArrayList(u8).init(gpa); | 1122 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1123 | defer code_buffer.deinit(); | 1123 | defer code_buffer.deinit(gpa); |
| 1124 | 1124 | ||
| 1125 | codegen.generateFunction( | 1125 | codegen.generateFunction( |
| 1126 | &coff.base, | 1126 | &coff.base, |
| ... | @@ -1167,8 +1167,8 @@ fn lowerConst( | ... | @@ -1167,8 +1167,8 @@ fn lowerConst( |
| 1167 | ) !LowerConstResult { | 1167 | ) !LowerConstResult { |
| 1168 | const gpa = coff.base.comp.gpa; | 1168 | const gpa = coff.base.comp.gpa; |
| 1169 | 1169 | ||
| 1170 | var code_buffer = std.ArrayList(u8).init(gpa); | 1170 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1171 | defer code_buffer.deinit(); | 1171 | defer code_buffer.deinit(gpa); |
| 1172 | 1172 | ||
| 1173 | const atom_index = try coff.createAtom(); | 1173 | const atom_index = try coff.createAtom(); |
| 1174 | const sym = coff.getAtom(atom_index).getSymbolPtr(coff); | 1174 | const sym = coff.getAtom(atom_index).getSymbolPtr(coff); |
| ... | @@ -1237,8 +1237,8 @@ pub fn updateNav( | ... | @@ -1237,8 +1237,8 @@ pub fn updateNav( |
| 1237 | 1237 | ||
| 1238 | coff.navs.getPtr(nav_index).?.section = coff.getNavOutputSection(nav_index); | 1238 | coff.navs.getPtr(nav_index).?.section = coff.getNavOutputSection(nav_index); |
| 1239 | 1239 | ||
| 1240 | var code_buffer = std.ArrayList(u8).init(gpa); | 1240 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1241 | defer code_buffer.deinit(); | 1241 | defer code_buffer.deinit(gpa); |
| 1242 | 1242 | ||
| 1243 | try codegen.generateSymbol( | 1243 | try codegen.generateSymbol( |
| 1244 | &coff.base, | 1244 | &coff.base, |
| ... | @@ -1267,8 +1267,8 @@ fn updateLazySymbolAtom( | ... | @@ -1267,8 +1267,8 @@ fn updateLazySymbolAtom( |
| 1267 | const gpa = comp.gpa; | 1267 | const gpa = comp.gpa; |
| 1268 | 1268 | ||
| 1269 | var required_alignment: InternPool.Alignment = .none; | 1269 | var required_alignment: InternPool.Alignment = .none; |
| 1270 | var code_buffer = std.ArrayList(u8).init(gpa); | 1270 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1271 | defer code_buffer.deinit(); | 1271 | defer code_buffer.deinit(gpa); |
| 1272 | 1272 | ||
| 1273 | const name = try allocPrint(gpa, "__lazy_{s}_{}", .{ | 1273 | const name = try allocPrint(gpa, "__lazy_{s}_{}", .{ |
| 1274 | @tagName(sym.kind), | 1274 | @tagName(sym.kind), |
src/link/Dwarf.zig+3-4| ... | @@ -1890,17 +1890,16 @@ pub const WipNav = struct { | ... | @@ -1890,17 +1890,16 @@ pub const WipNav = struct { |
| 1890 | const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; | 1890 | const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; |
| 1891 | try uleb128(diw, bytes); | 1891 | try uleb128(diw, bytes); |
| 1892 | if (bytes == 0) return; | 1892 | if (bytes == 0) return; |
| 1893 | var dim = wip_nav.debug_info.toManaged(wip_nav.dwarf.gpa); | 1893 | const old_len = wip_nav.debug_info.items.len; |
| 1894 | defer wip_nav.debug_info = dim.moveToUnmanaged(); | ||
| 1895 | try codegen.generateSymbol( | 1894 | try codegen.generateSymbol( |
| 1896 | wip_nav.dwarf.bin_file, | 1895 | wip_nav.dwarf.bin_file, |
| 1897 | wip_nav.pt, | 1896 | wip_nav.pt, |
| 1898 | src_loc, | 1897 | src_loc, |
| 1899 | val, | 1898 | val, |
| 1900 | &dim, | 1899 | &wip_nav.debug_info, |
| 1901 | .{ .debug_output = .{ .dwarf = wip_nav } }, | 1900 | .{ .debug_output = .{ .dwarf = wip_nav } }, |
| 1902 | ); | 1901 | ); |
| 1903 | assert(dim.items.len == wip_nav.debug_info.items.len + bytes); | 1902 | assert(old_len + bytes == wip_nav.debug_info.items.len); |
| 1904 | } | 1903 | } |
| 1905 | 1904 | ||
| 1906 | const AbbrevCodeForForm = struct { | 1905 | const AbbrevCodeForForm = struct { |
src/link/Elf/ZigObject.zig+8-8| ... | @@ -1431,8 +1431,8 @@ pub fn updateFunc( | ... | @@ -1431,8 +1431,8 @@ pub fn updateFunc( |
| 1431 | const sym_index = try self.getOrCreateMetadataForNav(zcu, func.owner_nav); | 1431 | const sym_index = try self.getOrCreateMetadataForNav(zcu, func.owner_nav); |
| 1432 | self.atom(self.symbol(sym_index).ref.index).?.freeRelocs(self); | 1432 | self.atom(self.symbol(sym_index).ref.index).?.freeRelocs(self); |
| 1433 | 1433 | ||
| 1434 | var code_buffer = std.ArrayList(u8).init(gpa); | 1434 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1435 | defer code_buffer.deinit(); | 1435 | defer code_buffer.deinit(gpa); |
| 1436 | 1436 | ||
| 1437 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null; | 1437 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null; |
| 1438 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); | 1438 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | @@ -1561,8 +1561,8 @@ pub fn updateNav( | ... | @@ -1561,8 +1561,8 @@ pub fn updateNav( |
| 1561 | const sym_index = try self.getOrCreateMetadataForNav(zcu, nav_index); | 1561 | const sym_index = try self.getOrCreateMetadataForNav(zcu, nav_index); |
| 1562 | self.symbol(sym_index).atom(elf_file).?.freeRelocs(self); | 1562 | self.symbol(sym_index).atom(elf_file).?.freeRelocs(self); |
| 1563 | 1563 | ||
| 1564 | var code_buffer = std.ArrayList(u8).init(zcu.gpa); | 1564 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1565 | defer code_buffer.deinit(); | 1565 | defer code_buffer.deinit(zcu.gpa); |
| 1566 | 1566 | ||
| 1567 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; | 1567 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; |
| 1568 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); | 1568 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | @@ -1616,8 +1616,8 @@ fn updateLazySymbol( | ... | @@ -1616,8 +1616,8 @@ fn updateLazySymbol( |
| 1616 | const gpa = zcu.gpa; | 1616 | const gpa = zcu.gpa; |
| 1617 | 1617 | ||
| 1618 | var required_alignment: InternPool.Alignment = .none; | 1618 | var required_alignment: InternPool.Alignment = .none; |
| 1619 | var code_buffer = std.ArrayList(u8).init(gpa); | 1619 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1620 | defer code_buffer.deinit(); | 1620 | defer code_buffer.deinit(gpa); |
| 1621 | 1621 | ||
| 1622 | const name_str_index = blk: { | 1622 | const name_str_index = blk: { |
| 1623 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ | 1623 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ |
| ... | @@ -1706,8 +1706,8 @@ fn lowerConst( | ... | @@ -1706,8 +1706,8 @@ fn lowerConst( |
| 1706 | ) !LowerConstResult { | 1706 | ) !LowerConstResult { |
| 1707 | const gpa = pt.zcu.gpa; | 1707 | const gpa = pt.zcu.gpa; |
| 1708 | 1708 | ||
| 1709 | var code_buffer = std.ArrayList(u8).init(gpa); | 1709 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1710 | defer code_buffer.deinit(); | 1710 | defer code_buffer.deinit(gpa); |
| 1711 | 1711 | ||
| 1712 | const name_off = try self.addString(gpa, name); | 1712 | const name_off = try self.addString(gpa, name); |
| 1713 | const sym_index = try self.newSymbolWithAtom(gpa, name_off); | 1713 | const sym_index = try self.newSymbolWithAtom(gpa, name_off); |
src/link/MachO/ZigObject.zig+8-8| ... | @@ -789,8 +789,8 @@ pub fn updateFunc( | ... | @@ -789,8 +789,8 @@ pub fn updateFunc( |
| 789 | const sym_index = try self.getOrCreateMetadataForNav(macho_file, func.owner_nav); | 789 | const sym_index = try self.getOrCreateMetadataForNav(macho_file, func.owner_nav); |
| 790 | self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file); | 790 | self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file); |
| 791 | 791 | ||
| 792 | var code_buffer = std.ArrayList(u8).init(gpa); | 792 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 793 | defer code_buffer.deinit(); | 793 | defer code_buffer.deinit(gpa); |
| 794 | 794 | ||
| 795 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null; | 795 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null; |
| 796 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); | 796 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | @@ -900,8 +900,8 @@ pub fn updateNav( | ... | @@ -900,8 +900,8 @@ pub fn updateNav( |
| 900 | const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index); | 900 | const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index); |
| 901 | self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file); | 901 | self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file); |
| 902 | 902 | ||
| 903 | var code_buffer = std.ArrayList(u8).init(zcu.gpa); | 903 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 904 | defer code_buffer.deinit(); | 904 | defer code_buffer.deinit(zcu.gpa); |
| 905 | 905 | ||
| 906 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; | 906 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; |
| 907 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); | 907 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | @@ -1201,8 +1201,8 @@ fn lowerConst( | ... | @@ -1201,8 +1201,8 @@ fn lowerConst( |
| 1201 | ) !LowerConstResult { | 1201 | ) !LowerConstResult { |
| 1202 | const gpa = macho_file.base.comp.gpa; | 1202 | const gpa = macho_file.base.comp.gpa; |
| 1203 | 1203 | ||
| 1204 | var code_buffer = std.ArrayList(u8).init(gpa); | 1204 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1205 | defer code_buffer.deinit(); | 1205 | defer code_buffer.deinit(gpa); |
| 1206 | 1206 | ||
| 1207 | const name_str = try self.addString(gpa, name); | 1207 | const name_str = try self.addString(gpa, name); |
| 1208 | const sym_index = try self.newSymbolWithAtom(gpa, name_str, macho_file); | 1208 | const sym_index = try self.newSymbolWithAtom(gpa, name_str, macho_file); |
| ... | @@ -1352,8 +1352,8 @@ fn updateLazySymbol( | ... | @@ -1352,8 +1352,8 @@ fn updateLazySymbol( |
| 1352 | const gpa = zcu.gpa; | 1352 | const gpa = zcu.gpa; |
| 1353 | 1353 | ||
| 1354 | var required_alignment: Atom.Alignment = .none; | 1354 | var required_alignment: Atom.Alignment = .none; |
| 1355 | var code_buffer = std.ArrayList(u8).init(gpa); | 1355 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1356 | defer code_buffer.deinit(); | 1356 | defer code_buffer.deinit(gpa); |
| 1357 | 1357 | ||
| 1358 | const name_str = blk: { | 1358 | const name_str = blk: { |
| 1359 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ | 1359 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ |
src/link/Plan9.zig+10-10| ... | @@ -404,8 +404,8 @@ pub fn updateFunc( | ... | @@ -404,8 +404,8 @@ pub fn updateFunc( |
| 404 | 404 | ||
| 405 | const atom_idx = try self.seeNav(pt, func.owner_nav); | 405 | const atom_idx = try self.seeNav(pt, func.owner_nav); |
| 406 | 406 | ||
| 407 | var code_buffer = std.ArrayList(u8).init(gpa); | 407 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 408 | defer code_buffer.deinit(); | 408 | defer code_buffer.deinit(gpa); |
| 409 | var dbg_info_output: DebugInfoOutput = .{ | 409 | var dbg_info_output: DebugInfoOutput = .{ |
| 410 | .dbg_line = std.ArrayList(u8).init(gpa), | 410 | .dbg_line = std.ArrayList(u8).init(gpa), |
| 411 | .start_line = null, | 411 | .start_line = null, |
| ... | @@ -426,7 +426,7 @@ pub fn updateFunc( | ... | @@ -426,7 +426,7 @@ pub fn updateFunc( |
| 426 | &code_buffer, | 426 | &code_buffer, |
| 427 | .{ .plan9 = &dbg_info_output }, | 427 | .{ .plan9 = &dbg_info_output }, |
| 428 | ); | 428 | ); |
| 429 | const code = try code_buffer.toOwnedSlice(); | 429 | const code = try code_buffer.toOwnedSlice(gpa); |
| 430 | self.getAtomPtr(atom_idx).code = .{ | 430 | self.getAtomPtr(atom_idx).code = .{ |
| 431 | .code_ptr = null, | 431 | .code_ptr = null, |
| 432 | .other = .{ .nav_index = func.owner_nav }, | 432 | .other = .{ .nav_index = func.owner_nav }, |
| ... | @@ -462,8 +462,8 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde | ... | @@ -462,8 +462,8 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde |
| 462 | if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) { | 462 | if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) { |
| 463 | const atom_idx = try self.seeNav(pt, nav_index); | 463 | const atom_idx = try self.seeNav(pt, nav_index); |
| 464 | 464 | ||
| 465 | var code_buffer = std.ArrayList(u8).init(gpa); | 465 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 466 | defer code_buffer.deinit(); | 466 | defer code_buffer.deinit(gpa); |
| 467 | // TODO we need the symbol index for symbol in the table of locals for the containing atom | 467 | // TODO we need the symbol index for symbol in the table of locals for the containing atom |
| 468 | try codegen.generateSymbol( | 468 | try codegen.generateSymbol( |
| 469 | &self.base, | 469 | &self.base, |
| ... | @@ -1060,8 +1060,8 @@ fn updateLazySymbolAtom( | ... | @@ -1060,8 +1060,8 @@ fn updateLazySymbolAtom( |
| 1060 | const diags = &comp.link_diags; | 1060 | const diags = &comp.link_diags; |
| 1061 | 1061 | ||
| 1062 | var required_alignment: InternPool.Alignment = .none; | 1062 | var required_alignment: InternPool.Alignment = .none; |
| 1063 | var code_buffer = std.ArrayList(u8).init(gpa); | 1063 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1064 | defer code_buffer.deinit(); | 1064 | defer code_buffer.deinit(gpa); |
| 1065 | 1065 | ||
| 1066 | // create the symbol for the name | 1066 | // create the symbol for the name |
| 1067 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ | 1067 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ |
| ... | @@ -1401,16 +1401,16 @@ pub fn lowerUav( | ... | @@ -1401,16 +1401,16 @@ pub fn lowerUav( |
| 1401 | const got_index = self.allocateGotIndex(); | 1401 | const got_index = self.allocateGotIndex(); |
| 1402 | gop.value_ptr.* = index; | 1402 | gop.value_ptr.* = index; |
| 1403 | // we need to free name latex | 1403 | // we need to free name latex |
| 1404 | var code_buffer = std.ArrayList(u8).init(gpa); | 1404 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; |
| 1405 | defer code_buffer.deinit(gpa); | ||
| 1405 | try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .atom_index = index }); | 1406 | try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .atom_index = index }); |
| 1406 | const code = code_buffer.items; | ||
| 1407 | const atom_ptr = self.getAtomPtr(index); | 1407 | const atom_ptr = self.getAtomPtr(index); |
| 1408 | atom_ptr.* = .{ | 1408 | atom_ptr.* = .{ |
| 1409 | .type = .d, | 1409 | .type = .d, |
| 1410 | .offset = undefined, | 1410 | .offset = undefined, |
| 1411 | .sym_index = null, | 1411 | .sym_index = null, |
| 1412 | .got_index = got_index, | 1412 | .got_index = got_index, |
| 1413 | .code = Atom.CodePtr.fromSlice(code), | 1413 | .code = Atom.CodePtr.fromSlice(try code_buffer.toOwnedSlice(gpa)), |
| 1414 | }; | 1414 | }; |
| 1415 | _ = try atom_ptr.getOrCreateSymbolTableEntry(self); | 1415 | _ = try atom_ptr.getOrCreateSymbolTableEntry(self); |
| 1416 | self.syms.items[atom_ptr.sym_index.?] = .{ | 1416 | self.syms.items[atom_ptr.sym_index.?] = .{ |
src/link/Wasm.zig+4-10| ... | @@ -1560,7 +1560,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index | ... | @@ -1560,7 +1560,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index |
| 1560 | const relocs_start: u32 = @intCast(wasm.relocations.len); | 1560 | const relocs_start: u32 = @intCast(wasm.relocations.len); |
| 1561 | wasm.string_bytes_lock.lock(); | 1561 | wasm.string_bytes_lock.lock(); |
| 1562 | 1562 | ||
| 1563 | const res = try codegen.generateSymbol( | 1563 | try codegen.generateSymbol( |
| 1564 | &wasm.base, | 1564 | &wasm.base, |
| 1565 | pt, | 1565 | pt, |
| 1566 | zcu.navSrcLoc(nav_index), | 1566 | zcu.navSrcLoc(nav_index), |
| ... | @@ -1573,15 +1573,9 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index | ... | @@ -1573,15 +1573,9 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index |
| 1573 | const relocs_len: u32 = @intCast(wasm.relocations.len - relocs_start); | 1573 | const relocs_len: u32 = @intCast(wasm.relocations.len - relocs_start); |
| 1574 | wasm.string_bytes_lock.unlock(); | 1574 | wasm.string_bytes_lock.unlock(); |
| 1575 | 1575 | ||
| 1576 | const code: Nav.Code = switch (res) { | 1576 | const code: Nav.Code = .{ |
| 1577 | .ok => .{ | 1577 | .off = code_start, |
| 1578 | .off = code_start, | 1578 | .len = code_len, |
| 1579 | .len = code_len, | ||
| 1580 | }, | ||
| 1581 | .fail => |em| { | ||
| 1582 | try zcu.failed_codegen.put(gpa, nav_index, em); | ||
| 1583 | return; | ||
| 1584 | }, | ||
| 1585 | }; | 1579 | }; |
| 1586 | 1580 | ||
| 1587 | const gop = try wasm.navs.getOrPut(gpa, nav_index); | 1581 | const gop = try wasm.navs.getOrPut(gpa, nav_index); |