authorgravatar for abbix@riseup.netlg <abbix@riseup.net> 2026-08-31 14:29:03-04:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-16 12:41:28+01:00
logc39b73d375353f4e32fd4eb962c06a42e6ca929e
tree632fa9dddadebd536b79a4b320c22cdb62a36379
parent56eb5323106cccfea7a5212dd6ab2e66d35f3f64
signature Commit is signed but in an unrecognized format.

Elf2: make section nodes optional


1 files changed, 95 insertions(+), 88 deletions(-)

src/link/Elf2.zig+95-88
...@@ -492,7 +492,7 @@ const Archive = struct {...@@ -492,7 +492,7 @@ const Archive = struct {
492492
493const Section = struct {493const Section = struct {
494 /// The node corresponding to this section.494 /// The node corresponding to this section.
495 ni: MappedFile.Node.Index,495 ni: MappedFile.Node.Index.Optional,
496 /// A symbol which is exactly at the start of this section.496 /// A symbol which is exactly at the start of this section.
497 ///497 ///
498 /// When not emitting a relocatable, or for special section types, this is `.null`.498 /// When not emitting a relocatable, or for special section types, this is `.null`.
...@@ -596,6 +596,13 @@ const Section = struct {...@@ -596,6 +596,13 @@ const Section = struct {
596 return &elf.shdrs.items[@backingInt(shndx) - 1]; // overflow means you tried to get the `.UNDEF` section596 return &elf.shdrs.items[@backingInt(shndx) - 1]; // overflow means you tried to get the `.UNDEF` section
597 }597 }
598598
599 /// Convenience function for accessing a section's `MappedFile` node.
600 ///
601 /// Asserts that the section's `ni` is not `.none` (so, the section type is not `SHT_NOBITS`).
602 fn node(shndx: Index, elf: *Elf) MappedFile.Node.Index {
603 return shndx.get(elf).ni.unwrap().?;
604 }
605
599 fn name(shndx: Index, elf: *Elf) String(.shstrtab) {606 fn name(shndx: Index, elf: *Elf) String(.shstrtab) {
600 return switch (elf.shdrPtr(shndx)) {607 return switch (elf.shdrPtr(shndx)) {
601 inline else => |shdr| @fromBackingInt(elf.targetLoad(&shdr.name)),608 inline else => |shdr| @fromBackingInt(elf.targetLoad(&shdr.name)),
...@@ -648,7 +655,7 @@ const Section = struct {...@@ -648,7 +655,7 @@ const Section = struct {
648 elf.targetStore(&shdr.addralign, @intCast(min_align.toByteUnits()));655 elf.targetStore(&shdr.addralign, @intCast(min_align.toByteUnits()));
649 },656 },
650 }657 }
651 const ni = shndx.get(elf).ni;658 const ni = shndx.node(elf);
652 if (min_align.compare(.gt, ni.alignment(&elf.mf))) {659 if (min_align.compare(.gt, ni.alignment(&elf.mf))) {
653 try ni.realign(elf.base.comp.gpa, &elf.mf, min_align);660 try ni.realign(elf.base.comp.gpa, &elf.mf, min_align);
654 }661 }
...@@ -662,7 +669,7 @@ const Section = struct {...@@ -662,7 +669,7 @@ const Section = struct {
662 /// Asserts that `rela_shndx` is a `SHT_RELA` section and ensures that its node has enough669 /// Asserts that `rela_shndx` is a `SHT_RELA` section and ensures that its node has enough
663 /// unused space to hold `n` additional `ElfN.Rela` entries.670 /// unused space to hold `n` additional `ElfN.Rela` entries.
664 fn relaEnsureAdditionalCapacity(rela_shndx: Index, elf: *Elf, n: usize) Error!void {671 fn relaEnsureAdditionalCapacity(rela_shndx: Index, elf: *Elf, n: usize) Error!void {
665 const node = rela_shndx.get(elf).ni;672 const ni = rela_shndx.node(elf);
666 const need_size: u64 = switch (elf.shdrPtr(rela_shndx)) {673 const need_size: u64 = switch (elf.shdrPtr(rela_shndx)) {
667 inline else => |shdr, class| need_size: {674 inline else => |shdr, class| need_size: {
668 assert(elf.targetLoad(&shdr.type) == .RELA);675 assert(elf.targetLoad(&shdr.type) == .RELA);
...@@ -673,7 +680,7 @@ const Section = struct {...@@ -673,7 +680,7 @@ const Section = struct {
673 const opt_free_head = rela_shndx.get(elf).rela.free_head;680 const opt_free_head = rela_shndx.get(elf).rela.free_head;
674 const free_head = opt_free_head.unwrap() orelse break :free_len 0;681 const free_head = opt_free_head.unwrap() orelse break :free_len 0;
675 const relas: []const class.ElfN().Rela = @ptrCast(@alignCast(682 const relas: []const class.ElfN().Rela = @ptrCast(@alignCast(
676 node.slice(&elf.mf)[0..@intCast(cur_size)],683 ni.slice(&elf.mf)[0..@intCast(cur_size)],
677 ));684 ));
678 const free_len = elf.targetLoad(&relas[@backingInt(free_head)].addend);685 const free_len = elf.targetLoad(&relas[@backingInt(free_head)].addend);
679 assert(free_len > 0);686 assert(free_len > 0);
...@@ -683,7 +690,7 @@ const Section = struct {...@@ -683,7 +690,7 @@ const Section = struct {
683 break :need_size cur_size + need_additional * ent_size;690 break :need_size cur_size + need_additional * ent_size;
684 },691 },
685 };692 };
686 try node.ensureMinimumSize(elf.base.comp.gpa, &elf.mf, need_size);693 try ni.ensureMinimumSize(elf.base.comp.gpa, &elf.mf, need_size);
687 }694 }
688695
689 /// Asserts that `rela_shndx` is a `SHT_RELA` section and deletes the `ElfN.Rela` entry at696 /// Asserts that `rela_shndx` is a `SHT_RELA` section and deletes the `ElfN.Rela` entry at
...@@ -695,7 +702,7 @@ const Section = struct {...@@ -695,7 +702,7 @@ const Section = struct {
695 assert(elf.targetLoad(&shdr.type) == .RELA);702 assert(elf.targetLoad(&shdr.type) == .RELA);
696 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));703 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));
697 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(704 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
698 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],705 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
699 ));706 ));
700 const opt_free_head = rela_shndx.get(elf).rela.free_head;707 const opt_free_head = rela_shndx.get(elf).rela.free_head;
701 const old_free_len: u32 = free_len: {708 const old_free_len: u32 = free_len: {
...@@ -743,7 +750,7 @@ const Section = struct {...@@ -743,7 +750,7 @@ const Section = struct {
743 assert(elf.targetLoad(&shdr.entsize) == ent_size);750 assert(elf.targetLoad(&shdr.entsize) == ent_size);
744 const new_index: RelaIndex = if (rela_shndx.get(elf).rela.free_head.unwrap()) |free_head| new_index: {751 const new_index: RelaIndex = if (rela_shndx.get(elf).rela.free_head.unwrap()) |free_head| new_index: {
745 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(752 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
746 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],753 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
747 ));754 ));
748 const next: RelaIndex.Optional = @fromBackingInt(@intCast(elf.targetLoad(755 const next: RelaIndex.Optional = @fromBackingInt(@intCast(elf.targetLoad(
749 &relas[@backingInt(free_head)].offset,756 &relas[@backingInt(free_head)].offset,
...@@ -766,7 +773,7 @@ const Section = struct {...@@ -766,7 +773,7 @@ const Section = struct {
766 break :new_index @fromBackingInt(@intCast(@divExact(old_size, ent_size)));773 break :new_index @fromBackingInt(@intCast(@divExact(old_size, ent_size)));
767 };774 };
768 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(775 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
769 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],776 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
770 ));777 ));
771 relas[@backingInt(new_index)] = .{778 relas[@backingInt(new_index)] = .{
772 .offset = @intCast(opts.offset),779 .offset = @intCast(opts.offset),
...@@ -794,7 +801,7 @@ const Section = struct {...@@ -794,7 +801,7 @@ const Section = struct {
794 assert(elf.targetLoad(&shdr.type) == .RELA);801 assert(elf.targetLoad(&shdr.type) == .RELA);
795 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));802 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));
796 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(803 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
797 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],804 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
798 ));805 ));
799 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);806 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);
800 {807 {
...@@ -818,7 +825,7 @@ const Section = struct {...@@ -818,7 +825,7 @@ const Section = struct {
818 assert(elf.targetLoad(&shdr.type) == .RELA);825 assert(elf.targetLoad(&shdr.type) == .RELA);
819 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));826 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));
820 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(827 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
821 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],828 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
822 ));829 ));
823 {830 {
824 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);831 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);
...@@ -839,7 +846,7 @@ const Section = struct {...@@ -839,7 +846,7 @@ const Section = struct {
839 assert(elf.targetLoad(&shdr.type) == .RELA);846 assert(elf.targetLoad(&shdr.type) == .RELA);
840 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));847 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));
841 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(848 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
842 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],849 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
843 ));850 ));
844 {851 {
845 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);852 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);
...@@ -863,7 +870,7 @@ const Section = struct {...@@ -863,7 +870,7 @@ const Section = struct {
863 assert(elf.targetLoad(&shdr.type) == .RELA);870 assert(elf.targetLoad(&shdr.type) == .RELA);
864 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));871 assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela));
865 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(872 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
866 rela_shndx.get(elf).ni.slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],873 rela_shndx.node(elf).slice(&elf.mf)[0..@intCast(elf.targetLoad(&shdr.size))],
867 ));874 ));
868 {875 {
869 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);876 const rela_info = elf.targetLoad(&relas[@backingInt(index)].info);
...@@ -2220,7 +2227,7 @@ const GotReloc = struct {...@@ -2220,7 +2227,7 @@ const GotReloc = struct {
2220 fn apply(reloc: *GotReloc, elf: *Elf) void {2227 fn apply(reloc: *GotReloc, elf: *Elf) void {
2221 assert(elf.ehdrType() != .REL);2228 assert(elf.ehdrType() != .REL);
2222 const node = reloc.node.unwrap() orelse return; // deleted2229 const node = reloc.node.unwrap() orelse return; // deleted
2223 if (node.hasMoved(&elf.mf) or elf.shndx.got.get(elf).ni.hasMoved(&elf.mf)) {2230 if (node.hasMoved(&elf.mf) or elf.shndx.got.node(elf).hasMoved(&elf.mf)) {
2224 // There's no point applying the relocation now, because it will be re-applied by2231 // There's no point applying the relocation now, because it will be re-applied by
2225 // `flushMoved` at some point anyway.2232 // `flushMoved` at some point anyway.
2226 return;2233 return;
...@@ -2452,7 +2459,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {...@@ -2452,7 +2459,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {
2452 switch (elf.targetDynsymHashInfo()) {2459 switch (elf.targetDynsymHashInfo()) {
2453 inline else => |info| {2460 inline else => |info| {
2454 {2461 {
2455 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));2462 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
2456 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);2463 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);
2457 assert(elf.targetLoad(&header.nchain) == cur_dynsym_count);2464 assert(elf.targetLoad(&header.nchain) == cur_dynsym_count);
2458 const nbucket = elf.targetLoad(&header.nbucket);2465 const nbucket = elf.targetLoad(&header.nbucket);
...@@ -2460,7 +2467,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {...@@ -2460,7 +2467,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {
2460 // We don't need to add any buckets, but we still need to make sure the section is large2467 // We don't need to add any buckets, but we still need to make sure the section is large
2461 // enough to fit `max_dynsym_count` chains.2468 // enough to fit `max_dynsym_count` chains.
2462 const need_size = @sizeOf(info.Header()) + (nbucket + max_dynsym_count) * 4;2469 const need_size = @sizeOf(info.Header()) + (nbucket + max_dynsym_count) * 4;
2463 try elf.shndx.hash.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, need_size);2470 try elf.shndx.hash.node(elf).ensureMinimumSize(gpa, &elf.mf, need_size);
2464 return;2471 return;
2465 }2472 }
2466 // We need more buckets, so we'll have to rebuild the hash table.2473 // We need more buckets, so we'll have to rebuild the hash table.
...@@ -2472,13 +2479,13 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {...@@ -2472,13 +2479,13 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {
24722479
2473 {2480 {
2474 const need_size = @sizeOf(info.Header()) + (new_nbucket + max_dynsym_count) * 4;2481 const need_size = @sizeOf(info.Header()) + (new_nbucket + max_dynsym_count) * 4;
2475 try elf.shndx.hash.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, need_size);2482 try elf.shndx.hash.node(elf).ensureMinimumSize(gpa, &elf.mf, need_size);
2476 }2483 }
24772484
2478 elf.mf.nodes_lock.lock();2485 elf.mf.nodes_lock.lock();
2479 defer elf.mf.nodes_lock.unlock();2486 defer elf.mf.nodes_lock.unlock();
24802487
2481 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));2488 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
2482 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);2489 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);
2483 const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]);2490 const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]);
24842491
...@@ -2508,7 +2515,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {...@@ -2508,7 +2515,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void {
2508fn appendDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {2515fn appendDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {
2509 switch (elf.targetDynsymHashInfo()) {2516 switch (elf.targetDynsymHashInfo()) {
2510 inline else => |info| {2517 inline else => |info| {
2511 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));2518 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
2512 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);2519 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);
2513 assert(elf.targetLoad(&header.nchain) == dynsym_index);2520 assert(elf.targetLoad(&header.nchain) == dynsym_index);
2514 elf.targetStore(&header.nchain, dynsym_index + 1);2521 elf.targetStore(&header.nchain, dynsym_index + 1);
...@@ -2529,7 +2536,7 @@ fn populateDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {...@@ -2529,7 +2536,7 @@ fn populateDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {
25292536
2530 switch (elf.targetDynsymHashInfo()) {2537 switch (elf.targetDynsymHashInfo()) {
2531 inline else => |info| {2538 inline else => |info| {
2532 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));2539 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
2533 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);2540 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);
2534 const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]);2541 const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]);
25352542
...@@ -2551,7 +2558,7 @@ fn popDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {...@@ -2551,7 +2558,7 @@ fn popDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {
25512558
2552 switch (elf.targetDynsymHashInfo()) {2559 switch (elf.targetDynsymHashInfo()) {
2553 inline else => |info| {2560 inline else => |info| {
2554 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));2561 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
2555 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);2562 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);
2556 assert(elf.targetLoad(&header.nchain) == dynsym_index + 1);2563 assert(elf.targetLoad(&header.nchain) == dynsym_index + 1);
2557 elf.targetStore(&header.nchain, dynsym_index);2564 elf.targetStore(&header.nchain, dynsym_index);
...@@ -2570,7 +2577,7 @@ fn clearDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {...@@ -2570,7 +2577,7 @@ fn clearDynsymHashEntry(elf: *Elf, dynsym_index: u32) void {
25702577
2571 switch (elf.targetDynsymHashInfo()) {2578 switch (elf.targetDynsymHashInfo()) {
2572 inline else => |info| {2579 inline else => |info| {
2573 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));2580 const section_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
2574 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);2581 const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]);
2575 const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]);2582 const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]);
25762583
...@@ -2615,7 +2622,7 @@ fn pltEntryIsDead(elf: *Elf, plt_index: usize) bool {...@@ -2615,7 +2622,7 @@ fn pltEntryIsDead(elf: *Elf, plt_index: usize) bool {
2615 inline else => |rela_shdr, class| {2622 inline else => |rela_shdr, class| {
2616 const size = elf.targetLoad(&rela_shdr.size);2623 const size = elf.targetLoad(&rela_shdr.size);
2617 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(2624 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
2618 elf.shndx.rela_plt.get(elf).ni.slice(&elf.mf)[0..@intCast(size)],2625 elf.shndx.rela_plt.node(elf).slice(&elf.mf)[0..@intCast(size)],
2619 ));2626 ));
2620 const rel_type = elf.targetLoad(&relas[plt_index].info).type;2627 const rel_type = elf.targetLoad(&relas[plt_index].info).type;
2621 return rel_type == MachineRelocType.none(elf).unwrap(elf);2628 return rel_type == MachineRelocType.none(elf).unwrap(elf);
...@@ -2636,7 +2643,7 @@ fn addLocalSymbol(elf: *Elf, opts: AddLocalSymbolOptions) Error!Symbol.LocalInde...@@ -2636,7 +2643,7 @@ fn addLocalSymbol(elf: *Elf, opts: AddLocalSymbolOptions) Error!Symbol.LocalInde
26362643
2637 try elf.symtab.ensureUnusedCapacity(gpa, 1);2644 try elf.symtab.ensureUnusedCapacity(gpa, 1);
2638 try elf.changed_symtab_index.ensureUnusedCapacity(gpa, 1);2645 try elf.changed_symtab_index.ensureUnusedCapacity(gpa, 1);
2639 try Section.Index.symtab.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, switch (elf.shdrPtr(.symtab)) {2646 try Section.Index.symtab.node(elf).ensureMinimumSize(gpa, &elf.mf, switch (elf.shdrPtr(.symtab)) {
2640 inline else => |shdr, class| elf.targetLoad(&shdr.size) + @sizeOf(class.ElfN().Sym),2647 inline else => |shdr, class| elf.targetLoad(&shdr.size) + @sizeOf(class.ElfN().Sym),
2641 });2648 });
26422649
...@@ -2715,7 +2722,7 @@ fn addGlobalSymbol(elf: *Elf, opts: Symbol.Global.AddOptions) (error{...@@ -2715,7 +2722,7 @@ fn addGlobalSymbol(elf: *Elf, opts: Symbol.Global.AddOptions) (error{
2715 try elf.globals_by_name.ensureUnusedCapacity(gpa, 1);2722 try elf.globals_by_name.ensureUnusedCapacity(gpa, 1);
2716 try elf.node_global_symbols.ensureUnusedCapacity(gpa, 1);2723 try elf.node_global_symbols.ensureUnusedCapacity(gpa, 1);
27172724
2718 try Section.Index.symtab.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, switch (elf.shdrPtr(.symtab)) {2725 try Section.Index.symtab.node(elf).ensureMinimumSize(gpa, &elf.mf, switch (elf.shdrPtr(.symtab)) {
2719 inline else => |shdr, class| elf.targetLoad(&shdr.size) + @sizeOf(class.ElfN().Sym),2726 inline else => |shdr, class| elf.targetLoad(&shdr.size) + @sizeOf(class.ElfN().Sym),
2720 });2727 });
27212728
...@@ -3059,8 +3066,8 @@ fn updateGlobalDynamic(elf: *Elf, orig_gsi: Symbol.Global.Index, force_apply_rel...@@ -3059,8 +3066,8 @@ fn updateGlobalDynamic(elf: *Elf, orig_gsi: Symbol.Global.Index, force_apply_rel
3059 };3066 };
3060 const need_dynsym_len: u32 = @intCast(@divExact(dynsym_size, dynsym_ent_size) + 1);3067 const need_dynsym_len: u32 = @intCast(@divExact(dynsym_size, dynsym_ent_size) + 1);
30613068
3062 try elf.shndx.dynsym.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, need_dynsym_len * dynsym_ent_size);3069 try elf.shndx.dynsym.node(elf).ensureMinimumSize(gpa, &elf.mf, need_dynsym_len * dynsym_ent_size);
3063 try elf.shndx.gnu_version.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, need_dynsym_len * 2);3070 try elf.shndx.gnu_version.node(elf).ensureMinimumSize(gpa, &elf.mf, need_dynsym_len * 2);
3064 try elf.ensureDynsymHashCapacity(need_dynsym_len);3071 try elf.ensureDynsymHashCapacity(need_dynsym_len);
30653072
3066 const dynstr_name: String(.dynstr) = name: {3073 const dynstr_name: String(.dynstr) = name: {
...@@ -3246,7 +3253,7 @@ fn updateGlobalDynamic(elf: *Elf, orig_gsi: Symbol.Global.Index, force_apply_rel...@@ -3246,7 +3253,7 @@ fn updateGlobalDynamic(elf: *Elf, orig_gsi: Symbol.Global.Index, force_apply_rel
3246 errdefer assert(elf.copied_globals.pop().?.key == gsi);3253 errdefer assert(elf.copied_globals.pop().?.key == gsi);
3247 try elf.nodes.ensureUnusedCapacity(gpa, 1);3254 try elf.nodes.ensureUnusedCapacity(gpa, 1);
3248 const node = elf.addNodeAssumeCapacity(3255 const node = elf.addNodeAssumeCapacity(
3249 try shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{3256 try shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
3250 .size = dso_global.alignment.forward(dso_global.size),3257 .size = dso_global.alignment.forward(dso_global.size),
3251 .alignment = dso_global.alignment,3258 .alignment = dso_global.alignment,
3252 }),3259 }),
...@@ -4295,7 +4302,7 @@ fn lazySymbolInner(elf: *Elf, lazy: link.File.LazySymbol) Error!link.File.Symbol...@@ -4295,7 +4302,7 @@ fn lazySymbolInner(elf: *Elf, lazy: link.File.LazySymbol) Error!link.File.Symbol
4295 .const_data => .{ .rodata, .OBJECT },4302 .const_data => .{ .rodata, .OBJECT },
4296 };4303 };
4297 const node = elf.addNodeAssumeCapacity(4304 const node = elf.addNodeAssumeCapacity(
4298 try shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),4305 try shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{}),
4299 switch (lazy.kind) {4306 switch (lazy.kind) {
4300 .code => .{ .lazy_code = @fromBackingInt(@intCast(gop.index)) },4307 .code => .{ .lazy_code = @fromBackingInt(@intCast(gop.index)) },
4301 .const_data => .{ .lazy_const_data = @fromBackingInt(@intCast(gop.index)) },4308 .const_data => .{ .lazy_const_data = @fromBackingInt(@intCast(gop.index)) },
...@@ -4472,7 +4479,7 @@ fn String(section: StringSection) type {...@@ -4472,7 +4479,7 @@ fn String(section: StringSection) type {
4472 _,4479 _,
44734480
4474 fn slice(str: @This(), elf: *Elf) [:0]const u8 {4481 fn slice(str: @This(), elf: *Elf) [:0]const u8 {
4475 const section_node = section.shndx(elf).get(elf).ni;4482 const section_node = section.shndx(elf).node(elf);
4476 const overlong = section_node.sliceConst(&elf.mf)[@backingInt(str)..];4483 const overlong = section_node.sliceConst(&elf.mf)[@backingInt(str)..];
4477 return overlong[0..std.mem.findScalar(u8, overlong, 0).? :0];4484 return overlong[0..std.mem.findScalar(u8, overlong, 0).? :0];
4478 }4485 }
...@@ -4532,14 +4539,14 @@ const StringTable = struct {...@@ -4532,14 +4539,14 @@ const StringTable = struct {
45324539
4533 fn getExisting(st: *StringTable, elf: *Elf, shndx: Section.Index, key: []const u8) u32 {4540 fn getExisting(st: *StringTable, elf: *Elf, shndx: Section.Index, key: []const u8) u32 {
4534 if (key.len == 0) return 0;4541 if (key.len == 0) return 0;
4535 const slice_const = shndx.get(elf).ni.sliceConst(&elf.mf);4542 const slice_const = shndx.node(elf).sliceConst(&elf.mf);
4536 const adapter: StringTable.Adapter = .{ .slice = slice_const };4543 const adapter: StringTable.Adapter = .{ .slice = slice_const };
4537 return st.map.getKeyAdapted(key, adapter).?;4544 return st.map.getKeyAdapted(key, adapter).?;
4538 }4545 }
45394546
4540 fn ensureAdditionalCapacity(st: *StringTable, elf: *Elf, shndx: Section.Index, string_len: usize) Error!void {4547 fn ensureAdditionalCapacity(st: *StringTable, elf: *Elf, shndx: Section.Index, string_len: usize) Error!void {
4541 const gpa = elf.base.comp.gpa;4548 const gpa = elf.base.comp.gpa;
4542 const ni = shndx.get(elf).ni;4549 const ni = shndx.node(elf);
4543 const slice_const = ni.sliceConst(&elf.mf);4550 const slice_const = ni.sliceConst(&elf.mf);
4544 try st.map.ensureUnusedCapacityContext(gpa, 1, .{ .slice = slice_const });4551 try st.map.ensureUnusedCapacityContext(gpa, 1, .{ .slice = slice_const });
4545 const size: u64 = switch (elf.shdrPtr(shndx)) {4552 const size: u64 = switch (elf.shdrPtr(shndx)) {
...@@ -4553,7 +4560,7 @@ const StringTable = struct {...@@ -4553,7 +4560,7 @@ const StringTable = struct {
4553 // case the empty string.4560 // case the empty string.
4554 if (key.len == 0) return 0;4561 if (key.len == 0) return 0;
45554562
4556 const ni = shndx.get(elf).ni;4563 const ni = shndx.node(elf);
4557 const slice_const = ni.sliceConst(&elf.mf);4564 const slice_const = ni.sliceConst(&elf.mf);
4558 const gop = st.map.getOrPutAssumeCapacityAdapted(4565 const gop = st.map.getOrPutAssumeCapacityAdapted(
4559 key,4566 key,
...@@ -5476,7 +5483,7 @@ fn initHeaders(...@@ -5476,7 +5483,7 @@ fn initHeaders(
5476 .node_align = node_block_align,5483 .node_align = node_block_align,
5477 .manual_size = true,5484 .manual_size = true,
5478 }));5485 }));
5479 Section.Index.get(.shstrtab, elf).ni.slice(&elf.mf)[0] = 0;5486 Section.Index.shstrtab.node(elf).slice(&elf.mf)[0] = 0;
54805487
5481 try Section.Index.symtab.rename(elf, ".symtab");5488 try Section.Index.symtab.rename(elf, ".symtab");
5482 try Section.Index.shstrtab.rename(elf, ".shstrtab");5489 try Section.Index.shstrtab.rename(elf, ".shstrtab");
...@@ -5489,7 +5496,7 @@ fn initHeaders(...@@ -5489,7 +5496,7 @@ fn initHeaders(
5489 .node_align = node_block_align,5496 .node_align = node_block_align,
5490 .manual_size = true,5497 .manual_size = true,
5491 }));5498 }));
5492 Section.Index.get(.strtab, elf).ni.slice(&elf.mf)[0] = 0;5499 Section.Index.strtab.node(elf).slice(&elf.mf)[0] = 0;
5493 switch (elf.shdrPtr(.symtab)) {5500 switch (elf.shdrPtr(.symtab)) {
5494 inline else => |shdr| elf.targetStore(&shdr.link, @backingInt(Section.Index.strtab)),5501 inline else => |shdr| elf.targetStore(&shdr.link, @backingInt(Section.Index.strtab)),
5495 }5502 }
...@@ -5595,7 +5602,7 @@ fn initHeaders(...@@ -5595,7 +5602,7 @@ fn initHeaders(
5595 .flags = .{ .ALLOC = true },5602 .flags = .{ .ALLOC = true },
5596 .size = @intCast(interp.len + 1),5603 .size = @intCast(interp.len + 1),
5597 });5604 });
5598 const sec_interp = sec_interp_shndx.get(elf).ni.slice(&elf.mf);5605 const sec_interp = sec_interp_shndx.node(elf).slice(&elf.mf);
5599 @memcpy(sec_interp[0..interp.len], interp);5606 @memcpy(sec_interp[0..interp.len], interp);
5600 sec_interp[interp.len] = 0;5607 sec_interp[interp.len] = 0;
5601 }5608 }
...@@ -5620,7 +5627,7 @@ fn initHeaders(...@@ -5620,7 +5627,7 @@ fn initHeaders(
5620 .node_align = node_block_align,5627 .node_align = node_block_align,
5621 .manual_size = true,5628 .manual_size = true,
5622 });5629 });
5623 dynstr_shndx.get(elf).ni.slice(&elf.mf)[0] = 0;5630 dynstr_shndx.node(elf).slice(&elf.mf)[0] = 0;
5624 elf.shndx.dynstr = dynstr_shndx;5631 elf.shndx.dynstr = dynstr_shndx;
56255632
5626 switch (class) {5633 switch (class) {
...@@ -5765,7 +5772,7 @@ fn initHeaders(...@@ -5765,7 +5772,7 @@ fn initHeaders(
5765 .size = @sizeOf(info.Header()) + @sizeOf(info.Int()) * (8 + 1),5772 .size = @sizeOf(info.Header()) + @sizeOf(info.Int()) * (8 + 1),
5766 .manual_size = true,5773 .manual_size = true,
5767 });5774 });
5768 const hash_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.get(elf).ni.slice(&elf.mf));5775 const hash_slice: []align(@sizeOf(info.Int())) u8 = @alignCast(elf.shndx.hash.node(elf).slice(&elf.mf));
5769 const header: *info.Header() = @ptrCast(hash_slice[0..@sizeOf(info.Header())]);5776 const header: *info.Header() = @ptrCast(hash_slice[0..@sizeOf(info.Header())]);
5770 header.* = .{ .nbucket = 8, .nchain = 1 };5777 header.* = .{ .nbucket = 8, .nchain = 1 };
5771 if (elf.targetEndian() != std.lang.Endian.native) {5778 if (elf.targetEndian() != std.lang.Endian.native) {
...@@ -5779,7 +5786,7 @@ fn initHeaders(...@@ -5779,7 +5786,7 @@ fn initHeaders(
5779 switch (machine) {5786 switch (machine) {
5780 .AARCH64, .PPC64, .RISCV => @panic(@tagName(machine)),5787 .AARCH64, .PPC64, .RISCV => @panic(@tagName(machine)),
5781 .X86_64 => {5788 .X86_64 => {
5782 const plt_ni = elf.shndx.plt.get(elf).ni;5789 const plt_ni = elf.shndx.plt.node(elf);
5783 const got_plt_sym: Symbol.Id = .local(elf.shndx.got_plt.get(elf).lsi);5790 const got_plt_sym: Symbol.Id = .local(elf.shndx.got_plt.get(elf).lsi);
5784 @memcpy(plt_ni.slice(&elf.mf)[0..16], &[16]u8{5791 @memcpy(plt_ni.slice(&elf.mf)[0..16], &[16]u8{
5785 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // push 0x0(%rip)5792 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // push 0x0(%rip)
...@@ -5804,7 +5811,7 @@ fn initHeaders(...@@ -5804,7 +5811,7 @@ fn initHeaders(
5804 );5811 );
5805 },5812 },
5806 .LOONGARCH => {5813 .LOONGARCH => {
5807 const plt_ni = elf.shndx.plt.get(elf).ni;5814 const plt_ni = elf.shndx.plt.node(elf);
5808 const got_plt_sym: Symbol.Id = .local(elf.shndx.got_plt.get(elf).lsi);5815 const got_plt_sym: Symbol.Id = .local(elf.shndx.got_plt.get(elf).lsi);
5809 @memcpy(plt_ni.slice(&elf.mf)[0..32], switch (class) {5816 @memcpy(plt_ni.slice(&elf.mf)[0..32], switch (class) {
5810 .NONE, _ => unreachable,5817 .NONE, _ => unreachable,
...@@ -5881,7 +5888,7 @@ fn initHeaders(...@@ -5881,7 +5888,7 @@ fn initHeaders(
5881 .manual_size = true,5888 .manual_size = true,
5882 });5889 });
58835890
5884 const eh_frame_hdr_ni = elf.shndx.eh_frame_hdr.get(elf).ni;5891 const eh_frame_hdr_ni = elf.shndx.eh_frame_hdr.node(elf);
5885 elf.eh_frame_hdr_first_symbol_reloc =5892 elf.eh_frame_hdr_first_symbol_reloc =
5886 @fromBackingInt(@intCast(elf.symbol_relocs.items.len));5893 @fromBackingInt(@intCast(elf.symbol_relocs.items.len));
5887 try elf.dwarf.genEhFrameHdr(5894 try elf.dwarf.genEhFrameHdr(
...@@ -5890,7 +5897,7 @@ fn initHeaders(...@@ -5890,7 +5897,7 @@ fn initHeaders(
5890 Symbol.Id.local(elf.shndx.eh_frame.get(elf).lsi).toTypeErased(),5897 Symbol.Id.local(elf.shndx.eh_frame.get(elf).lsi).toTypeErased(),
5891 );5898 );
5892 _ = elf.addNodeAssumeCapacity(5899 _ = elf.addNodeAssumeCapacity(
5893 try elf.shndx.eh_frame.get(elf).ni.addOnlyFooterChild(gpa, &elf.mf, .{5900 try elf.shndx.eh_frame.node(elf).addOnlyFooterChild(gpa, &elf.mf, .{
5894 .size = addr_align.forward(4),5901 .size = addr_align.forward(4),
5895 .alignment = addr_align,5902 .alignment = addr_align,
5896 }),5903 }),
...@@ -5937,7 +5944,7 @@ fn initHeaders(...@@ -5937,7 +5944,7 @@ fn initHeaders(
59375944
5938 // Despite the name, `__dso_handle` is necessary even in static binaries.5945 // Despite the name, `__dso_handle` is necessary even in static binaries.
5939 _ = elf.addGlobalSymbol(.{5946 _ = elf.addGlobalSymbol(.{
5940 .node = .wrap(Section.Index.text.get(elf).ni),5947 .node = .wrap(Section.Index.text.node(elf)),
5941 .name = "__dso_handle",5948 .name = "__dso_handle",
5942 .value = Section.Index.text.vaddr(elf),5949 .value = Section.Index.text.vaddr(elf),
5943 .size = 0,5950 .size = 0,
...@@ -5952,7 +5959,7 @@ fn initHeaders(...@@ -5952,7 +5959,7 @@ fn initHeaders(
5952 else => |e| return e,5959 else => |e| return e,
5953 };5960 };
5954 _ = elf.addGlobalSymbol(.{5961 _ = elf.addGlobalSymbol(.{
5955 .node = .wrap(elf.shndx.plt.get(elf).ni),5962 .node = .wrap(elf.shndx.plt.node(elf)),
5956 .name = "_PROCEDURE_LINKAGE_TABLE_",5963 .name = "_PROCEDURE_LINKAGE_TABLE_",
5957 .value = elf.shndx.plt.vaddr(elf),5964 .value = elf.shndx.plt.vaddr(elf),
5958 .size = 0,5965 .size = 0,
...@@ -5967,7 +5974,7 @@ fn initHeaders(...@@ -5967,7 +5974,7 @@ fn initHeaders(
5967 else => |e| return e,5974 else => |e| return e,
5968 };5975 };
5969 _ = elf.addGlobalSymbol(.{5976 _ = elf.addGlobalSymbol(.{
5970 .node = .wrap(elf.shndx.got.get(elf).ni),5977 .node = .wrap(elf.shndx.got.node(elf)),
5971 .name = "_GLOBAL_OFFSET_TABLE_",5978 .name = "_GLOBAL_OFFSET_TABLE_",
5972 .value = switch (machine) {5979 .value = switch (machine) {
5973 .AARCH64,5980 .AARCH64,
...@@ -6085,7 +6092,7 @@ fn initHeaders(...@@ -6085,7 +6092,7 @@ fn initHeaders(
6085 };6092 };
6086 if (have_dynamic) {6093 if (have_dynamic) {
6087 _ = elf.addGlobalSymbol(.{6094 _ = elf.addGlobalSymbol(.{
6088 .node = .wrap(elf.shndx.dynamic.get(elf).ni),6095 .node = .wrap(elf.shndx.dynamic.node(elf)),
6089 .name = "_DYNAMIC",6096 .name = "_DYNAMIC",
6090 .value = elf.shndx.dynamic.vaddr(elf),6097 .value = elf.shndx.dynamic.vaddr(elf),
6091 .size = 0,6098 .size = 0,
...@@ -6868,7 +6875,7 @@ const SymPtr = union(std.elf.CLASS) {...@@ -6868,7 +6875,7 @@ const SymPtr = union(std.elf.CLASS) {
6868 @"64": *std.elf.Elf64.Sym,6875 @"64": *std.elf.Elf64.Sym,
6869};6876};
6870fn symPtr(elf: *Elf, index: Symbol.Index) SymPtr {6877fn symPtr(elf: *Elf, index: Symbol.Index) SymPtr {
6871 const raw_slice = Section.Index.symtab.get(elf).ni.slice(&elf.mf);6878 const raw_slice = Section.Index.symtab.node(elf).slice(&elf.mf);
6872 switch (elf.shdrPtr(.symtab)) {6879 switch (elf.shdrPtr(.symtab)) {
6873 inline else => |shdr, class| {6880 inline else => |shdr, class| {
6874 const size = elf.targetLoad(&shdr.size);6881 const size = elf.targetLoad(&shdr.size);
...@@ -6878,7 +6885,7 @@ fn symPtr(elf: *Elf, index: Symbol.Index) SymPtr {...@@ -6878,7 +6885,7 @@ fn symPtr(elf: *Elf, index: Symbol.Index) SymPtr {
6878 }6885 }
6879}6886}
6880fn dynsymPtr(elf: *Elf, index: u32) SymPtr {6887fn dynsymPtr(elf: *Elf, index: u32) SymPtr {
6881 const raw_slice = elf.shndx.dynsym.get(elf).ni.slice(&elf.mf);6888 const raw_slice = elf.shndx.dynsym.node(elf).slice(&elf.mf);
6882 switch (elf.shdrPtr(elf.shndx.dynsym)) {6889 switch (elf.shdrPtr(elf.shndx.dynsym)) {
6883 inline else => |shdr, class| {6890 inline else => |shdr, class| {
6884 const size = elf.targetLoad(&shdr.size);6891 const size = elf.targetLoad(&shdr.size);
...@@ -6889,7 +6896,7 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {...@@ -6889,7 +6896,7 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {
6889}6896}
68906897
6891fn versymSlice(elf: *Elf) []std.elf.Versym {6898fn versymSlice(elf: *Elf) []std.elf.Versym {
6892 const raw_slice = elf.shndx.gnu_version.get(elf).ni.slice(&elf.mf);6899 const raw_slice = elf.shndx.gnu_version.node(elf).slice(&elf.mf);
6893 const size = elf.shndx.gnu_version.size(elf);6900 const size = elf.shndx.gnu_version.size(elf);
6894 return @ptrCast(@alignCast(raw_slice[0..@intCast(size)]));6901 return @ptrCast(@alignCast(raw_slice[0..@intCast(size)]));
6895}6902}
...@@ -6903,7 +6910,7 @@ const VerdefEntry = extern struct {...@@ -6903,7 +6910,7 @@ const VerdefEntry = extern struct {
6903 aux: std.elf.Verdaux,6910 aux: std.elf.Verdaux,
6904};6911};
6905fn verdefSlice(elf: *Elf) []VerdefEntry {6912fn verdefSlice(elf: *Elf) []VerdefEntry {
6906 const raw_slice = elf.shndx.gnu_version_d.get(elf).ni.slice(&elf.mf);6913 const raw_slice = elf.shndx.gnu_version_d.node(elf).slice(&elf.mf);
6907 const size = elf.shndx.gnu_version_d.size(elf);6914 const size = elf.shndx.gnu_version_d.size(elf);
6908 return @ptrCast(@alignCast(raw_slice[0..@intCast(size)]));6915 return @ptrCast(@alignCast(raw_slice[0..@intCast(size)]));
6909}6916}
...@@ -6916,7 +6923,7 @@ const VerneedEntry = extern union {...@@ -6916,7 +6923,7 @@ const VerneedEntry = extern union {
6916 }6923 }
6917};6924};
6918fn verneedSlice(elf: *Elf) []VerneedEntry {6925fn verneedSlice(elf: *Elf) []VerneedEntry {
6919 const raw_slice = elf.shndx.gnu_version_r.get(elf).ni.slice(&elf.mf);6926 const raw_slice = elf.shndx.gnu_version_r.node(elf).slice(&elf.mf);
6920 const size = elf.shndx.gnu_version_r.size(elf);6927 const size = elf.shndx.gnu_version_r.size(elf);
6921 return @ptrCast(@alignCast(raw_slice[0..@intCast(size)]));6928 return @ptrCast(@alignCast(raw_slice[0..@intCast(size)]));
6922}6929}
...@@ -7101,7 +7108,7 @@ fn navMapIndex(elf: *Elf, zcu: *Zcu, nav_index: InternPool.Nav.Index) Error!Node...@@ -7101,7 +7108,7 @@ fn navMapIndex(elf: *Elf, zcu: *Zcu, nav_index: InternPool.Nav.Index) Error!Node
7101 },7108 },
7102 };7109 };
7103 try shndx.ensureAligned(elf, alignment);7110 try shndx.ensureAligned(elf, alignment);
7104 const node = elf.addNodeAssumeCapacity(try shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{7111 const node = elf.addNodeAssumeCapacity(try shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
7105 .alignment = alignment,7112 .alignment = alignment,
7106 }), .{ .nav = nmi });7113 }), .{ .nav = nmi });
7107 nav_gop.value_ptr.* = .{7114 nav_gop.value_ptr.* = .{
...@@ -7143,7 +7150,7 @@ fn uavMapIndex(...@@ -7143,7 +7150,7 @@ fn uavMapIndex(
7143 if (!uav_gop.found_existing) {7150 if (!uav_gop.found_existing) {
7144 const shndx: Section.Index = .data_rel_ro; // TODO: it would be better to use `.rodata` if the UAV value doesn't have relocs7151 const shndx: Section.Index = .data_rel_ro; // TODO: it would be better to use `.rodata` if the UAV value doesn't have relocs
7145 try shndx.ensureAligned(elf, resolved_align);7152 try shndx.ensureAligned(elf, resolved_align);
7146 const node = elf.addNodeAssumeCapacity(try shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{7153 const node = elf.addNodeAssumeCapacity(try shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
7147 .moved = true, // see assert at end of `genUav`7154 .moved = true, // see assert at end of `genUav`
7148 .alignment = resolved_align,7155 .alignment = resolved_align,
7149 }), .{ .uav = umi });7156 }), .{ .uav = umi });
...@@ -7603,7 +7610,7 @@ fn loadObject(...@@ -7603,7 +7610,7 @@ fn loadObject(
7603 };7610 };
7604 const ni = elf.addNodeAssumeCapacity(7611 const ni = elf.addNodeAssumeCapacity(
7605 if (opts.node_fixed) ni: {7612 if (opts.node_fixed) ni: {
7606 const shndx_ni = opts.shndx.get(elf).ni;7613 const shndx_ni = opts.shndx.node(elf);
7607 const after_oni: MappedFile.Node.Index.Optional = after: {7614 const after_oni: MappedFile.Node.Index.Optional = after: {
7608 const last_ni = shndx_ni.last(&elf.mf).unwrap() orelse break :after .none;7615 const last_ni = shndx_ni.last(&elf.mf).unwrap() orelse break :after .none;
7609 break :after switch (last_ni.position(&elf.mf)) {7616 break :after switch (last_ni.position(&elf.mf)) {
...@@ -7612,7 +7619,7 @@ fn loadObject(...@@ -7612,7 +7619,7 @@ fn loadObject(
7612 };7619 };
7613 };7620 };
7614 break :ni try shndx_ni.addHeaderChildAfter(gpa, &elf.mf, after_oni, add_node_opts);7621 break :ni try shndx_ni.addHeaderChildAfter(gpa, &elf.mf, after_oni, add_node_opts);
7615 } else try opts.shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, add_node_opts),7622 } else try opts.shndx.node(elf).addFloatingChild(gpa, &elf.mf, add_node_opts),
7616 .{ .input_section = @fromBackingInt(@intCast(elf.input_sections.items.len)) },7623 .{ .input_section = @fromBackingInt(@intCast(elf.input_sections.items.len)) },
7617 );7624 );
7618 section.isi = @fromBackingInt(@intCast(elf.input_sections.items.len));7625 section.isi = @fromBackingInt(@intCast(elf.input_sections.items.len));
...@@ -8327,7 +8334,7 @@ fn createInitFiniArraySection(...@@ -8327,7 +8334,7 @@ fn createInitFiniArraySection(
8327 .version = null,8334 .version = null,
8328 }).?;8335 }).?;
8329 try elf.setGlobalSymbolValue(start_gsi, .{8336 try elf.setGlobalSymbolValue(start_gsi, .{
8330 .node = .wrap(shndx.get(elf).ni),8337 .node = .wrap(shndx.node(elf)),
8331 .value = shndx.vaddr(elf),8338 .value = shndx.vaddr(elf),
8332 .size = 0,8339 .size = 0,
8333 .type = .NOTYPE,8340 .type = .NOTYPE,
...@@ -8335,7 +8342,7 @@ fn createInitFiniArraySection(...@@ -8335,7 +8342,7 @@ fn createInitFiniArraySection(
8335 });8342 });
8336 try elf.updateGlobalDynamic(start_gsi, true);8343 try elf.updateGlobalDynamic(start_gsi, true);
8337 try elf.setGlobalSymbolValue(end_gsi, .{8344 try elf.setGlobalSymbolValue(end_gsi, .{
8338 .node = .wrap(shndx.get(elf).ni),8345 .node = .wrap(shndx.node(elf)),
8339 .value = shndx.vaddr(elf),8346 .value = shndx.vaddr(elf),
8340 .size = 0,8347 .size = 0,
8341 .type = .NOTYPE,8348 .type = .NOTYPE,
...@@ -8388,7 +8395,7 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -8388,7 +8395,7 @@ fn prelinkInner(elf: *Elf) Error!void {
8388 elf.shndx.debug_str_offsets,8395 elf.shndx.debug_str_offsets,
8389 }) |debug_shndx| {8396 }) |debug_shndx| {
8390 if (debug_shndx == .UNDEF) continue;8397 if (debug_shndx == .UNDEF) continue;
8391 const debug_ni = debug_shndx.get(elf).ni;8398 const debug_ni = debug_shndx.node(elf);
8392 const frame_format = debug_shndx.debugFrameFormat(elf);8399 const frame_format = debug_shndx.debugFrameFormat(elf);
8393 const unit_padding_ni = elf.addNodeAssumeCapacity(8400 const unit_padding_ni = elf.addNodeAssumeCapacity(
8394 try debug_ni.addHeaderChildAfter(gpa, &elf.mf, last_header_oni: {8401 try debug_ni.addHeaderChildAfter(gpa, &elf.mf, last_header_oni: {
...@@ -8444,7 +8451,7 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -8444,7 +8451,7 @@ fn prelinkInner(elf: *Elf) Error!void {
8444 .UNDEF => {},8451 .UNDEF => {},
8445 else => |debug_addr_shndx| {8452 else => |debug_addr_shndx| {
8446 const debug_addr_ni = elf.addNodeAssumeCapacity(8453 const debug_addr_ni = elf.addNodeAssumeCapacity(
8447 try debug_addr_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{8454 try debug_addr_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
8448 .alignment = addr_align,8455 .alignment = addr_align,
8449 .next_moved = true,8456 .next_moved = true,
8450 .enable_next_moved = true,8457 .enable_next_moved = true,
...@@ -8465,7 +8472,7 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -8465,7 +8472,7 @@ fn prelinkInner(elf: *Elf) Error!void {
8465 switch (elf.shndx.debug_abbrev) {8472 switch (elf.shndx.debug_abbrev) {
8466 .UNDEF => {},8473 .UNDEF => {},
8467 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(8474 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(
8468 try debug_abbrev_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),8475 try debug_abbrev_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{}),
8469 .{ .debug_shared = .debug_abbrev },8476 .{ .debug_shared = .debug_abbrev },
8470 )),8477 )),
8471 }8478 }
...@@ -8473,14 +8480,14 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -8473,14 +8480,14 @@ fn prelinkInner(elf: *Elf) Error!void {
8473 .UNDEF => {},8480 .UNDEF => {},
8474 else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni =8481 else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni =
8475 .wrap(elf.addNodeAssumeCapacity(8482 .wrap(elf.addNodeAssumeCapacity(
8476 try debug_line_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),8483 try debug_line_str_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{}),
8477 .{ .debug_shared = .debug_line_str },8484 .{ .debug_shared = .debug_line_str },
8478 )),8485 )),
8479 }8486 }
8480 switch (elf.shndx.debug_str) {8487 switch (elf.shndx.debug_str) {
8481 .UNDEF => {},8488 .UNDEF => {},
8482 else => |debug_str_shndx| elf.dwarf.debug_str.ni = .wrap(elf.addNodeAssumeCapacity(8489 else => |debug_str_shndx| elf.dwarf.debug_str.ni = .wrap(elf.addNodeAssumeCapacity(
8483 try debug_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),8490 try debug_str_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{}),
8484 .{ .debug_shared = .debug_str },8491 .{ .debug_shared = .debug_str },
8485 )),8492 )),
8486 }8493 }
...@@ -8488,7 +8495,7 @@ fn prelinkInner(elf: *Elf) Error!void {...@@ -8488,7 +8495,7 @@ fn prelinkInner(elf: *Elf) Error!void {
8488 .UNDEF => {},8495 .UNDEF => {},
8489 else => |debug_str_offsets_shndx| {8496 else => |debug_str_offsets_shndx| {
8490 const debug_str_offsets_ni = elf.addNodeAssumeCapacity(8497 const debug_str_offsets_ni = elf.addNodeAssumeCapacity(
8491 try debug_str_offsets_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{8498 try debug_str_offsets_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
8492 .alignment = switch (elf.dwarf.format) {8499 .alignment = switch (elf.dwarf.format) {
8493 .@"32" => .@"4",8500 .@"32" => .@"4",
8494 .@"64" => .@"8",8501 .@"64" => .@"8",
...@@ -8549,7 +8556,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {...@@ -8549,7 +8556,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
8549 else => |debug_info_shndx| {8556 else => |debug_info_shndx| {
8550 const debug_info_ni = unit.debug_info_ni.unwrap() orelse debug_info_ni: {8557 const debug_info_ni = unit.debug_info_ni.unwrap() orelse debug_info_ni: {
8551 const debug_info_ni = elf.addNodeAssumeCapacity(8558 const debug_info_ni = elf.addNodeAssumeCapacity(
8552 try debug_info_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{8559 try debug_info_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
8553 .alignment = elf.mf.flags.block_size,8560 .alignment = elf.mf.flags.block_size,
8554 .enable_next_moved = true,8561 .enable_next_moved = true,
8555 }),8562 }),
...@@ -8576,7 +8583,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {...@@ -8576,7 +8583,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
8576 else => |debug_line_shndx| {8583 else => |debug_line_shndx| {
8577 const debug_line_ni = unit.debug_line_ni.unwrap() orelse debug_line_ni: {8584 const debug_line_ni = unit.debug_line_ni.unwrap() orelse debug_line_ni: {
8578 const debug_line_ni = elf.addNodeAssumeCapacity(8585 const debug_line_ni = elf.addNodeAssumeCapacity(
8579 try debug_line_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{8586 try debug_line_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
8580 .alignment = elf.mf.flags.block_size,8587 .alignment = elf.mf.flags.block_size,
8581 .enable_next_moved = true,8588 .enable_next_moved = true,
8582 }),8589 }),
...@@ -8600,7 +8607,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {...@@ -8600,7 +8607,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
8600 else => |debug_rnglists_shndx| {8607 else => |debug_rnglists_shndx| {
8601 const debug_rnglists_ni = unit.debug_rnglists_ni.unwrap() orelse debug_rnglists_ni: {8608 const debug_rnglists_ni = unit.debug_rnglists_ni.unwrap() orelse debug_rnglists_ni: {
8602 const debug_rnglists_ni = elf.addNodeAssumeCapacity(8609 const debug_rnglists_ni = elf.addNodeAssumeCapacity(
8603 try debug_rnglists_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{8610 try debug_rnglists_shndx.node(elf).addFloatingChild(gpa, &elf.mf, .{
8604 .next_moved = true,8611 .next_moved = true,
8605 .enable_next_moved = true,8612 .enable_next_moved = true,
8606 }),8613 }),
...@@ -8680,7 +8687,7 @@ fn prepareDynamic(elf: *Elf) Error!void {...@@ -8680,7 +8687,7 @@ fn prepareDynamic(elf: *Elf) Error!void {
86808687
8681 const dynamic_size = dynamic_len * 2 * elf.targetPtrSize();8688 const dynamic_size = dynamic_len * 2 * elf.targetPtrSize();
86828689
8683 try elf.shndx.dynamic.get(elf).ni.resizeLeaf(comp.gpa, &elf.mf, dynamic_size);8690 try elf.shndx.dynamic.node(elf).resizeLeaf(comp.gpa, &elf.mf, dynamic_size);
8684 switch (elf.shdrPtr(elf.shndx.dynamic)) {8691 switch (elf.shdrPtr(elf.shndx.dynamic)) {
8685 inline else => |shdr| elf.targetStore(&shdr.size, @intCast(dynamic_size)),8692 inline else => |shdr| elf.targetStore(&shdr.size, @intCast(dynamic_size)),
8686 }8693 }
...@@ -8702,7 +8709,7 @@ fn flushDynamic(elf: *Elf) void {...@@ -8702,7 +8709,7 @@ fn flushDynamic(elf: *Elf) void {
8702 comp.config.pie);8709 comp.config.pie);
87038710
8704 const dynamic_size = elf.targetLoad(&@field(elf.shdrPtr(elf.shndx.dynamic), @tagName(class)).size);8711 const dynamic_size = elf.targetLoad(&@field(elf.shdrPtr(elf.shndx.dynamic), @tagName(class)).size);
8705 const dynamic_slice = elf.shndx.dynamic.get(elf).ni.slice(&elf.mf)[0..@intCast(dynamic_size)];8712 const dynamic_slice = elf.shndx.dynamic.node(elf).slice(&elf.mf)[0..@intCast(dynamic_size)];
8706 const dynamic_entries: [][2]ElfN.Addr = @ptrCast(@alignCast(dynamic_slice));8713 const dynamic_entries: [][2]ElfN.Addr = @ptrCast(@alignCast(dynamic_slice));
87078714
8708 var dynamic_index: usize = 0;8715 var dynamic_index: usize = 0;
...@@ -8896,7 +8903,7 @@ fn addSection(elf: *Elf, segment_ni: MappedFile.Node.Index, opts: struct {...@@ -8896,7 +8903,7 @@ fn addSection(elf: *Elf, segment_ni: MappedFile.Node.Index, opts: struct {
8896 .type = .SECTION,8903 .type = .SECTION,
8897 .shndx = shndx,8904 .shndx = shndx,
8898 }) else .null,8905 }) else .null,
8899 .ni = ni,8906 .ni = .wrap(ni),
8900 .rela = switch (opts.type) {8907 .rela = switch (opts.type) {
8901 .REL => unreachable,8908 .REL => unreachable,
8902 .RELA => .{ .free_head = .none },8909 .RELA => .{ .free_head = .none },
...@@ -8973,7 +8980,7 @@ fn ensureUnusedRelocCapacity(elf: *Elf, node: MappedFile.Node.Index, len: usize)...@@ -8973,7 +8980,7 @@ fn ensureUnusedRelocCapacity(elf: *Elf, node: MappedFile.Node.Index, len: usize)
8973 .NONE, _ => unreachable,8980 .NONE, _ => unreachable,
8974 inline else => |ct_class| (elf.got.count() + new_got_entries) * @sizeOf(ct_class.ElfN().Addr),8981 inline else => |ct_class| (elf.got.count() + new_got_entries) * @sizeOf(ct_class.ElfN().Addr),
8975 };8982 };
8976 try elf.shndx.got.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, need_got_size);8983 try elf.shndx.got.node(elf).ensureMinimumSize(gpa, &elf.mf, need_got_size);
89778984
8978 if (elf.shndx.dynamic != .UNDEF) {8985 if (elf.shndx.dynamic != .UNDEF) {
8979 try elf.shndx.rela_dyn.relaEnsureAdditionalCapacity(elf, new_got_entries);8986 try elf.shndx.rela_dyn.relaEnsureAdditionalCapacity(elf, new_got_entries);
...@@ -9816,7 +9823,7 @@ fn updateGotEntry(elf: *Elf, got_index: usize) void {...@@ -9816,7 +9823,7 @@ fn updateGotEntry(elf: *Elf, got_index: usize) void {
9816 const addr_size = @sizeOf(class.ElfN().Addr);9823 const addr_size = @sizeOf(class.ElfN().Addr);
9817 const offset = got_index * addr_size;9824 const offset = got_index * addr_size;
9818 const entry_ptr: *class.ElfN().Addr = @ptrCast(@alignCast(9825 const entry_ptr: *class.ElfN().Addr = @ptrCast(@alignCast(
9819 elf.shndx.got.get(elf).ni.slice(&elf.mf)[offset..][0..addr_size],9826 elf.shndx.got.node(elf).slice(&elf.mf)[offset..][0..addr_size],
9820 ));9827 ));
9821 elf.targetStore(entry_ptr, switch (entry_value) {9828 elf.targetStore(entry_ptr, switch (entry_value) {
9822 .unsigned => |x| @intCast(x),9829 .unsigned => |x| @intCast(x),
...@@ -10179,7 +10186,7 @@ fn updateFuncInner(...@@ -10179,7 +10186,7 @@ fn updateFuncInner(
10179 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_func.frame_format) {10186 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_func.frame_format) {
10180 .debug_frame => elf.shndx.debug_frame,10187 .debug_frame => elf.shndx.debug_frame,
10181 .eh_frame => elf.shndx.eh_frame,10188 .eh_frame => elf.shndx.eh_frame,
10182 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{10189 }.node(elf).addFloatingChild(gpa, &elf.mf, .{
10183 .alignment = frame_align.max(elf.mf.flags.block_size),10190 .alignment = frame_align.max(elf.mf.flags.block_size),
10184 .enable_next_moved = true,10191 .enable_next_moved = true,
10185 }), .{ .unit_frame = wip_func.unit });10192 }), .{ .unit_frame = wip_func.unit });
...@@ -11904,17 +11911,17 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -11904,17 +11911,17 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
11904 const gpa = elf.base.comp.gpa;11911 const gpa = elf.base.comp.gpa;
11905 try elf.shndx.rela_plt.relaEnsureAdditionalCapacity(elf, 1);11912 try elf.shndx.rela_plt.relaEnsureAdditionalCapacity(elf, 1);
11906 try elf.plt.ensureUnusedCapacity(gpa, 1);11913 try elf.plt.ensureUnusedCapacity(gpa, 1);
11907 try elf.shndx.plt.get(elf).ni.ensureMinimumSize(11914 try elf.shndx.plt.node(elf).ensureMinimumSize(
11908 gpa,11915 gpa,
11909 &elf.mf,11916 &elf.mf,
11910 plt.entry_size * (plt.header_entries + elf.plt.count() + 1),11917 plt.entry_size * (plt.header_entries + elf.plt.count() + 1),
11911 );11918 );
11912 if (plt.got_plt) |got_plt| try elf.shndx.got_plt.get(elf).ni.ensureMinimumSize(11919 if (plt.got_plt) |got_plt| try elf.shndx.got_plt.node(elf).ensureMinimumSize(
11913 gpa,11920 gpa,
11914 &elf.mf,11921 &elf.mf,
11915 elf.targetPtrSize() * (got_plt.header_entries + elf.plt.count() + 1),11922 elf.targetPtrSize() * (got_plt.header_entries + elf.plt.count() + 1),
11916 );11923 );
11917 if (plt.plt_sec) |plt_sec| try elf.shndx.plt_sec.get(elf).ni.ensureMinimumSize(11924 if (plt.plt_sec) |plt_sec| try elf.shndx.plt_sec.node(elf).ensureMinimumSize(
11918 gpa,11925 gpa,
11919 &elf.mf,11926 &elf.mf,
11920 plt_sec.entry_size * (elf.plt.count() + 1),11927 plt_sec.entry_size * (elf.plt.count() + 1),
...@@ -11962,7 +11969,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -11962,7 +11969,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
11962 switch (elf.ehdrMachine()) {11969 switch (elf.ehdrMachine()) {
11963 .AARCH64, .PPC64, .RISCV => |machine| @panic(@tagName(machine)),11970 .AARCH64, .PPC64, .RISCV => |machine| @panic(@tagName(machine)),
11964 .X86_64 => {11971 .X86_64 => {
11965 const plt_ni = elf.shndx.plt.get(elf).ni;11972 const plt_ni = elf.shndx.plt.node(elf);
11966 const plt_addr = plt_addr: switch (elf.shdrPtr(elf.shndx.plt)) {11973 const plt_addr = plt_addr: switch (elf.shdrPtr(elf.shndx.plt)) {
11967 inline else => |shdr| {11974 inline else => |shdr| {
11968 const old_size = 16 * (1 + plt_index);11975 const old_size = 16 * (1 + plt_index);
...@@ -11986,7 +11993,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -11986,7 +11993,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
11986 },11993 },
11987 };11994 };
1198811995
11989 const got_plt_ni = elf.shndx.got_plt.get(elf).ni;11996 const got_plt_ni = elf.shndx.got_plt.node(elf);
11990 switch (elf.shdrPtr(elf.shndx.got_plt)) {11997 switch (elf.shdrPtr(elf.shndx.got_plt)) {
11991 inline else => |shdr, class| {11998 inline else => |shdr, class| {
11992 assert(elf.targetLoad(&shdr.size) == got_plt_offset);11999 assert(elf.targetLoad(&shdr.size) == got_plt_offset);
...@@ -12000,7 +12007,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -12000,7 +12007,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
12000 },12007 },
12001 }12008 }
1200212009
12003 const plt_sec_ni = elf.shndx.plt_sec.get(elf).ni;12010 const plt_sec_ni = elf.shndx.plt_sec.node(elf);
12004 switch (elf.shdrPtr(elf.shndx.plt_sec)) {12011 switch (elf.shdrPtr(elf.shndx.plt_sec)) {
12005 inline else => |shdr| {12012 inline else => |shdr| {
12006 const old_size = 16 * plt_index;12013 const old_size = 16 * plt_index;
...@@ -12024,7 +12031,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -12024,7 +12031,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
12024 },12031 },
12025 .LOONGARCH => {12032 .LOONGARCH => {
12026 // add a .PLT entry, writing the template12033 // add a .PLT entry, writing the template
12027 const plt_ni = elf.shndx.plt.get(elf).ni;12034 const plt_ni = elf.shndx.plt.node(elf);
12028 const plt_addr, const plt_slice = plt_entry: switch (elf.shdrPtr(elf.shndx.plt)) {12035 const plt_addr, const plt_slice = plt_entry: switch (elf.shdrPtr(elf.shndx.plt)) {
12029 inline else => |shdr| {12036 inline else => |shdr| {
12030 const old_size = 16 * (1 + plt_index);12037 const old_size = 16 * (1 + plt_index);
...@@ -12048,7 +12055,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -12048,7 +12055,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
12048 };12055 };
1204912056
12050 // add a .GOT.PLT entry, writing the address of the corresponding .PLT entry12057 // add a .GOT.PLT entry, writing the address of the corresponding .PLT entry
12051 const got_plt_ni = elf.shndx.got_plt.get(elf).ni;12058 const got_plt_ni = elf.shndx.got_plt.node(elf);
12052 switch (elf.shdrPtr(elf.shndx.got_plt)) {12059 switch (elf.shdrPtr(elf.shndx.got_plt)) {
12053 inline else => |shdr, class| {12060 inline else => |shdr, class| {
12054 assert(elf.targetLoad(&shdr.size) == got_plt_offset);12061 assert(elf.targetLoad(&shdr.size) == got_plt_offset);
...@@ -12080,7 +12087,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {...@@ -12080,7 +12087,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool {
12080 },12087 },
12081 .SPARCV9 => {12088 .SPARCV9 => {
12082 // add a .PLT entry, writing the template12089 // add a .PLT entry, writing the template
12083 const plt_ni = elf.shndx.plt.get(elf).ni;12090 const plt_ni = elf.shndx.plt.node(elf);
12084 switch (elf.shdrPtr(elf.shndx.plt)) {12091 switch (elf.shdrPtr(elf.shndx.plt)) {
12085 inline else => |shdr| {12092 inline else => |shdr| {
12086 assert(elf.targetLoad(&shdr.size) == got_plt_offset);12093 assert(elf.targetLoad(&shdr.size) == got_plt_offset);
...@@ -12137,7 +12144,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -12137,7 +12144,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
12137 // We also need to update all of the references from `.plt.sec` to `.got.plt`.12144 // We also need to update all of the references from `.plt.sec` to `.got.plt`.
12138 // However, if there's also a flush pending for `.got.plt`, don't bother doing12145 // However, if there's also a flush pending for `.got.plt`, don't bother doing
12139 // this now, because we'll do it when `.got.plt` is flushed anyway.12146 // this now, because we'll do it when `.got.plt` is flushed anyway.
12140 if (elf.shndx.got_plt.get(elf).ni.hasMoved(&elf.mf)) {12147 if (elf.shndx.got_plt.node(elf).hasMoved(&elf.mf)) {
12141 return;12148 return;
12142 }12149 }
12143 // Exit this `switch` to update those references.12150 // Exit this `switch` to update those references.
...@@ -12152,7 +12159,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -12152,7 +12159,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
12152 // We also need to update all of the references from `.plt.sec` to `.got.plt`.12159 // We also need to update all of the references from `.plt.sec` to `.got.plt`.
12153 // However, if there's also a flush pending for `.plt.sec`, don't bother doing12160 // However, if there's also a flush pending for `.plt.sec`, don't bother doing
12154 // this now, because we'll do it when `.plt.sec` is flushed anyway.12161 // this now, because we'll do it when `.plt.sec` is flushed anyway.
12155 if (elf.shndx.plt_sec.get(elf).ni.hasMoved(&elf.mf)) {12162 if (elf.shndx.plt_sec.node(elf).hasMoved(&elf.mf)) {
12156 return;12163 return;
12157 }12164 }
12158 // Exit this `switch` to update those references.12165 // Exit this `switch` to update those references.
...@@ -12161,7 +12168,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -12161,7 +12168,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
12161 // We are updating the references from `.plt.sec` to `.got.plt`.12168 // We are updating the references from `.plt.sec` to `.got.plt`.
12162 const got_plt_addr = elf.shndx.got_plt.vaddr(elf);12169 const got_plt_addr = elf.shndx.got_plt.vaddr(elf);
12163 const plt_sec_addr = elf.shndx.plt_sec.vaddr(elf);12170 const plt_sec_addr = elf.shndx.plt_sec.vaddr(elf);
12164 const plt_sec_slice = elf.shndx.plt_sec.get(elf).ni.slice(&elf.mf);12171 const plt_sec_slice = elf.shndx.plt_sec.node(elf).slice(&elf.mf);
12165 switch (elf.identClass()) {12172 switch (elf.identClass()) {
12166 .NONE, _ => unreachable,12173 .NONE, _ => unreachable,
12167 inline else => |class| {12174 inline else => |class| {
...@@ -12194,7 +12201,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -12194,7 +12201,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
12194 // We also need to update all of the references from `.plt` to `.got.plt`.12201 // We also need to update all of the references from `.plt` to `.got.plt`.
12195 // However, if there's also a flush pending for `.got.plt`, don't bother doing12202 // However, if there's also a flush pending for `.got.plt`, don't bother doing
12196 // this now, because we'll do it when `.got.plt` is flushed anyway.12203 // this now, because we'll do it when `.got.plt` is flushed anyway.
12197 if (elf.shndx.got_plt.get(elf).ni.hasMoved(&elf.mf)) {12204 if (elf.shndx.got_plt.node(elf).hasMoved(&elf.mf)) {
12198 return;12205 return;
12199 }12206 }
12200 // Exit this `switch` to update those references.12207 // Exit this `switch` to update those references.
...@@ -12210,7 +12217,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -12210,7 +12217,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
12210 // We also need to update all of the references from `.plt` to `.got.plt`.12217 // We also need to update all of the references from `.plt` to `.got.plt`.
12211 // However, if there's also a flush pending for `.plt`, don't bother doing12218 // However, if there's also a flush pending for `.plt`, don't bother doing
12212 // this now, because we'll do it when `.plt` is flushed anyway.12219 // this now, because we'll do it when `.plt` is flushed anyway.
12213 if (elf.shndx.plt.get(elf).ni.hasMoved(&elf.mf)) {12220 if (elf.shndx.plt.node(elf).hasMoved(&elf.mf)) {
12214 return;12221 return;
12215 }12222 }
12216 // Exit this `switch` to update those references.12223 // Exit this `switch` to update those references.
...@@ -12219,7 +12226,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -12219,7 +12226,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
12219 // We are updating the references from `.plt` to `.got.plt`.12226 // We are updating the references from `.plt` to `.got.plt`.
12220 const got_plt_addr = elf.shndx.got_plt.vaddr(elf);12227 const got_plt_addr = elf.shndx.got_plt.vaddr(elf);
12221 const plt_addr = elf.shndx.plt.vaddr(elf);12228 const plt_addr = elf.shndx.plt.vaddr(elf);
12222 const plt_slice = elf.shndx.plt.get(elf).ni.slice(&elf.mf);12229 const plt_slice = elf.shndx.plt.node(elf).slice(&elf.mf);
12223 switch (elf.identClass()) {12230 switch (elf.identClass()) {
12224 .NONE, _ => unreachable,12231 .NONE, _ => unreachable,
12225 inline else => |class| {12232 inline else => |class| {
...@@ -12657,7 +12664,7 @@ const VerdefAdapter = struct {...@@ -12657,7 +12664,7 @@ const VerdefAdapter = struct {
12657fn verdefId(elf: *Elf, version: String(.dynstr)) Error!u15 {12664fn verdefId(elf: *Elf, version: String(.dynstr)) Error!u15 {
12658 const gpa = elf.base.comp.gpa;12665 const gpa = elf.base.comp.gpa;
12659 const adapter: VerdefAdapter = .{ .elf = elf };12666 const adapter: VerdefAdapter = .{ .elf = elf };
12660 try elf.shndx.gnu_version_d.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, (elf.verdef.count() + 2) * @sizeOf(VerdefEntry));12667 try elf.shndx.gnu_version_d.node(elf).ensureMinimumSize(gpa, &elf.mf, (elf.verdef.count() + 2) * @sizeOf(VerdefEntry));
12661 const gop = try elf.verdef.getOrPutAdapted(gpa, version, adapter);12668 const gop = try elf.verdef.getOrPutAdapted(gpa, version, adapter);
1266212669
12663 if (gop.found_existing) {12670 if (gop.found_existing) {
...@@ -12766,7 +12773,7 @@ const VerneedAdapter = struct {...@@ -12766,7 +12773,7 @@ const VerneedAdapter = struct {
12766fn verneedId(elf: *Elf, file: String(.dynstr), version: String(.dynstr)) Error!u15 {12773fn verneedId(elf: *Elf, file: String(.dynstr), version: String(.dynstr)) Error!u15 {
12767 const gpa = elf.base.comp.gpa;12774 const gpa = elf.base.comp.gpa;
12768 const adapter: VerneedAdapter = .{ .elf = elf };12775 const adapter: VerneedAdapter = .{ .elf = elf };
12769 try elf.shndx.gnu_version_r.get(elf).ni.ensureMinimumSize(gpa, &elf.mf, (elf.verneed.count() + 2) * @sizeOf(VerneedEntry));12776 try elf.shndx.gnu_version_r.node(elf).ensureMinimumSize(gpa, &elf.mf, (elf.verneed.count() + 2) * @sizeOf(VerneedEntry));
1277012777
12771 if (elf.verneed.getIndexAdapted(@as(VerneedAdapter.Key, .{12778 if (elf.verneed.getIndexAdapted(@as(VerneedAdapter.Key, .{
12772 .file = file,12779 .file = file,