authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-30 06:24:21-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-03 12:59:38-04:00
logf9ae1f808b9e8c1d9a0394505be222f8becf4259
tree974c16daf179bb5382149969d516008f1f1dd137
parenteecbd183ccca14f904eada0b909b70812a2c9cb8

Elf2: replace `trimStart` calls with an unconditional padding node

The trim strategy came from the old dwarf impl, but it does not work with the overaligned section node optimization.

2 files changed, 9 insertions(+), 34 deletions(-)

src/link/Elf2.zig+9-17
......@@ -7189,7 +7189,6 @@ fn prelinkInner(elf: *Elf) Error!void {
71897189 }) |debug_shndx| {
71907190 if (debug_shndx == .UNDEF) continue;
71917191 const debug_ni = debug_shndx.get(elf).ni;
7192 _ = debug_ni.last(&elf.mf).unwrap() orelse continue;
71937192 const frame_format = debug_shndx.debugFrameFormat(elf);
71947193 const unit_padding_ni = elf.addNodeAssumeCapacity(
71957194 try debug_ni.addFloatingChild(gpa, &elf.mf, .{
......@@ -8941,7 +8940,6 @@ fn updateFuncInner(
89418940 .debug_frame => elf.shndx.debug_frame,
89428941 .eh_frame => elf.shndx.eh_frame,
89438942 }.get(elf).ni;
8944 try frame_ni.trimStart(gpa, &elf.mf);
89458943 switch (wip_nav.frame_format) {
89468944 .debug_frame => {},
89478945 .eh_frame => {
......@@ -8953,11 +8951,6 @@ fn updateFuncInner(
89538951 },
89548952 .dwarf2 => |debug| {
89558953 try debug.finishFunc(func_length);
8956 for ([3]Section.Index{
8957 elf.shndx.debug_info,
8958 elf.shndx.debug_line,
8959 elf.shndx.debug_rnglists,
8960 }) |debug_shndx| try debug_shndx.get(elf).ni.trimStart(gpa, &elf.mf);
89618954 const unit = debug.wip_nav.unit.get(debug.wip_nav.dwarf);
89628955 {
89638956 const debug_info_ni = unit.debug_info_ni.unwrap().?;
......@@ -10928,19 +10921,21 @@ pub fn printNode(
1092810921 const zcu = elf.base.comp.zcu.?;
1092910922 const ip = &zcu.intern_pool;
1093010923 const nav = ip.getNav(gi.nav(&elf.dwarf));
10931 try w.print("({f}, {f})", .{
10932 Type.fromInterned(nav.resolved.?.type).fmt(.{ .zcu = zcu, .tid = tid }),
10933 nav.fqn.fmt(ip),
10924 try w.writeByte('(');
10925 if (nav.resolved) |resolved| try w.print("{f}, ", .{
10926 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
1093410927 });
10928 try w.print("{f})", .{nav.fqn.fmt(ip)});
1093510929 },
1093610930 .func_frame_fde, .func_debug_info, .func_debug_line => |fi| {
1093710931 const zcu = elf.base.comp.zcu.?;
1093810932 const ip = &zcu.intern_pool;
1093910933 const nav = ip.getNav(fi.nav(&elf.dwarf));
10940 try w.print("({f}, {f})", .{
10941 Type.fromInterned(nav.resolved.?.type).fmt(.{ .zcu = zcu, .tid = tid }),
10942 nav.fqn.fmt(ip),
10934 try w.writeByte('(');
10935 if (nav.resolved) |resolved| try w.print("{f}, ", .{
10936 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
1094310937 });
10938 try w.print("{f})", .{nav.fqn.fmt(ip)});
1094410939 },
1094510940 .decl_debug_info => |di| {
1094610941 const comp = elf.base.comp;
......@@ -10948,10 +10943,7 @@ pub fn printNode(
1094810943 const ip = &zcu.intern_pool;
1094910944 const src_inst = di.srcInst(&elf.dwarf);
1095010945 try w.print("({f}, ", .{zcu.fileByIndex(src_inst.resolveFile(ip)).path.fmt(comp)});
10951 if (src_inst.resolve(ip)) |inst|
10952 try w.print("%{d}", .{inst})
10953 else
10954 try w.writeAll("lost");
10946 if (src_inst.resolve(ip)) |inst| try w.print("%{d}", .{inst}) else try w.writeAll("lost");
1095510947 try w.writeByte(')');
1095610948 },
1095710949 }
src/link/MappedFile.zig-17
......@@ -664,23 +664,6 @@ pub const Node = extern struct {
664664 return true;
665665 }
666666
667 pub fn trimStart(ni: Node.Index, gpa: Allocator, mf: *MappedFile) Allocator.Error!void {
668 mf.nodes_lock.assertUnlocked();
669 const node = ni.get(mf);
670 const first_ni = node.first.unwrap() orelse return;
671 const shift, _ = first_ni.location(mf).resolve(mf);
672 if (shift == 0) return;
673 const offset, const size = node.location().resolve(mf);
674 try ni.setLocation(gpa, mf, offset + shift, size - shift);
675 var child_oni = node.first;
676 while (child_oni.unwrap()) |child_ni| {
677 const child_node = child_ni.get(mf);
678 const child_offset, const child_size = child_node.location().resolve(mf);
679 try child_ni.setLocation(gpa, mf, child_offset - shift, child_size);
680 child_oni = child_node.next;
681 }
682 }
683
684667 /// Ensures that the size of `ni` is at least `min_size`. Valid for any node.
685668 ///
686669 /// Applies `growth_factor` if necessary (so the caller should *not* apply `growth_factor`).