authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-19 13:36:50+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-19 18:30:35+01:00
log6a5ce4aa99dc5c3ca86187845de24bd521644056
treec70f0a2d7e8038a26544bc792403f7a786598e8b
parentf7626b95269bc3baad2c46e4d3b7acc16221c424
signature Commit is signed but in an unrecognized format.

link.Dwarf: match new Dwarf2 extern representation

A previous commit in this branch changed how `link.Dwarf2` represents `extern`s. The legacy `link.Dwarf` implementation, used by the old ELF linker, did not have this change, which led to deviations in debugger output. This commit brings them back into sync.

1 files changed, 37 insertions(+), 16 deletions(-)

src/link/Dwarf.zig+37-16
......@@ -2662,7 +2662,6 @@ fn initWipNavInner(
26622662 try wip_nav.strp(@"extern".name.toSlice(ip));
26632663 try wip_nav.refType(.fromInterned(if (maybe_func_type) |func_type| func_type.return_type else @"extern".ty));
26642664 if (maybe_func_type) |func_type| {
2665 try wip_nav.infoAddrSym(sym_index, 0);
26662665 try diw.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));
26672666 if (func_type.param_types.len > 0 or func_type.is_var_args) {
26682667 for (func_type.param_types.get(ip)) |param_type| {
......@@ -2672,7 +2671,7 @@ fn initWipNavInner(
26722671 if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
26732672 try diw.writeUleb128(@backingInt(AbbrevCode.null));
26742673 }
2675 } else try wip_nav.infoExprLoc(.{ .addr_reloc = sym_index });
2674 }
26762675 },
26772676 .syntax => switch (ip.isFunctionType(@"extern".ty)) {
26782677 false => continue :nav_val .{ .undef = @"extern".ty },
......@@ -2690,7 +2689,6 @@ fn initWipNavInner(
26902689 }, &nav, inst_info.file, &decl);
26912690 try wip_nav.strp(@"extern".name.toSlice(ip));
26922691 try wip_nav.refType(.fromInterned(func_type.return_type));
2693 try wip_nav.infoAddrSym(sym_index, 0);
26942692 try diw.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));
26952693 if (func_type.param_types.len > 0 or func_type.is_var_args) {
26962694 for (func_type.param_types.get(ip)) |param_type| {
......@@ -2817,13 +2815,19 @@ fn initWipNavInner(
28172815 else => {
28182816 const diw = &wip_nav.debug_info.writer;
28192817 try wip_nav.declCommon(.{
2820 .decl = .decl_var,
2818 .decl = switch (decl.linkage) {
2819 .@"extern" => .decl_extern_var,
2820 else => .decl_var,
2821 },
28212822 .decl_specification = switch (decl.kind) {
28222823 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
28232824 .@"const" => .decl_specification_const,
28242825 .@"var" => .decl_specification_var,
28252826 },
2826 .decl_instance = .decl_instance_var,
2827 .decl_instance = switch (decl.linkage) {
2828 .@"extern" => .decl_instance_extern_var,
2829 else => .decl_instance_var,
2830 },
28272831 }, &nav, inst_info.file, &decl);
28282832 try wip_nav.strp(switch (decl.linkage) {
28292833 .normal => nav.fqn,
......@@ -2842,20 +2846,24 @@ fn initWipNavInner(
28422846 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
28432847 .@"const" => {
28442848 const const_ty_reloc_index = try wip_nav.refForward();
2845 try wip_nav.infoExprLoc(loc);
2849 if (decl.linkage != .@"extern") try wip_nav.infoExprLoc(loc);
28462850 try diw.writeUleb128(nav.resolved.?.@"align".toByteUnits() orelse
28472851 ty.abiAlignment(zcu).toByteUnits().?);
2848 try diw.writeByte(@intFromBool(decl.linkage != .normal));
2852 if (decl.linkage != .@"extern") {
2853 try diw.writeByte(@intFromBool(decl.linkage != .normal));
2854 }
28492855 wip_nav.finishForward(const_ty_reloc_index);
28502856 try wip_nav.abbrevCode(.is_const);
28512857 try wip_nav.refType(ty);
28522858 },
28532859 .@"var" => {
28542860 try wip_nav.refType(ty);
2855 try wip_nav.infoExprLoc(loc);
2861 if (decl.linkage != .@"extern") try wip_nav.infoExprLoc(loc);
28562862 try diw.writeUleb128(nav.resolved.?.@"align".toByteUnits() orelse
28572863 ty.abiAlignment(zcu).toByteUnits().?);
2858 try diw.writeByte(@intFromBool(decl.linkage != .normal));
2864 if (decl.linkage != .@"extern") {
2865 try diw.writeByte(@intFromBool(decl.linkage != .normal));
2866 }
28592867 },
28602868 }
28612869 },
......@@ -5138,6 +5146,7 @@ const AbbrevCode = enum {
51385146 decl_union,
51395147 decl_packed_union,
51405148 decl_var,
5149 decl_extern_var,
51415150 decl_const,
51425151 decl_const_runtime_bits,
51435152 decl_const_comptime_state,
......@@ -5160,6 +5169,7 @@ const AbbrevCode = enum {
51605169 decl_instance_union,
51615170 decl_instance_packed_union,
51625171 decl_instance_var,
5172 decl_instance_extern_var,
51635173 decl_instance_const,
51645174 decl_instance_const_runtime_bits,
51655175 decl_instance_const_comptime_state,
......@@ -5360,6 +5370,15 @@ const AbbrevCode = enum {
53605370 .{ .external, .flag },
53615371 },
53625372 },
5373 .decl_extern_var = .{
5374 .tag = .variable,
5375 .attrs = decl_abbrev_common_attrs ++ .{
5376 .{ .linkage_name, .strp },
5377 .{ .type, .ref_addr },
5378 .{ .alignment, .udata },
5379 .{ .external, .flag_present },
5380 },
5381 },
53635382 .decl_const = .{
53645383 .tag = .constant,
53655384 .attrs = decl_abbrev_common_attrs ++ .{
......@@ -5443,7 +5462,6 @@ const AbbrevCode = enum {
54435462 .attrs = decl_abbrev_common_attrs ++ .{
54445463 .{ .linkage_name, .strp },
54455464 .{ .type, .ref_addr },
5446 .{ .low_pc, .addr },
54475465 .{ .external, .flag_present },
54485466 .{ .noreturn, .flag },
54495467 },
......@@ -5454,7 +5472,6 @@ const AbbrevCode = enum {
54545472 .attrs = decl_abbrev_common_attrs ++ .{
54555473 .{ .linkage_name, .strp },
54565474 .{ .type, .ref_addr },
5457 .{ .low_pc, .addr },
54585475 .{ .external, .flag_present },
54595476 .{ .noreturn, .flag },
54605477 },
......@@ -5536,6 +5553,15 @@ const AbbrevCode = enum {
55365553 .{ .external, .flag },
55375554 },
55385555 },
5556 .decl_instance_extern_var = .{
5557 .tag = .variable,
5558 .attrs = decl_instance_abbrev_common_attrs ++ .{
5559 .{ .linkage_name, .strp },
5560 .{ .location, .exprloc },
5561 .{ .alignment, .udata },
5562 .{ .external, .flag_present },
5563 },
5564 },
55395565 .decl_instance_const = .{
55405566 .tag = .constant,
55415567 .attrs = decl_instance_abbrev_common_attrs ++ .{
......@@ -5619,7 +5645,6 @@ const AbbrevCode = enum {
56195645 .attrs = decl_instance_abbrev_common_attrs ++ .{
56205646 .{ .linkage_name, .strp },
56215647 .{ .type, .ref_addr },
5622 .{ .low_pc, .addr },
56235648 .{ .external, .flag_present },
56245649 .{ .noreturn, .flag },
56255650 },
......@@ -5630,7 +5655,6 @@ const AbbrevCode = enum {
56305655 .attrs = decl_instance_abbrev_common_attrs ++ .{
56315656 .{ .linkage_name, .strp },
56325657 .{ .type, .ref_addr },
5633 .{ .low_pc, .addr },
56345658 .{ .external, .flag_present },
56355659 .{ .noreturn, .flag },
56365660 },
......@@ -6048,7 +6072,6 @@ const AbbrevCode = enum {
60486072 .{ .ZIG_parent, .ref_addr },
60496073 .{ .linkage_name, .strp },
60506074 .{ .type, .ref_addr },
6051 .{ .low_pc, .addr },
60526075 .{ .external, .flag_present },
60536076 .{ .noreturn, .flag },
60546077 },
......@@ -6060,7 +6083,6 @@ const AbbrevCode = enum {
60606083 .{ .ZIG_parent, .ref_addr },
60616084 .{ .linkage_name, .strp },
60626085 .{ .type, .ref_addr },
6063 .{ .low_pc, .addr },
60646086 .{ .external, .flag_present },
60656087 .{ .noreturn, .flag },
60666088 },
......@@ -6071,7 +6093,6 @@ const AbbrevCode = enum {
60716093 .{ .ZIG_parent, .ref_addr },
60726094 .{ .linkage_name, .strp },
60736095 .{ .type, .ref_addr },
6074 .{ .location, .exprloc },
60756096 .{ .external, .flag_present },
60766097 },
60776098 },