| author | |
| committer | |
| log | c6286eee4ba8065b4a3f37fe3668041871e1b42e |
| tree | 6dda0dbc9eb1ca77546fb960a2eba24ef3f5d07f |
| parent | ee84deda988afb36f24ecd35ebea40221c1b80d8 |
| parent | 0a5291435513727a9f19570008388364f391b0d2 |
| signature |
Dwarf: more cleanup10 files changed, 212 insertions(+), 77 deletions(-)
ci/x86_64-linux-debug.sh+1-1| ... | ... | @@ -64,7 +64,7 @@ stage3-debug/bin/zig build \ |
| 64 | 64 | |
| 65 | 65 | stage3-debug/bin/zig build test docs \ |
| 66 | 66 | --maxrss 21000000000 \ |
| 67 | -Dlldb=$HOME/deps/lldb-zig/Debug-f96d3e6fc/bin/lldb \ | |
| 67 | -Dlldb=$HOME/deps/lldb-zig/Debug-62538077d/bin/lldb \ | |
| 68 | 68 | -fqemu \ |
| 69 | 69 | -fwasmtime \ |
| 70 | 70 | -Dstatic-llvm \ |
ci/x86_64-linux-release.sh+1-1| ... | ... | @@ -64,7 +64,7 @@ stage3-release/bin/zig build \ |
| 64 | 64 | |
| 65 | 65 | stage3-release/bin/zig build test docs \ |
| 66 | 66 | --maxrss 21000000000 \ |
| 67 | -Dlldb=$HOME/deps/lldb-zig/Release-f96d3e6fc/bin/lldb \ | |
| 67 | -Dlldb=$HOME/deps/lldb-zig/Release-62538077d/bin/lldb \ | |
| 68 | 68 | -fqemu \ |
| 69 | 69 | -fwasmtime \ |
| 70 | 70 | -Dstatic-llvm \ |
src/Type.zig+1-1| ... | ... | @@ -202,6 +202,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error |
| 202 | 202 | .C => try writer.writeAll("[*c]"), |
| 203 | 203 | .Slice => try writer.writeAll("[]"), |
| 204 | 204 | } |
| 205 | if (info.flags.is_allowzero and info.flags.size != .C) try writer.writeAll("allowzero "); | |
| 205 | 206 | if (info.flags.alignment != .none or |
| 206 | 207 | info.packed_offset.host_size != 0 or |
| 207 | 208 | info.flags.vector_index != .none) |
| ... | ... | @@ -229,7 +230,6 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error |
| 229 | 230 | } |
| 230 | 231 | if (info.flags.is_const) try writer.writeAll("const "); |
| 231 | 232 | if (info.flags.is_volatile) try writer.writeAll("volatile "); |
| 232 | if (info.flags.is_allowzero and info.flags.size != .C) try writer.writeAll("allowzero "); | |
| 233 | 233 | |
| 234 | 234 | try print(Type.fromInterned(info.child), writer, pt); |
| 235 | 235 | return; |
src/arch/x86_64/CodeGen.zig+28-9| ... | ... | @@ -59,6 +59,7 @@ owner: Owner, |
| 59 | 59 | inline_func: InternPool.Index, |
| 60 | 60 | mod: *Package.Module, |
| 61 | 61 | err_msg: ?*ErrorMsg, |
| 62 | arg_index: u32, | |
| 62 | 63 | args: []MCValue, |
| 63 | 64 | va_info: union { |
| 64 | 65 | sysv: struct { |
| ... | ... | @@ -71,7 +72,6 @@ va_info: union { |
| 71 | 72 | }, |
| 72 | 73 | ret_mcv: InstTracking, |
| 73 | 74 | fn_type: Type, |
| 74 | arg_index: u32, | |
| 75 | 75 | src_loc: Zcu.LazySrcLoc, |
| 76 | 76 | |
| 77 | 77 | eflags_inst: ?Air.Inst.Index = null, |
| ... | ... | @@ -802,11 +802,11 @@ pub fn generate( |
| 802 | 802 | .owner = .{ .nav_index = func.owner_nav }, |
| 803 | 803 | .inline_func = func_index, |
| 804 | 804 | .err_msg = null, |
| 805 | .arg_index = undefined, | |
| 805 | 806 | .args = undefined, // populated after `resolveCallingConventionValues` |
| 806 | 807 | .va_info = undefined, // populated after `resolveCallingConventionValues` |
| 807 | 808 | .ret_mcv = undefined, // populated after `resolveCallingConventionValues` |
| 808 | 809 | .fn_type = fn_type, |
| 809 | .arg_index = 0, | |
| 810 | 810 | .src_loc = src_loc, |
| 811 | 811 | .end_di_line = func.rbrace_line, |
| 812 | 812 | .end_di_column = func.rbrace_column, |
| ... | ... | @@ -877,6 +877,7 @@ pub fn generate( |
| 877 | 877 | }), |
| 878 | 878 | ); |
| 879 | 879 | function.va_info = switch (cc) { |
| 880 | else => undefined, | |
| 880 | 881 | .SysV => .{ .sysv = .{ |
| 881 | 882 | .gp_count = call_info.gp_count, |
| 882 | 883 | .fp_count = call_info.fp_count, |
| ... | ... | @@ -884,7 +885,6 @@ pub fn generate( |
| 884 | 885 | .reg_save_area = undefined, |
| 885 | 886 | } }, |
| 886 | 887 | .Win64 => .{ .win64 = .{} }, |
| 887 | else => undefined, | |
| 888 | 888 | }; |
| 889 | 889 | |
| 890 | 890 | function.gen() catch |err| switch (err) { |
| ... | ... | @@ -978,11 +978,11 @@ pub fn generateLazy( |
| 978 | 978 | .owner = .{ .lazy_sym = lazy_sym }, |
| 979 | 979 | .inline_func = undefined, |
| 980 | 980 | .err_msg = null, |
| 981 | .arg_index = undefined, | |
| 981 | 982 | .args = undefined, |
| 982 | 983 | .va_info = undefined, |
| 983 | 984 | .ret_mcv = undefined, |
| 984 | 985 | .fn_type = undefined, |
| 985 | .arg_index = undefined, | |
| 986 | 986 | .src_loc = src_loc, |
| 987 | 987 | .end_di_line = undefined, // no debug info yet |
| 988 | 988 | .end_di_column = undefined, // no debug info yet |
| ... | ... | @@ -1482,6 +1482,8 @@ fn asmOpOnly(self: *Self, tag: Mir.Inst.FixedTag) !void { |
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | fn asmPseudo(self: *Self, ops: Mir.Inst.Ops) !void { |
| 1485 | assert(std.mem.startsWith(u8, @tagName(ops), "pseudo_") and | |
| 1486 | std.mem.endsWith(u8, @tagName(ops), "_none")); | |
| 1485 | 1487 | _ = try self.addInst(.{ |
| 1486 | 1488 | .tag = .pseudo, |
| 1487 | 1489 | .ops = ops, |
| ... | ... | @@ -2101,6 +2103,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 2101 | 2103 | const ip = &mod.intern_pool; |
| 2102 | 2104 | const air_tags = self.air.instructions.items(.tag); |
| 2103 | 2105 | |
| 2106 | self.arg_index = 0; | |
| 2104 | 2107 | for (body) |inst| { |
| 2105 | 2108 | wip_mir_log.debug("{}", .{self.fmtAir(inst)}); |
| 2106 | 2109 | verbose_tracking_log.debug("{}", .{self.fmtTracking()}); |
| ... | ... | @@ -2114,6 +2117,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 2114 | 2117 | self.checkInvariantsAfterAirInst(inst, old_air_bookkeeping); |
| 2115 | 2118 | } |
| 2116 | 2119 | |
| 2120 | if (self.arg_index == 0) try self.airDbgVarArgs(); | |
| 2121 | self.arg_index = 0; | |
| 2117 | 2122 | for (body) |inst| { |
| 2118 | 2123 | if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue; |
| 2119 | 2124 | wip_mir_log.debug("{}", .{self.fmtAir(inst)}); |
| ... | ... | @@ -12055,11 +12060,25 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 12055 | 12060 | } |
| 12056 | 12061 | |
| 12057 | 12062 | fn airDbgArg(self: *Self, inst: Air.Inst.Index) !void { |
| 12058 | defer self.finishAirBookkeeping(); | |
| 12059 | if (self.debug_output == .none) return; | |
| 12060 | const name = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.name; | |
| 12061 | if (name != .none) try self.genLocalDebugInfo(inst, self.getResolvedInstValue(inst).short); | |
| 12062 | if (self.liveness.isUnused(inst)) try self.processDeath(inst); | |
| 12063 | // skip zero-bit arguments as they don't have a corresponding arg instruction | |
| 12064 | var arg_index = self.arg_index; | |
| 12065 | while (self.args[arg_index] == .none) arg_index += 1; | |
| 12066 | self.arg_index = arg_index + 1; | |
| 12067 | ||
| 12068 | if (self.debug_output != .none) { | |
| 12069 | const name = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.name; | |
| 12070 | if (name != .none) try self.genLocalDebugInfo(inst, self.getResolvedInstValue(inst).short); | |
| 12071 | if (self.liveness.isUnused(inst)) try self.processDeath(inst); | |
| 12072 | } | |
| 12073 | for (self.args[self.arg_index..]) |arg| { | |
| 12074 | if (arg != .none) break; | |
| 12075 | } else try self.airDbgVarArgs(); | |
| 12076 | self.finishAirBookkeeping(); | |
| 12077 | } | |
| 12078 | ||
| 12079 | fn airDbgVarArgs(self: *Self) !void { | |
| 12080 | if (self.pt.zcu.typeToFunc(self.fn_type).?.is_var_args) | |
| 12081 | try self.asmPseudo(.pseudo_dbg_var_args_none); | |
| 12063 | 12082 | } |
| 12064 | 12083 | |
| 12065 | 12084 | fn genLocalDebugInfo( |
src/arch/x86_64/Emit.zig+7| ... | ... | @@ -384,6 +384,13 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 384 | 384 | .none => {}, |
| 385 | 385 | } |
| 386 | 386 | }, |
| 387 | .pseudo_dbg_var_args_none => { | |
| 388 | switch (emit.debug_output) { | |
| 389 | .dwarf => |dw| try dw.genVarArgsDebugInfo(), | |
| 390 | .plan9 => {}, | |
| 391 | .none => {}, | |
| 392 | } | |
| 393 | }, | |
| 387 | 394 | .pseudo_dead_none => {}, |
| 388 | 395 | }, |
| 389 | 396 | } |
src/arch/x86_64/Lower.zig+1| ... | ... | @@ -279,6 +279,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct { |
| 279 | 279 | .pseudo_dbg_local_aro, |
| 280 | 280 | .pseudo_dbg_local_af, |
| 281 | 281 | .pseudo_dbg_local_am, |
| 282 | .pseudo_dbg_var_args_none, | |
| 282 | 283 | .pseudo_dead_none, |
| 283 | 284 | => {}, |
| 284 | 285 | else => unreachable, |
src/arch/x86_64/Mir.zig+2| ... | ... | @@ -924,6 +924,8 @@ pub const Inst = struct { |
| 924 | 924 | /// Local argument or variable. |
| 925 | 925 | /// Uses `ax` payload with extra data of type `Memory`. |
| 926 | 926 | pseudo_dbg_local_am, |
| 927 | /// Remaining arguments are varargs. | |
| 928 | pseudo_dbg_var_args_none, | |
| 927 | 929 | |
| 928 | 930 | /// Tombstone |
| 929 | 931 | /// Emitter should skip this instruction. |
src/link/Dwarf.zig+92-42| ... | ... | @@ -1108,6 +1108,12 @@ pub const WipNav = struct { |
| 1108 | 1108 | wip_nav.any_children = true; |
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | pub fn genVarArgsDebugInfo(wip_nav: *WipNav) UpdateError!void { | |
| 1112 | assert(wip_nav.func != .none); | |
| 1113 | try wip_nav.abbrevCode(.is_var_args); | |
| 1114 | wip_nav.any_children = true; | |
| 1115 | } | |
| 1116 | ||
| 1111 | 1117 | pub fn advancePCAndLine( |
| 1112 | 1118 | wip_nav: *WipNav, |
| 1113 | 1119 | delta_line: i33, |
| ... | ... | @@ -1380,7 +1386,11 @@ pub const WipNav = struct { |
| 1380 | 1386 | fn enumConstValue( |
| 1381 | 1387 | wip_nav: *WipNav, |
| 1382 | 1388 | loaded_enum: InternPool.LoadedEnumType, |
| 1383 | abbrev_code: std.enums.EnumFieldStruct(std.builtin.Signedness, AbbrevCode, null), | |
| 1389 | abbrev_code: struct { | |
| 1390 | sdata: AbbrevCode, | |
| 1391 | udata: AbbrevCode, | |
| 1392 | block: AbbrevCode, | |
| 1393 | }, | |
| 1384 | 1394 | field_index: usize, |
| 1385 | 1395 | ) UpdateError!void { |
| 1386 | 1396 | const zcu = wip_nav.pt.zcu; |
| ... | ... | @@ -1390,20 +1400,15 @@ pub const WipNav = struct { |
| 1390 | 1400 | .comptime_int_type => .signed, |
| 1391 | 1401 | else => Type.fromInterned(loaded_enum.tag_ty).intInfo(zcu).signedness, |
| 1392 | 1402 | }; |
| 1393 | try wip_nav.abbrevCode(switch (signedness) { | |
| 1394 | inline .signed, .unsigned => |ct_signedness| @field(abbrev_code, @tagName(ct_signedness)), | |
| 1395 | }); | |
| 1396 | if (loaded_enum.values.len > 0) switch (ip.indexToKey(loaded_enum.values.get(ip)[field_index]).int.storage) { | |
| 1397 | .u64 => |value| switch (signedness) { | |
| 1398 | .signed => try sleb128(diw, value), | |
| 1399 | .unsigned => try uleb128(diw, value), | |
| 1400 | }, | |
| 1401 | .i64 => |value| switch (signedness) { | |
| 1402 | .signed => try sleb128(diw, value), | |
| 1403 | .unsigned => unreachable, | |
| 1404 | }, | |
| 1405 | .big_int => |big_int| { | |
| 1406 | const bits = big_int.bitCountTwosCompForSignedness(signedness); | |
| 1403 | if (loaded_enum.values.len > 0) { | |
| 1404 | var big_int_space: InternPool.Key.Int.Storage.BigIntSpace = undefined; | |
| 1405 | const big_int = ip.indexToKey(loaded_enum.values.get(ip)[field_index]).int.storage.toBigInt(&big_int_space); | |
| 1406 | const bits = @max(1, big_int.bitCountTwosCompForSignedness(signedness)); | |
| 1407 | if (bits <= 64) { | |
| 1408 | try wip_nav.abbrevCode(switch (signedness) { | |
| 1409 | .signed => abbrev_code.sdata, | |
| 1410 | .unsigned => abbrev_code.udata, | |
| 1411 | }); | |
| 1407 | 1412 | try wip_nav.debug_info.ensureUnusedCapacity(wip_nav.dwarf.gpa, std.math.divCeil(usize, bits, 7) catch unreachable); |
| 1408 | 1413 | var bit: usize = 0; |
| 1409 | 1414 | var carry: u1 = 1; |
| ... | ... | @@ -1412,11 +1417,8 @@ pub const WipNav = struct { |
| 1412 | 1417 | const limb_index = bit / limb_bits; |
| 1413 | 1418 | const limb_shift: std.math.Log2Int(std.math.big.Limb) = @intCast(bit % limb_bits); |
| 1414 | 1419 | const low_abs_part: u7 = @truncate(big_int.limbs[limb_index] >> limb_shift); |
| 1415 | const abs_part = if (limb_shift > limb_bits - 7) abs_part: { | |
| 1416 | const next_limb: std.math.big.Limb = if (limb_index + 1 < big_int.limbs.len) | |
| 1417 | big_int.limbs[limb_index + 1] | |
| 1418 | else if (big_int.positive) 0 else std.math.maxInt(std.math.big.Limb); | |
| 1419 | const high_abs_part: u7 = @truncate(next_limb << -%limb_shift); | |
| 1420 | const abs_part = if (limb_shift > limb_bits - 7 and limb_index + 1 < big_int.limbs.len) abs_part: { | |
| 1421 | const high_abs_part: u7 = @truncate(big_int.limbs[limb_index + 1] << -%limb_shift); | |
| 1420 | 1422 | break :abs_part high_abs_part | low_abs_part; |
| 1421 | 1423 | } else low_abs_part; |
| 1422 | 1424 | const twos_comp_part = if (big_int.positive) abs_part else twos_comp_part: { |
| ... | ... | @@ -1425,11 +1427,21 @@ pub const WipNav = struct { |
| 1425 | 1427 | }; |
| 1426 | 1428 | wip_nav.debug_info.appendAssumeCapacity(@as(u8, if (bit + 7 < bits) 0x80 else 0x00) | twos_comp_part); |
| 1427 | 1429 | } |
| 1428 | }, | |
| 1429 | .lazy_align, .lazy_size => unreachable, | |
| 1430 | } else { | |
| 1431 | try wip_nav.abbrevCode(abbrev_code.block); | |
| 1432 | const bytes = Type.fromInterned(loaded_enum.tag_ty).abiSize(wip_nav.pt); | |
| 1433 | try uleb128(diw, bytes); | |
| 1434 | big_int.writeTwosComplement(try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), wip_nav.dwarf.endian); | |
| 1435 | } | |
| 1430 | 1436 | } else switch (signedness) { |
| 1431 | .signed => try sleb128(diw, field_index), | |
| 1432 | .unsigned => try uleb128(diw, field_index), | |
| 1437 | .signed => { | |
| 1438 | try wip_nav.abbrevCode(abbrev_code.sdata); | |
| 1439 | try sleb128(diw, field_index); | |
| 1440 | }, | |
| 1441 | .unsigned => { | |
| 1442 | try wip_nav.abbrevCode(abbrev_code.udata); | |
| 1443 | try uleb128(diw, field_index); | |
| 1444 | }, | |
| 1433 | 1445 | } |
| 1434 | 1446 | } |
| 1435 | 1447 | |
| ... | ... | @@ -2267,8 +2279,9 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2267 | 2279 | try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty)); |
| 2268 | 2280 | for (0..loaded_enum.names.len) |field_index| { |
| 2269 | 2281 | try wip_nav.enumConstValue(loaded_enum, .{ |
| 2270 | .signed = .signed_enum_field, | |
| 2271 | .unsigned = .unsigned_enum_field, | |
| 2282 | .sdata = .signed_enum_field, | |
| 2283 | .udata = .unsigned_enum_field, | |
| 2284 | .block = .big_enum_field, | |
| 2272 | 2285 | }, field_index); |
| 2273 | 2286 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 2274 | 2287 | } |
| ... | ... | @@ -2367,8 +2380,9 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2367 | 2380 | |
| 2368 | 2381 | for (0..loaded_union.field_types.len) |field_index| { |
| 2369 | 2382 | try wip_nav.enumConstValue(loaded_tag, .{ |
| 2370 | .signed = .signed_tagged_union_field, | |
| 2371 | .unsigned = .unsigned_tagged_union_field, | |
| 2383 | .sdata = .signed_tagged_union_field, | |
| 2384 | .udata = .unsigned_tagged_union_field, | |
| 2385 | .block = .big_tagged_union_field, | |
| 2372 | 2386 | }, field_index); |
| 2373 | 2387 | { |
| 2374 | 2388 | try wip_nav.abbrevCode(.struct_field); |
| ... | ... | @@ -2831,17 +2845,18 @@ fn updateType( |
| 2831 | 2845 | }, |
| 2832 | 2846 | .enum_type => { |
| 2833 | 2847 | const loaded_enum = ip.loadEnumType(type_index); |
| 2834 | try wip_nav.abbrevCode(.enum_type); | |
| 2848 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); | |
| 2835 | 2849 | try wip_nav.strp(name); |
| 2836 | 2850 | try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty)); |
| 2837 | 2851 | for (0..loaded_enum.names.len) |field_index| { |
| 2838 | 2852 | try wip_nav.enumConstValue(loaded_enum, .{ |
| 2839 | .signed = .signed_enum_field, | |
| 2840 | .unsigned = .unsigned_enum_field, | |
| 2853 | .sdata = .signed_enum_field, | |
| 2854 | .udata = .unsigned_enum_field, | |
| 2855 | .block = .big_enum_field, | |
| 2841 | 2856 | }, field_index); |
| 2842 | 2857 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 2843 | 2858 | } |
| 2844 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 2859 | if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 2845 | 2860 | }, |
| 2846 | 2861 | .func_type => |func_type| { |
| 2847 | 2862 | const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; |
| ... | ... | @@ -3049,7 +3064,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3049 | 3064 | } |
| 3050 | 3065 | }, |
| 3051 | 3066 | .@"packed" => { |
| 3052 | try wip_nav.abbrevCode(.packed_struct_type); | |
| 3067 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); | |
| 3053 | 3068 | try wip_nav.strp(name); |
| 3054 | 3069 | try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 3055 | 3070 | var field_bit_offset: u16 = 0; |
| ... | ... | @@ -3061,27 +3076,28 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3061 | 3076 | try uleb128(diw, field_bit_offset); |
| 3062 | 3077 | field_bit_offset += @intCast(field_type.bitSize(pt)); |
| 3063 | 3078 | } |
| 3064 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 3079 | if (loaded_struct.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 3065 | 3080 | }, |
| 3066 | 3081 | } |
| 3067 | 3082 | }, |
| 3068 | 3083 | .enum_type => { |
| 3069 | 3084 | const loaded_enum = ip.loadEnumType(type_index); |
| 3070 | try wip_nav.abbrevCode(.enum_type); | |
| 3085 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); | |
| 3071 | 3086 | try wip_nav.strp(name); |
| 3072 | 3087 | try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty)); |
| 3073 | 3088 | for (0..loaded_enum.names.len) |field_index| { |
| 3074 | 3089 | try wip_nav.enumConstValue(loaded_enum, .{ |
| 3075 | .signed = .signed_enum_field, | |
| 3076 | .unsigned = .unsigned_enum_field, | |
| 3090 | .sdata = .signed_enum_field, | |
| 3091 | .udata = .unsigned_enum_field, | |
| 3092 | .block = .big_enum_field, | |
| 3077 | 3093 | }, field_index); |
| 3078 | 3094 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 3079 | 3095 | } |
| 3080 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 3096 | if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 3081 | 3097 | }, |
| 3082 | 3098 | .union_type => { |
| 3083 | 3099 | const loaded_union = ip.loadUnionType(type_index); |
| 3084 | try wip_nav.abbrevCode(.union_type); | |
| 3100 | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); | |
| 3085 | 3101 | try wip_nav.strp(name); |
| 3086 | 3102 | const union_layout = pt.getUnionLayout(loaded_union); |
| 3087 | 3103 | try uleb128(diw, union_layout.abi_size); |
| ... | ... | @@ -3103,8 +3119,9 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3103 | 3119 | |
| 3104 | 3120 | for (0..loaded_union.field_types.len) |field_index| { |
| 3105 | 3121 | try wip_nav.enumConstValue(loaded_tag, .{ |
| 3106 | .signed = .signed_tagged_union_field, | |
| 3107 | .unsigned = .unsigned_tagged_union_field, | |
| 3122 | .sdata = .signed_tagged_union_field, | |
| 3123 | .udata = .unsigned_tagged_union_field, | |
| 3124 | .block = .big_tagged_union_field, | |
| 3108 | 3125 | }, field_index); |
| 3109 | 3126 | { |
| 3110 | 3127 | try wip_nav.abbrevCode(.struct_field); |
| ... | ... | @@ -3130,7 +3147,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3130 | 3147 | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3131 | 3148 | field_type.abiAlignment(pt).toByteUnits().?); |
| 3132 | 3149 | } |
| 3133 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 3150 | if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | |
| 3134 | 3151 | }, |
| 3135 | 3152 | .opaque_type => { |
| 3136 | 3153 | try wip_nav.abbrevCode(.namespace_struct_type); |
| ... | ... | @@ -3570,6 +3587,7 @@ const AbbrevCode = enum { |
| 3570 | 3587 | file, |
| 3571 | 3588 | signed_enum_field, |
| 3572 | 3589 | unsigned_enum_field, |
| 3590 | big_enum_field, | |
| 3573 | 3591 | generated_field, |
| 3574 | 3592 | struct_field, |
| 3575 | 3593 | struct_field_comptime, |
| ... | ... | @@ -3578,6 +3596,7 @@ const AbbrevCode = enum { |
| 3578 | 3596 | tagged_union, |
| 3579 | 3597 | signed_tagged_union_field, |
| 3580 | 3598 | unsigned_tagged_union_field, |
| 3599 | big_tagged_union_field, | |
| 3581 | 3600 | tagged_union_default_field, |
| 3582 | 3601 | void_type, |
| 3583 | 3602 | numeric_type, |
| ... | ... | @@ -3596,7 +3615,9 @@ const AbbrevCode = enum { |
| 3596 | 3615 | namespace_struct_type, |
| 3597 | 3616 | struct_type, |
| 3598 | 3617 | packed_struct_type, |
| 3618 | empty_packed_struct_type, | |
| 3599 | 3619 | union_type, |
| 3620 | empty_union_type, | |
| 3600 | 3621 | empty_inlined_func, |
| 3601 | 3622 | inlined_func, |
| 3602 | 3623 | local_arg, |
| ... | ... | @@ -3778,6 +3799,13 @@ const AbbrevCode = enum { |
| 3778 | 3799 | .{ .name, .strp }, |
| 3779 | 3800 | }, |
| 3780 | 3801 | }, |
| 3802 | .big_enum_field = .{ | |
| 3803 | .tag = .enumerator, | |
| 3804 | .attrs = &.{ | |
| 3805 | .{ .const_value, .block }, | |
| 3806 | .{ .name, .strp }, | |
| 3807 | }, | |
| 3808 | }, | |
| 3781 | 3809 | .generated_field = .{ |
| 3782 | 3810 | .tag = .member, |
| 3783 | 3811 | .attrs = &.{ |
| ... | ... | @@ -3841,6 +3869,13 @@ const AbbrevCode = enum { |
| 3841 | 3869 | .{ .discr_value, .udata }, |
| 3842 | 3870 | }, |
| 3843 | 3871 | }, |
| 3872 | .big_tagged_union_field = .{ | |
| 3873 | .tag = .variant, | |
| 3874 | .children = true, | |
| 3875 | .attrs = &.{ | |
| 3876 | .{ .discr_value, .block }, | |
| 3877 | }, | |
| 3878 | }, | |
| 3844 | 3879 | .tagged_union_default_field = .{ |
| 3845 | 3880 | .tag = .variant, |
| 3846 | 3881 | .children = true, |
| ... | ... | @@ -3971,6 +4006,13 @@ const AbbrevCode = enum { |
| 3971 | 4006 | .{ .type, .ref_addr }, |
| 3972 | 4007 | }, |
| 3973 | 4008 | }, |
| 4009 | .empty_packed_struct_type = .{ | |
| 4010 | .tag = .structure_type, | |
| 4011 | .attrs = &.{ | |
| 4012 | .{ .name, .strp }, | |
| 4013 | .{ .type, .ref_addr }, | |
| 4014 | }, | |
| 4015 | }, | |
| 3974 | 4016 | .union_type = .{ |
| 3975 | 4017 | .tag = .union_type, |
| 3976 | 4018 | .children = true, |
| ... | ... | @@ -3980,6 +4022,14 @@ const AbbrevCode = enum { |
| 3980 | 4022 | .{ .alignment, .udata }, |
| 3981 | 4023 | }, |
| 3982 | 4024 | }, |
| 4025 | .empty_union_type = .{ | |
| 4026 | .tag = .union_type, | |
| 4027 | .attrs = &.{ | |
| 4028 | .{ .name, .strp }, | |
| 4029 | .{ .byte_size, .udata }, | |
| 4030 | .{ .alignment, .udata }, | |
| 4031 | }, | |
| 4032 | }, | |
| 3983 | 4033 | .empty_inlined_func = .{ |
| 3984 | 4034 | .tag = .inlined_subroutine, |
| 3985 | 4035 | .attrs = &.{ |
src/link/Elf/ZigObject.zig+61-5| ... | ... | @@ -169,7 +169,6 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 169 | 169 | if (self.dwarf) |*dwarf| { |
| 170 | 170 | const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid }; |
| 171 | 171 | try dwarf.flushModule(pt); |
| 172 | try dwarf.resolveRelocs(); | |
| 173 | 172 | |
| 174 | 173 | const gpa = elf_file.base.comp.gpa; |
| 175 | 174 | const cpu_arch = elf_file.getTarget().cpu.arch; |
| ... | ... | @@ -209,7 +208,28 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 209 | 208 | |
| 210 | 209 | const relocs = &self.relocs.items[atom_ptr.relocsShndx().?]; |
| 211 | 210 | for (sect.units.items) |*unit| { |
| 212 | try relocs.ensureUnusedCapacity(gpa, unit.cross_section_relocs.items.len); | |
| 211 | try relocs.ensureUnusedCapacity(gpa, unit.cross_unit_relocs.items.len + | |
| 212 | unit.cross_section_relocs.items.len); | |
| 213 | for (unit.cross_unit_relocs.items) |reloc| { | |
| 214 | const target_unit = sect.getUnit(reloc.target_unit); | |
| 215 | const r_offset = unit.off + reloc.source_off; | |
| 216 | const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry| | |
| 217 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off | |
| 218 | else | |
| 219 | 0)); | |
| 220 | const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch); | |
| 221 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={}", .{ | |
| 222 | self.symbol(sym_index).name(elf_file), | |
| 223 | r_offset, | |
| 224 | r_addend, | |
| 225 | relocation.fmtRelocType(r_type, cpu_arch), | |
| 226 | }); | |
| 227 | atom_ptr.addRelocAssumeCapacity(.{ | |
| 228 | .r_offset = r_offset, | |
| 229 | .r_addend = r_addend, | |
| 230 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | |
| 231 | }, self); | |
| 232 | } | |
| 213 | 233 | for (unit.cross_section_relocs.items) |reloc| { |
| 214 | 234 | const target_sym_index = switch (reloc.target_sec) { |
| 215 | 235 | .debug_abbrev => self.debug_abbrev_index.?, |
| ... | ... | @@ -246,7 +266,45 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 246 | 266 | for (unit.entries.items) |*entry| { |
| 247 | 267 | const entry_off = unit.off + unit.header_len + entry.off; |
| 248 | 268 | |
| 249 | try relocs.ensureUnusedCapacity(gpa, entry.cross_section_relocs.items.len); | |
| 269 | try relocs.ensureUnusedCapacity(gpa, entry.cross_entry_relocs.items.len + | |
| 270 | entry.cross_unit_relocs.items.len + entry.cross_section_relocs.items.len + | |
| 271 | entry.external_relocs.items.len); | |
| 272 | for (entry.cross_entry_relocs.items) |reloc| { | |
| 273 | const r_offset = entry_off + reloc.source_off; | |
| 274 | const r_addend: i64 = @intCast(unit.off + reloc.target_off + unit.header_len + unit.getEntry(reloc.target_entry).assertNonEmpty(unit, sect, dwarf).off); | |
| 275 | const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch); | |
| 276 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={}", .{ | |
| 277 | self.symbol(sym_index).name(elf_file), | |
| 278 | r_offset, | |
| 279 | r_addend, | |
| 280 | relocation.fmtRelocType(r_type, cpu_arch), | |
| 281 | }); | |
| 282 | atom_ptr.addRelocAssumeCapacity(.{ | |
| 283 | .r_offset = r_offset, | |
| 284 | .r_addend = r_addend, | |
| 285 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | |
| 286 | }, self); | |
| 287 | } | |
| 288 | for (entry.cross_unit_relocs.items) |reloc| { | |
| 289 | const target_unit = sect.getUnit(reloc.target_unit); | |
| 290 | const r_offset = entry_off + reloc.source_off; | |
| 291 | const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry| | |
| 292 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off | |
| 293 | else | |
| 294 | 0)); | |
| 295 | const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch); | |
| 296 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={}", .{ | |
| 297 | self.symbol(sym_index).name(elf_file), | |
| 298 | r_offset, | |
| 299 | r_addend, | |
| 300 | relocation.fmtRelocType(r_type, cpu_arch), | |
| 301 | }); | |
| 302 | atom_ptr.addRelocAssumeCapacity(.{ | |
| 303 | .r_offset = r_offset, | |
| 304 | .r_addend = r_addend, | |
| 305 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, | |
| 306 | }, self); | |
| 307 | } | |
| 250 | 308 | for (entry.cross_section_relocs.items) |reloc| { |
| 251 | 309 | const target_sym_index = switch (reloc.target_sec) { |
| 252 | 310 | .debug_abbrev => self.debug_abbrev_index.?, |
| ... | ... | @@ -279,8 +337,6 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 279 | 337 | .r_info = (@as(u64, @intCast(target_sym_index)) << 32) | r_type, |
| 280 | 338 | }, self); |
| 281 | 339 | } |
| 282 | ||
| 283 | try relocs.ensureUnusedCapacity(gpa, entry.external_relocs.items.len); | |
| 284 | 340 | for (entry.external_relocs.items) |reloc| { |
| 285 | 341 | const target_sym = self.symbol(reloc.target_sym); |
| 286 | 342 | const r_offset = entry_off + reloc.source_off; |
test/src/Debugger.zig+18-18| ... | ... | @@ -205,26 +205,26 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void { |
| 205 | 205 | \\ single_volatile: *volatile u32 = @ptrFromInt(0x1018), |
| 206 | 206 | \\ single_const_volatile: *const volatile u32 = @ptrFromInt(0x101c), |
| 207 | 207 | \\ single_allowzero: *allowzero u32 = @ptrFromInt(0x1020), |
| 208 | \\ single_const_allowzero: *const allowzero u32 = @ptrFromInt(0x1024), | |
| 209 | \\ single_volatile_allowzero: *volatile allowzero u32 = @ptrFromInt(0x1028), | |
| 210 | \\ single_const_volatile_allowzero: *const volatile allowzero u32 = @ptrFromInt(0x102c), | |
| 208 | \\ single_allowzero_const: *allowzero const u32 = @ptrFromInt(0x1024), | |
| 209 | \\ single_allowzero_volatile: *allowzero volatile u32 = @ptrFromInt(0x1028), | |
| 210 | \\ single_allowzero_const_volatile: *allowzero const volatile u32 = @ptrFromInt(0x102c), | |
| 211 | 211 | \\ |
| 212 | 212 | \\ many: [*]u32 = @ptrFromInt(0x2010), |
| 213 | 213 | \\ many_const: [*]const u32 = @ptrFromInt(0x2014), |
| 214 | 214 | \\ many_volatile: [*]volatile u32 = @ptrFromInt(0x2018), |
| 215 | 215 | \\ many_const_volatile: [*]const volatile u32 = @ptrFromInt(0x201c), |
| 216 | 216 | \\ many_allowzero: [*]allowzero u32 = @ptrFromInt(0x2020), |
| 217 | \\ many_const_allowzero: [*]const allowzero u32 = @ptrFromInt(0x2024), | |
| 218 | \\ many_volatile_allowzero: [*]volatile allowzero u32 = @ptrFromInt(0x2028), | |
| 219 | \\ many_const_volatile_allowzero: [*]const volatile allowzero u32 = @ptrFromInt(0x202c), | |
| 217 | \\ many_allowzero_const: [*]allowzero const u32 = @ptrFromInt(0x2024), | |
| 218 | \\ many_allowzero_volatile: [*]allowzero volatile u32 = @ptrFromInt(0x2028), | |
| 219 | \\ many_allowzero_const_volatile: [*]allowzero const volatile u32 = @ptrFromInt(0x202c), | |
| 220 | 220 | \\ slice: []u32 = array[0..1], |
| 221 | 221 | \\ slice_const: []const u32 = array[0..2], |
| 222 | 222 | \\ slice_volatile: []volatile u32 = array[0..3], |
| 223 | 223 | \\ slice_const_volatile: []const volatile u32 = array[0..4], |
| 224 | 224 | \\ slice_allowzero: []allowzero u32 = array[4..4], |
| 225 | \\ slice_const_allowzero: []const allowzero u32 = array[4..5], | |
| 226 | \\ slice_volatile_allowzero: []volatile allowzero u32 = array[4..6], | |
| 227 | \\ slice_const_volatile_allowzero: []const volatile allowzero u32 = array[4..7], | |
| 225 | \\ slice_allowzero_const: []allowzero const u32 = array[4..5], | |
| 226 | \\ slice_allowzero_volatile: []allowzero volatile u32 = array[4..6], | |
| 227 | \\ slice_allowzero_const_volatile: []allowzero const volatile u32 = array[4..7], | |
| 228 | 228 | \\ |
| 229 | 229 | \\ c: [*c]u32 = @ptrFromInt(0x4010), |
| 230 | 230 | \\ c_const: [*c]const u32 = @ptrFromInt(0x4014), |
| ... | ... | @@ -254,17 +254,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void { |
| 254 | 254 | \\ (*volatile u32) single_volatile = 0x0000000000001018 |
| 255 | 255 | \\ (*const volatile u32) single_const_volatile = 0x000000000000101c |
| 256 | 256 | \\ (*allowzero u32) single_allowzero = 0x0000000000001020 |
| 257 | \\ (*const allowzero u32) single_const_allowzero = 0x0000000000001024 | |
| 258 | \\ (*volatile allowzero u32) single_volatile_allowzero = 0x0000000000001028 | |
| 259 | \\ (*const volatile allowzero u32) single_const_volatile_allowzero = 0x000000000000102c | |
| 257 | \\ (*allowzero const u32) single_allowzero_const = 0x0000000000001024 | |
| 258 | \\ (*allowzero volatile u32) single_allowzero_volatile = 0x0000000000001028 | |
| 259 | \\ (*allowzero const volatile u32) single_allowzero_const_volatile = 0x000000000000102c | |
| 260 | 260 | \\ ([*]u32) many = 0x0000000000002010 |
| 261 | 261 | \\ ([*]const u32) many_const = 0x0000000000002014 |
| 262 | 262 | \\ ([*]volatile u32) many_volatile = 0x0000000000002018 |
| 263 | 263 | \\ ([*]const volatile u32) many_const_volatile = 0x000000000000201c |
| 264 | 264 | \\ ([*]allowzero u32) many_allowzero = 0x0000000000002020 |
| 265 | \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024 | |
| 266 | \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028 | |
| 267 | \\ ([*]const volatile allowzero u32) many_const_volatile_allowzero = 0x000000000000202c | |
| 265 | \\ ([*]allowzero const u32) many_allowzero_const = 0x0000000000002024 | |
| 266 | \\ ([*]allowzero volatile u32) many_allowzero_volatile = 0x0000000000002028 | |
| 267 | \\ ([*]allowzero const volatile u32) many_allowzero_const_volatile = 0x000000000000202c | |
| 268 | 268 | \\ ([]u32) slice = len=1 { |
| 269 | 269 | \\ (u32) [0] = 3010 |
| 270 | 270 | \\ } |
| ... | ... | @@ -284,14 +284,14 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void { |
| 284 | 284 | \\ (u32) [3] = 3022 |
| 285 | 285 | \\ } |
| 286 | 286 | \\ ([]allowzero u32) slice_allowzero = len=0 {} |
| 287 | \\ ([]const allowzero u32) slice_const_allowzero = len=1 { | |
| 287 | \\ ([]allowzero const u32) slice_allowzero_const = len=1 { | |
| 288 | 288 | \\ (u32) [0] = 3026 |
| 289 | 289 | \\ } |
| 290 | \\ ([]volatile allowzero u32) slice_volatile_allowzero = len=2 { | |
| 290 | \\ ([]allowzero volatile u32) slice_allowzero_volatile = len=2 { | |
| 291 | 291 | \\ (u32) [0] = 3026 |
| 292 | 292 | \\ (u32) [1] = 3030 |
| 293 | 293 | \\ } |
| 294 | \\ ([]const volatile allowzero u32) slice_const_volatile_allowzero = len=3 { | |
| 294 | \\ ([]allowzero const volatile u32) slice_allowzero_const_volatile = len=3 { | |
| 295 | 295 | \\ (u32) [0] = 3026 |
| 296 | 296 | \\ (u32) [1] = 3030 |
| 297 | 297 | \\ (u32) [2] = 3034 |