| ... | ... | @@ -492,7 +492,7 @@ const Archive = struct { |
| 492 | 492 | |
| 493 | 493 | const Section = struct { |
| 494 | 494 | /// The node corresponding to this section. |
| 495 | | ni: MappedFile.Node.Index, |
| 495 | ni: MappedFile.Node.Index.Optional, |
| 496 | 496 | /// A symbol which is exactly at the start of this section. |
| 497 | 497 | /// |
| 498 | 498 | /// When not emitting a relocatable, or for special section types, this is `.null`. |
| ... | ... | @@ -596,6 +596,13 @@ const Section = struct { |
| 596 | 596 | return &elf.shdrs.items[@backingInt(shndx) - 1]; // overflow means you tried to get the `.UNDEF` section |
| 597 | 597 | } |
| 598 | 598 | |
| 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 | 606 | fn name(shndx: Index, elf: *Elf) String(.shstrtab) { |
| 600 | 607 | return switch (elf.shdrPtr(shndx)) { |
| 601 | 608 | inline else => |shdr| @fromBackingInt(elf.targetLoad(&shdr.name)), |
| ... | ... | @@ -648,7 +655,7 @@ const Section = struct { |
| 648 | 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 | 659 | if (min_align.compare(.gt, ni.alignment(&elf.mf))) { |
| 653 | 660 | try ni.realign(elf.base.comp.gpa, &elf.mf, min_align); |
| 654 | 661 | } |
| ... | ... | @@ -662,7 +669,7 @@ const Section = struct { |
| 662 | 669 | /// Asserts that `rela_shndx` is a `SHT_RELA` section and ensures that its node has enough |
| 663 | 670 | /// unused space to hold `n` additional `ElfN.Rela` entries. |
| 664 | 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 | 673 | const need_size: u64 = switch (elf.shdrPtr(rela_shndx)) { |
| 667 | 674 | inline else => |shdr, class| need_size: { |
| 668 | 675 | assert(elf.targetLoad(&shdr.type) == .RELA); |
| ... | ... | @@ -673,7 +680,7 @@ const Section = struct { |
| 673 | 680 | const opt_free_head = rela_shndx.get(elf).rela.free_head; |
| 674 | 681 | const free_head = opt_free_head.unwrap() orelse break :free_len 0; |
| 675 | 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 | 685 | const free_len = elf.targetLoad(&relas[@backingInt(free_head)].addend); |
| 679 | 686 | assert(free_len > 0); |
| ... | ... | @@ -683,7 +690,7 @@ const Section = struct { |
| 683 | 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 | } |
| 688 | 695 | |
| 689 | 696 | /// Asserts that `rela_shndx` is a `SHT_RELA` section and deletes the `ElfN.Rela` entry at |
| ... | ... | @@ -695,7 +702,7 @@ const Section = struct { |
| 695 | 702 | assert(elf.targetLoad(&shdr.type) == .RELA); |
| 696 | 703 | assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela)); |
| 697 | 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 | 707 | const opt_free_head = rela_shndx.get(elf).rela.free_head; |
| 701 | 708 | const old_free_len: u32 = free_len: { |
| ... | ... | @@ -743,7 +750,7 @@ const Section = struct { |
| 743 | 750 | assert(elf.targetLoad(&shdr.entsize) == ent_size); |
| 744 | 751 | const new_index: RelaIndex = if (rela_shndx.get(elf).rela.free_head.unwrap()) |free_head| new_index: { |
| 745 | 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 | 755 | const next: RelaIndex.Optional = @fromBackingInt(@intCast(elf.targetLoad( |
| 749 | 756 | &relas[@backingInt(free_head)].offset, |
| ... | ... | @@ -766,7 +773,7 @@ const Section = struct { |
| 766 | 773 | break :new_index @fromBackingInt(@intCast(@divExact(old_size, ent_size))); |
| 767 | 774 | }; |
| 768 | 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 | 778 | relas[@backingInt(new_index)] = .{ |
| 772 | 779 | .offset = @intCast(opts.offset), |
| ... | ... | @@ -794,7 +801,7 @@ const Section = struct { |
| 794 | 801 | assert(elf.targetLoad(&shdr.type) == .RELA); |
| 795 | 802 | assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela)); |
| 796 | 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 | 806 | const rela_info = elf.targetLoad(&relas[@backingInt(index)].info); |
| 800 | 807 | { |
| ... | ... | @@ -818,7 +825,7 @@ const Section = struct { |
| 818 | 825 | assert(elf.targetLoad(&shdr.type) == .RELA); |
| 819 | 826 | assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela)); |
| 820 | 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 | 831 | const rela_info = elf.targetLoad(&relas[@backingInt(index)].info); |
| ... | ... | @@ -839,7 +846,7 @@ const Section = struct { |
| 839 | 846 | assert(elf.targetLoad(&shdr.type) == .RELA); |
| 840 | 847 | assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela)); |
| 841 | 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 | 852 | const rela_info = elf.targetLoad(&relas[@backingInt(index)].info); |
| ... | ... | @@ -863,7 +870,7 @@ const Section = struct { |
| 863 | 870 | assert(elf.targetLoad(&shdr.type) == .RELA); |
| 864 | 871 | assert(elf.targetLoad(&shdr.entsize) == @sizeOf(class.ElfN().Rela)); |
| 865 | 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 | 876 | const rela_info = elf.targetLoad(&relas[@backingInt(index)].info); |
| ... | ... | @@ -2220,7 +2227,7 @@ const GotReloc = struct { |
| 2220 | 2227 | fn apply(reloc: *GotReloc, elf: *Elf) void { |
| 2221 | 2228 | assert(elf.ehdrType() != .REL); |
| 2222 | 2229 | 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 | 2231 | // There's no point applying the relocation now, because it will be re-applied by |
| 2225 | 2232 | // `flushMoved` at some point anyway. |
| 2226 | 2233 | return; |
| ... | ... | @@ -2452,7 +2459,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void { |
| 2452 | 2459 | switch (elf.targetDynsymHashInfo()) { |
| 2453 | 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 | 2463 | const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]); |
| 2457 | 2464 | assert(elf.targetLoad(&header.nchain) == cur_dynsym_count); |
| 2458 | 2465 | const nbucket = elf.targetLoad(&header.nbucket); |
| ... | ... | @@ -2460,7 +2467,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void { |
| 2460 | 2467 | // We don't need to add any buckets, but we still need to make sure the section is large |
| 2461 | 2468 | // enough to fit `max_dynsym_count` chains. |
| 2462 | 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 | 2471 | return; |
| 2465 | 2472 | } |
| 2466 | 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 | 2479 | |
| 2473 | 2480 | { |
| 2474 | 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 | } |
| 2477 | 2484 | |
| 2478 | 2485 | elf.mf.nodes_lock.lock(); |
| 2479 | 2486 | defer elf.mf.nodes_lock.unlock(); |
| 2480 | 2487 | |
| 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 | 2489 | const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]); |
| 2483 | 2490 | const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]); |
| 2484 | 2491 | |
| ... | ... | @@ -2508,7 +2515,7 @@ fn ensureDynsymHashCapacity(elf: *Elf, max_dynsym_count: u32) Error!void { |
| 2508 | 2515 | fn appendDynsymHashEntry(elf: *Elf, dynsym_index: u32) void { |
| 2509 | 2516 | switch (elf.targetDynsymHashInfo()) { |
| 2510 | 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 | 2519 | const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]); |
| 2513 | 2520 | assert(elf.targetLoad(&header.nchain) == dynsym_index); |
| 2514 | 2521 | elf.targetStore(&header.nchain, dynsym_index + 1); |
| ... | ... | @@ -2529,7 +2536,7 @@ fn populateDynsymHashEntry(elf: *Elf, dynsym_index: u32) void { |
| 2529 | 2536 | |
| 2530 | 2537 | switch (elf.targetDynsymHashInfo()) { |
| 2531 | 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 | 2540 | const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]); |
| 2534 | 2541 | const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]); |
| 2535 | 2542 | |
| ... | ... | @@ -2551,7 +2558,7 @@ fn popDynsymHashEntry(elf: *Elf, dynsym_index: u32) void { |
| 2551 | 2558 | |
| 2552 | 2559 | switch (elf.targetDynsymHashInfo()) { |
| 2553 | 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 | 2562 | const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]); |
| 2556 | 2563 | assert(elf.targetLoad(&header.nchain) == dynsym_index + 1); |
| 2557 | 2564 | elf.targetStore(&header.nchain, dynsym_index); |
| ... | ... | @@ -2570,7 +2577,7 @@ fn clearDynsymHashEntry(elf: *Elf, dynsym_index: u32) void { |
| 2570 | 2577 | |
| 2571 | 2578 | switch (elf.targetDynsymHashInfo()) { |
| 2572 | 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 | 2581 | const header: *info.Header() = @ptrCast(section_slice[0..@sizeOf(info.Header())]); |
| 2575 | 2582 | const trailing: []info.Int() = @ptrCast(section_slice[@sizeOf(info.Header())..]); |
| 2576 | 2583 | |
| ... | ... | @@ -2615,7 +2622,7 @@ fn pltEntryIsDead(elf: *Elf, plt_index: usize) bool { |
| 2615 | 2622 | inline else => |rela_shdr, class| { |
| 2616 | 2623 | const size = elf.targetLoad(&rela_shdr.size); |
| 2617 | 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 | 2627 | const rel_type = elf.targetLoad(&relas[plt_index].info).type; |
| 2621 | 2628 | return rel_type == MachineRelocType.none(elf).unwrap(elf); |
| ... | ... | @@ -2636,7 +2643,7 @@ fn addLocalSymbol(elf: *Elf, opts: AddLocalSymbolOptions) Error!Symbol.LocalInde |
| 2636 | 2643 | |
| 2637 | 2644 | try elf.symtab.ensureUnusedCapacity(gpa, 1); |
| 2638 | 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 | 2647 | inline else => |shdr, class| elf.targetLoad(&shdr.size) + @sizeOf(class.ElfN().Sym), |
| 2641 | 2648 | }); |
| 2642 | 2649 | |
| ... | ... | @@ -2715,7 +2722,7 @@ fn addGlobalSymbol(elf: *Elf, opts: Symbol.Global.AddOptions) (error{ |
| 2715 | 2722 | try elf.globals_by_name.ensureUnusedCapacity(gpa, 1); |
| 2716 | 2723 | try elf.node_global_symbols.ensureUnusedCapacity(gpa, 1); |
| 2717 | 2724 | |
| 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 | 2726 | inline else => |shdr, class| elf.targetLoad(&shdr.size) + @sizeOf(class.ElfN().Sym), |
| 2720 | 2727 | }); |
| 2721 | 2728 | |
| ... | ... | @@ -3059,8 +3066,8 @@ fn updateGlobalDynamic(elf: *Elf, orig_gsi: Symbol.Global.Index, force_apply_rel |
| 3059 | 3066 | }; |
| 3060 | 3067 | const need_dynsym_len: u32 = @intCast(@divExact(dynsym_size, dynsym_ent_size) + 1); |
| 3061 | 3068 | |
| 3062 | | try elf.shndx.dynsym.get(elf).ni.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); |
| 3069 | try elf.shndx.dynsym.node(elf).ensureMinimumSize(gpa, &elf.mf, need_dynsym_len * dynsym_ent_size); |
| 3070 | try elf.shndx.gnu_version.node(elf).ensureMinimumSize(gpa, &elf.mf, need_dynsym_len * 2); |
| 3064 | 3071 | try elf.ensureDynsymHashCapacity(need_dynsym_len); |
| 3065 | 3072 | |
| 3066 | 3073 | const dynstr_name: String(.dynstr) = name: { |
| ... | ... | @@ -3246,7 +3253,7 @@ fn updateGlobalDynamic(elf: *Elf, orig_gsi: Symbol.Global.Index, force_apply_rel |
| 3246 | 3253 | errdefer assert(elf.copied_globals.pop().?.key == gsi); |
| 3247 | 3254 | try elf.nodes.ensureUnusedCapacity(gpa, 1); |
| 3248 | 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 | 3257 | .size = dso_global.alignment.forward(dso_global.size), |
| 3251 | 3258 | .alignment = dso_global.alignment, |
| 3252 | 3259 | }), |
| ... | ... | @@ -4295,7 +4302,7 @@ fn lazySymbolInner(elf: *Elf, lazy: link.File.LazySymbol) Error!link.File.Symbol |
| 4295 | 4302 | .const_data => .{ .rodata, .OBJECT }, |
| 4296 | 4303 | }; |
| 4297 | 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 | 4306 | switch (lazy.kind) { |
| 4300 | 4307 | .code => .{ .lazy_code = @fromBackingInt(@intCast(gop.index)) }, |
| 4301 | 4308 | .const_data => .{ .lazy_const_data = @fromBackingInt(@intCast(gop.index)) }, |
| ... | ... | @@ -4472,7 +4479,7 @@ fn String(section: StringSection) type { |
| 4472 | 4479 | _, |
| 4473 | 4480 | |
| 4474 | 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 | 4483 | const overlong = section_node.sliceConst(&elf.mf)[@backingInt(str)..]; |
| 4477 | 4484 | return overlong[0..std.mem.findScalar(u8, overlong, 0).? :0]; |
| 4478 | 4485 | } |
| ... | ... | @@ -4532,14 +4539,14 @@ const StringTable = struct { |
| 4532 | 4539 | |
| 4533 | 4540 | fn getExisting(st: *StringTable, elf: *Elf, shndx: Section.Index, key: []const u8) u32 { |
| 4534 | 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 | 4543 | const adapter: StringTable.Adapter = .{ .slice = slice_const }; |
| 4537 | 4544 | return st.map.getKeyAdapted(key, adapter).?; |
| 4538 | 4545 | } |
| 4539 | 4546 | |
| 4540 | 4547 | fn ensureAdditionalCapacity(st: *StringTable, elf: *Elf, shndx: Section.Index, string_len: usize) Error!void { |
| 4541 | 4548 | const gpa = elf.base.comp.gpa; |
| 4542 | | const ni = shndx.get(elf).ni; |
| 4549 | const ni = shndx.node(elf); |
| 4543 | 4550 | const slice_const = ni.sliceConst(&elf.mf); |
| 4544 | 4551 | try st.map.ensureUnusedCapacityContext(gpa, 1, .{ .slice = slice_const }); |
| 4545 | 4552 | const size: u64 = switch (elf.shdrPtr(shndx)) { |
| ... | ... | @@ -4553,7 +4560,7 @@ const StringTable = struct { |
| 4553 | 4560 | // case the empty string. |
| 4554 | 4561 | if (key.len == 0) return 0; |
| 4555 | 4562 | |
| 4556 | | const ni = shndx.get(elf).ni; |
| 4563 | const ni = shndx.node(elf); |
| 4557 | 4564 | const slice_const = ni.sliceConst(&elf.mf); |
| 4558 | 4565 | const gop = st.map.getOrPutAssumeCapacityAdapted( |
| 4559 | 4566 | key, |
| ... | ... | @@ -5476,7 +5483,7 @@ fn initHeaders( |
| 5476 | 5483 | .node_align = node_block_align, |
| 5477 | 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; |
| 5480 | 5487 | |
| 5481 | 5488 | try Section.Index.symtab.rename(elf, ".symtab"); |
| 5482 | 5489 | try Section.Index.shstrtab.rename(elf, ".shstrtab"); |
| ... | ... | @@ -5489,7 +5496,7 @@ fn initHeaders( |
| 5489 | 5496 | .node_align = node_block_align, |
| 5490 | 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 | 5500 | switch (elf.shdrPtr(.symtab)) { |
| 5494 | 5501 | inline else => |shdr| elf.targetStore(&shdr.link, @backingInt(Section.Index.strtab)), |
| 5495 | 5502 | } |
| ... | ... | @@ -5595,7 +5602,7 @@ fn initHeaders( |
| 5595 | 5602 | .flags = .{ .ALLOC = true }, |
| 5596 | 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 | 5606 | @memcpy(sec_interp[0..interp.len], interp); |
| 5600 | 5607 | sec_interp[interp.len] = 0; |
| 5601 | 5608 | } |
| ... | ... | @@ -5620,7 +5627,7 @@ fn initHeaders( |
| 5620 | 5627 | .node_align = node_block_align, |
| 5621 | 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 | 5631 | elf.shndx.dynstr = dynstr_shndx; |
| 5625 | 5632 | |
| 5626 | 5633 | switch (class) { |
| ... | ... | @@ -5765,7 +5772,7 @@ fn initHeaders( |
| 5765 | 5772 | .size = @sizeOf(info.Header()) + @sizeOf(info.Int()) * (8 + 1), |
| 5766 | 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 | 5776 | const header: *info.Header() = @ptrCast(hash_slice[0..@sizeOf(info.Header())]); |
| 5770 | 5777 | header.* = .{ .nbucket = 8, .nchain = 1 }; |
| 5771 | 5778 | if (elf.targetEndian() != std.lang.Endian.native) { |
| ... | ... | @@ -5779,7 +5786,7 @@ fn initHeaders( |
| 5779 | 5786 | switch (machine) { |
| 5780 | 5787 | .AARCH64, .PPC64, .RISCV => @panic(@tagName(machine)), |
| 5781 | 5788 | .X86_64 => { |
| 5782 | | const plt_ni = elf.shndx.plt.get(elf).ni; |
| 5789 | const plt_ni = elf.shndx.plt.node(elf); |
| 5783 | 5790 | const got_plt_sym: Symbol.Id = .local(elf.shndx.got_plt.get(elf).lsi); |
| 5784 | 5791 | @memcpy(plt_ni.slice(&elf.mf)[0..16], &[16]u8{ |
| 5785 | 5792 | 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // push 0x0(%rip) |
| ... | ... | @@ -5804,7 +5811,7 @@ fn initHeaders( |
| 5804 | 5811 | ); |
| 5805 | 5812 | }, |
| 5806 | 5813 | .LOONGARCH => { |
| 5807 | | const plt_ni = elf.shndx.plt.get(elf).ni; |
| 5814 | const plt_ni = elf.shndx.plt.node(elf); |
| 5808 | 5815 | const got_plt_sym: Symbol.Id = .local(elf.shndx.got_plt.get(elf).lsi); |
| 5809 | 5816 | @memcpy(plt_ni.slice(&elf.mf)[0..32], switch (class) { |
| 5810 | 5817 | .NONE, _ => unreachable, |
| ... | ... | @@ -5881,7 +5888,7 @@ fn initHeaders( |
| 5881 | 5888 | .manual_size = true, |
| 5882 | 5889 | }); |
| 5883 | 5890 | |
| 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 | 5892 | elf.eh_frame_hdr_first_symbol_reloc = |
| 5886 | 5893 | @fromBackingInt(@intCast(elf.symbol_relocs.items.len)); |
| 5887 | 5894 | try elf.dwarf.genEhFrameHdr( |
| ... | ... | @@ -5890,7 +5897,7 @@ fn initHeaders( |
| 5890 | 5897 | Symbol.Id.local(elf.shndx.eh_frame.get(elf).lsi).toTypeErased(), |
| 5891 | 5898 | ); |
| 5892 | 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 | 5901 | .size = addr_align.forward(4), |
| 5895 | 5902 | .alignment = addr_align, |
| 5896 | 5903 | }), |
| ... | ... | @@ -5937,7 +5944,7 @@ fn initHeaders( |
| 5937 | 5944 | |
| 5938 | 5945 | // Despite the name, `__dso_handle` is necessary even in static binaries. |
| 5939 | 5946 | _ = elf.addGlobalSymbol(.{ |
| 5940 | | .node = .wrap(Section.Index.text.get(elf).ni), |
| 5947 | .node = .wrap(Section.Index.text.node(elf)), |
| 5941 | 5948 | .name = "__dso_handle", |
| 5942 | 5949 | .value = Section.Index.text.vaddr(elf), |
| 5943 | 5950 | .size = 0, |
| ... | ... | @@ -5952,7 +5959,7 @@ fn initHeaders( |
| 5952 | 5959 | else => |e| return e, |
| 5953 | 5960 | }; |
| 5954 | 5961 | _ = elf.addGlobalSymbol(.{ |
| 5955 | | .node = .wrap(elf.shndx.plt.get(elf).ni), |
| 5962 | .node = .wrap(elf.shndx.plt.node(elf)), |
| 5956 | 5963 | .name = "_PROCEDURE_LINKAGE_TABLE_", |
| 5957 | 5964 | .value = elf.shndx.plt.vaddr(elf), |
| 5958 | 5965 | .size = 0, |
| ... | ... | @@ -5967,7 +5974,7 @@ fn initHeaders( |
| 5967 | 5974 | else => |e| return e, |
| 5968 | 5975 | }; |
| 5969 | 5976 | _ = elf.addGlobalSymbol(.{ |
| 5970 | | .node = .wrap(elf.shndx.got.get(elf).ni), |
| 5977 | .node = .wrap(elf.shndx.got.node(elf)), |
| 5971 | 5978 | .name = "_GLOBAL_OFFSET_TABLE_", |
| 5972 | 5979 | .value = switch (machine) { |
| 5973 | 5980 | .AARCH64, |
| ... | ... | @@ -6085,7 +6092,7 @@ fn initHeaders( |
| 6085 | 6092 | }; |
| 6086 | 6093 | if (have_dynamic) { |
| 6087 | 6094 | _ = elf.addGlobalSymbol(.{ |
| 6088 | | .node = .wrap(elf.shndx.dynamic.get(elf).ni), |
| 6095 | .node = .wrap(elf.shndx.dynamic.node(elf)), |
| 6089 | 6096 | .name = "_DYNAMIC", |
| 6090 | 6097 | .value = elf.shndx.dynamic.vaddr(elf), |
| 6091 | 6098 | .size = 0, |
| ... | ... | @@ -6868,7 +6875,7 @@ const SymPtr = union(std.elf.CLASS) { |
| 6868 | 6875 | @"64": *std.elf.Elf64.Sym, |
| 6869 | 6876 | }; |
| 6870 | 6877 | fn 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 | 6879 | switch (elf.shdrPtr(.symtab)) { |
| 6873 | 6880 | inline else => |shdr, class| { |
| 6874 | 6881 | const size = elf.targetLoad(&shdr.size); |
| ... | ... | @@ -6878,7 +6885,7 @@ fn symPtr(elf: *Elf, index: Symbol.Index) SymPtr { |
| 6878 | 6885 | } |
| 6879 | 6886 | } |
| 6880 | 6887 | fn 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 | 6889 | switch (elf.shdrPtr(elf.shndx.dynsym)) { |
| 6883 | 6890 | inline else => |shdr, class| { |
| 6884 | 6891 | const size = elf.targetLoad(&shdr.size); |
| ... | ... | @@ -6889,7 +6896,7 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr { |
| 6889 | 6896 | } |
| 6890 | 6897 | |
| 6891 | 6898 | fn 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 | 6900 | const size = elf.shndx.gnu_version.size(elf); |
| 6894 | 6901 | return @ptrCast(@alignCast(raw_slice[0..@intCast(size)])); |
| 6895 | 6902 | } |
| ... | ... | @@ -6903,7 +6910,7 @@ const VerdefEntry = extern struct { |
| 6903 | 6910 | aux: std.elf.Verdaux, |
| 6904 | 6911 | }; |
| 6905 | 6912 | fn 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 | 6914 | const size = elf.shndx.gnu_version_d.size(elf); |
| 6908 | 6915 | return @ptrCast(@alignCast(raw_slice[0..@intCast(size)])); |
| 6909 | 6916 | } |
| ... | ... | @@ -6916,7 +6923,7 @@ const VerneedEntry = extern union { |
| 6916 | 6923 | } |
| 6917 | 6924 | }; |
| 6918 | 6925 | fn 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 | 6927 | const size = elf.shndx.gnu_version_r.size(elf); |
| 6921 | 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 | 7108 | }, |
| 7102 | 7109 | }; |
| 7103 | 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 | 7112 | .alignment = alignment, |
| 7106 | 7113 | }), .{ .nav = nmi }); |
| 7107 | 7114 | nav_gop.value_ptr.* = .{ |
| ... | ... | @@ -7143,7 +7150,7 @@ fn uavMapIndex( |
| 7143 | 7150 | if (!uav_gop.found_existing) { |
| 7144 | 7151 | const shndx: Section.Index = .data_rel_ro; // TODO: it would be better to use `.rodata` if the UAV value doesn't have relocs |
| 7145 | 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 | 7154 | .moved = true, // see assert at end of `genUav` |
| 7148 | 7155 | .alignment = resolved_align, |
| 7149 | 7156 | }), .{ .uav = umi }); |
| ... | ... | @@ -7603,7 +7610,7 @@ fn loadObject( |
| 7603 | 7610 | }; |
| 7604 | 7611 | const ni = elf.addNodeAssumeCapacity( |
| 7605 | 7612 | if (opts.node_fixed) ni: { |
| 7606 | | const shndx_ni = opts.shndx.get(elf).ni; |
| 7613 | const shndx_ni = opts.shndx.node(elf); |
| 7607 | 7614 | const after_oni: MappedFile.Node.Index.Optional = after: { |
| 7608 | 7615 | const last_ni = shndx_ni.last(&elf.mf).unwrap() orelse break :after .none; |
| 7609 | 7616 | break :after switch (last_ni.position(&elf.mf)) { |
| ... | ... | @@ -7612,7 +7619,7 @@ fn loadObject( |
| 7612 | 7619 | }; |
| 7613 | 7620 | }; |
| 7614 | 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 | 7623 | .{ .input_section = @fromBackingInt(@intCast(elf.input_sections.items.len)) }, |
| 7617 | 7624 | ); |
| 7618 | 7625 | section.isi = @fromBackingInt(@intCast(elf.input_sections.items.len)); |
| ... | ... | @@ -8327,7 +8334,7 @@ fn createInitFiniArraySection( |
| 8327 | 8334 | .version = null, |
| 8328 | 8335 | }).?; |
| 8329 | 8336 | try elf.setGlobalSymbolValue(start_gsi, .{ |
| 8330 | | .node = .wrap(shndx.get(elf).ni), |
| 8337 | .node = .wrap(shndx.node(elf)), |
| 8331 | 8338 | .value = shndx.vaddr(elf), |
| 8332 | 8339 | .size = 0, |
| 8333 | 8340 | .type = .NOTYPE, |
| ... | ... | @@ -8335,7 +8342,7 @@ fn createInitFiniArraySection( |
| 8335 | 8342 | }); |
| 8336 | 8343 | try elf.updateGlobalDynamic(start_gsi, true); |
| 8337 | 8344 | try elf.setGlobalSymbolValue(end_gsi, .{ |
| 8338 | | .node = .wrap(shndx.get(elf).ni), |
| 8345 | .node = .wrap(shndx.node(elf)), |
| 8339 | 8346 | .value = shndx.vaddr(elf), |
| 8340 | 8347 | .size = 0, |
| 8341 | 8348 | .type = .NOTYPE, |
| ... | ... | @@ -8388,7 +8395,7 @@ fn prelinkInner(elf: *Elf) Error!void { |
| 8388 | 8395 | elf.shndx.debug_str_offsets, |
| 8389 | 8396 | }) |debug_shndx| { |
| 8390 | 8397 | if (debug_shndx == .UNDEF) continue; |
| 8391 | | const debug_ni = debug_shndx.get(elf).ni; |
| 8398 | const debug_ni = debug_shndx.node(elf); |
| 8392 | 8399 | const frame_format = debug_shndx.debugFrameFormat(elf); |
| 8393 | 8400 | const unit_padding_ni = elf.addNodeAssumeCapacity( |
| 8394 | 8401 | try debug_ni.addHeaderChildAfter(gpa, &elf.mf, last_header_oni: { |
| ... | ... | @@ -8444,7 +8451,7 @@ fn prelinkInner(elf: *Elf) Error!void { |
| 8444 | 8451 | .UNDEF => {}, |
| 8445 | 8452 | else => |debug_addr_shndx| { |
| 8446 | 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 | 8455 | .alignment = addr_align, |
| 8449 | 8456 | .next_moved = true, |
| 8450 | 8457 | .enable_next_moved = true, |
| ... | ... | @@ -8465,7 +8472,7 @@ fn prelinkInner(elf: *Elf) Error!void { |
| 8465 | 8472 | switch (elf.shndx.debug_abbrev) { |
| 8466 | 8473 | .UNDEF => {}, |
| 8467 | 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 | 8476 | .{ .debug_shared = .debug_abbrev }, |
| 8470 | 8477 | )), |
| 8471 | 8478 | } |
| ... | ... | @@ -8473,14 +8480,14 @@ fn prelinkInner(elf: *Elf) Error!void { |
| 8473 | 8480 | .UNDEF => {}, |
| 8474 | 8481 | else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni = |
| 8475 | 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 | 8484 | .{ .debug_shared = .debug_line_str }, |
| 8478 | 8485 | )), |
| 8479 | 8486 | } |
| 8480 | 8487 | switch (elf.shndx.debug_str) { |
| 8481 | 8488 | .UNDEF => {}, |
| 8482 | 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 | 8491 | .{ .debug_shared = .debug_str }, |
| 8485 | 8492 | )), |
| 8486 | 8493 | } |
| ... | ... | @@ -8488,7 +8495,7 @@ fn prelinkInner(elf: *Elf) Error!void { |
| 8488 | 8495 | .UNDEF => {}, |
| 8489 | 8496 | else => |debug_str_offsets_shndx| { |
| 8490 | 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 | 8499 | .alignment = switch (elf.dwarf.format) { |
| 8493 | 8500 | .@"32" => .@"4", |
| 8494 | 8501 | .@"64" => .@"8", |
| ... | ... | @@ -8549,7 +8556,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void { |
| 8549 | 8556 | else => |debug_info_shndx| { |
| 8550 | 8557 | const debug_info_ni = unit.debug_info_ni.unwrap() orelse debug_info_ni: { |
| 8551 | 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 | 8560 | .alignment = elf.mf.flags.block_size, |
| 8554 | 8561 | .enable_next_moved = true, |
| 8555 | 8562 | }), |
| ... | ... | @@ -8576,7 +8583,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void { |
| 8576 | 8583 | else => |debug_line_shndx| { |
| 8577 | 8584 | const debug_line_ni = unit.debug_line_ni.unwrap() orelse debug_line_ni: { |
| 8578 | 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 | 8587 | .alignment = elf.mf.flags.block_size, |
| 8581 | 8588 | .enable_next_moved = true, |
| 8582 | 8589 | }), |
| ... | ... | @@ -8600,7 +8607,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void { |
| 8600 | 8607 | else => |debug_rnglists_shndx| { |
| 8601 | 8608 | const debug_rnglists_ni = unit.debug_rnglists_ni.unwrap() orelse debug_rnglists_ni: { |
| 8602 | 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 | 8611 | .next_moved = true, |
| 8605 | 8612 | .enable_next_moved = true, |
| 8606 | 8613 | }), |
| ... | ... | @@ -8680,7 +8687,7 @@ fn prepareDynamic(elf: *Elf) Error!void { |
| 8680 | 8687 | |
| 8681 | 8688 | const dynamic_size = dynamic_len * 2 * elf.targetPtrSize(); |
| 8682 | 8689 | |
| 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 | 8691 | switch (elf.shdrPtr(elf.shndx.dynamic)) { |
| 8685 | 8692 | inline else => |shdr| elf.targetStore(&shdr.size, @intCast(dynamic_size)), |
| 8686 | 8693 | } |
| ... | ... | @@ -8702,7 +8709,7 @@ fn flushDynamic(elf: *Elf) void { |
| 8702 | 8709 | comp.config.pie); |
| 8703 | 8710 | |
| 8704 | 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 | 8713 | const dynamic_entries: [][2]ElfN.Addr = @ptrCast(@alignCast(dynamic_slice)); |
| 8707 | 8714 | |
| 8708 | 8715 | var dynamic_index: usize = 0; |
| ... | ... | @@ -8896,7 +8903,7 @@ fn addSection(elf: *Elf, segment_ni: MappedFile.Node.Index, opts: struct { |
| 8896 | 8903 | .type = .SECTION, |
| 8897 | 8904 | .shndx = shndx, |
| 8898 | 8905 | }) else .null, |
| 8899 | | .ni = ni, |
| 8906 | .ni = .wrap(ni), |
| 8900 | 8907 | .rela = switch (opts.type) { |
| 8901 | 8908 | .REL => unreachable, |
| 8902 | 8909 | .RELA => .{ .free_head = .none }, |
| ... | ... | @@ -8973,7 +8980,7 @@ fn ensureUnusedRelocCapacity(elf: *Elf, node: MappedFile.Node.Index, len: usize) |
| 8973 | 8980 | .NONE, _ => unreachable, |
| 8974 | 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); |
| 8977 | 8984 | |
| 8978 | 8985 | if (elf.shndx.dynamic != .UNDEF) { |
| 8979 | 8986 | try elf.shndx.rela_dyn.relaEnsureAdditionalCapacity(elf, new_got_entries); |
| ... | ... | @@ -9816,7 +9823,7 @@ fn updateGotEntry(elf: *Elf, got_index: usize) void { |
| 9816 | 9823 | const addr_size = @sizeOf(class.ElfN().Addr); |
| 9817 | 9824 | const offset = got_index * addr_size; |
| 9818 | 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 | 9828 | elf.targetStore(entry_ptr, switch (entry_value) { |
| 9822 | 9829 | .unsigned => |x| @intCast(x), |
| ... | ... | @@ -10179,7 +10186,7 @@ fn updateFuncInner( |
| 10179 | 10186 | const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_func.frame_format) { |
| 10180 | 10187 | .debug_frame => elf.shndx.debug_frame, |
| 10181 | 10188 | .eh_frame => elf.shndx.eh_frame, |
| 10182 | | }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{ |
| 10189 | }.node(elf).addFloatingChild(gpa, &elf.mf, .{ |
| 10183 | 10190 | .alignment = frame_align.max(elf.mf.flags.block_size), |
| 10184 | 10191 | .enable_next_moved = true, |
| 10185 | 10192 | }), .{ .unit_frame = wip_func.unit }); |
| ... | ... | @@ -11904,17 +11911,17 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 11904 | 11911 | const gpa = elf.base.comp.gpa; |
| 11905 | 11912 | try elf.shndx.rela_plt.relaEnsureAdditionalCapacity(elf, 1); |
| 11906 | 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 | 11915 | gpa, |
| 11909 | 11916 | &elf.mf, |
| 11910 | 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 | 11920 | gpa, |
| 11914 | 11921 | &elf.mf, |
| 11915 | 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 | 11925 | gpa, |
| 11919 | 11926 | &elf.mf, |
| 11920 | 11927 | plt_sec.entry_size * (elf.plt.count() + 1), |
| ... | ... | @@ -11962,7 +11969,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 11962 | 11969 | switch (elf.ehdrMachine()) { |
| 11963 | 11970 | .AARCH64, .PPC64, .RISCV => |machine| @panic(@tagName(machine)), |
| 11964 | 11971 | .X86_64 => { |
| 11965 | | const plt_ni = elf.shndx.plt.get(elf).ni; |
| 11972 | const plt_ni = elf.shndx.plt.node(elf); |
| 11966 | 11973 | const plt_addr = plt_addr: switch (elf.shdrPtr(elf.shndx.plt)) { |
| 11967 | 11974 | inline else => |shdr| { |
| 11968 | 11975 | const old_size = 16 * (1 + plt_index); |
| ... | ... | @@ -11986,7 +11993,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 11986 | 11993 | }, |
| 11987 | 11994 | }; |
| 11988 | 11995 | |
| 11989 | | const got_plt_ni = elf.shndx.got_plt.get(elf).ni; |
| 11996 | const got_plt_ni = elf.shndx.got_plt.node(elf); |
| 11990 | 11997 | switch (elf.shdrPtr(elf.shndx.got_plt)) { |
| 11991 | 11998 | inline else => |shdr, class| { |
| 11992 | 11999 | assert(elf.targetLoad(&shdr.size) == got_plt_offset); |
| ... | ... | @@ -12000,7 +12007,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 12000 | 12007 | }, |
| 12001 | 12008 | } |
| 12002 | 12009 | |
| 12003 | | const plt_sec_ni = elf.shndx.plt_sec.get(elf).ni; |
| 12010 | const plt_sec_ni = elf.shndx.plt_sec.node(elf); |
| 12004 | 12011 | switch (elf.shdrPtr(elf.shndx.plt_sec)) { |
| 12005 | 12012 | inline else => |shdr| { |
| 12006 | 12013 | const old_size = 16 * plt_index; |
| ... | ... | @@ -12024,7 +12031,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 12024 | 12031 | }, |
| 12025 | 12032 | .LOONGARCH => { |
| 12026 | 12033 | // 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 | 12035 | const plt_addr, const plt_slice = plt_entry: switch (elf.shdrPtr(elf.shndx.plt)) { |
| 12029 | 12036 | inline else => |shdr| { |
| 12030 | 12037 | const old_size = 16 * (1 + plt_index); |
| ... | ... | @@ -12048,7 +12055,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 12048 | 12055 | }; |
| 12049 | 12056 | |
| 12050 | 12057 | // 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 | 12059 | switch (elf.shdrPtr(elf.shndx.got_plt)) { |
| 12053 | 12060 | inline else => |shdr, class| { |
| 12054 | 12061 | assert(elf.targetLoad(&shdr.size) == got_plt_offset); |
| ... | ... | @@ -12080,7 +12087,7 @@ fn ensurePltEntry(elf: *Elf, gsi: Symbol.Global.Index) Error!bool { |
| 12080 | 12087 | }, |
| 12081 | 12088 | .SPARCV9 => { |
| 12082 | 12089 | // 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 | 12091 | switch (elf.shdrPtr(elf.shndx.plt)) { |
| 12085 | 12092 | inline else => |shdr| { |
| 12086 | 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 | 12144 | // We also need to update all of the references from `.plt.sec` to `.got.plt`. |
| 12138 | 12145 | // However, if there's also a flush pending for `.got.plt`, don't bother doing |
| 12139 | 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 | 12148 | return; |
| 12142 | 12149 | } |
| 12143 | 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 | 12159 | // We also need to update all of the references from `.plt.sec` to `.got.plt`. |
| 12153 | 12160 | // However, if there's also a flush pending for `.plt.sec`, don't bother doing |
| 12154 | 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 | 12163 | return; |
| 12157 | 12164 | } |
| 12158 | 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 | 12168 | // We are updating the references from `.plt.sec` to `.got.plt`. |
| 12162 | 12169 | const got_plt_addr = elf.shndx.got_plt.vaddr(elf); |
| 12163 | 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 | 12172 | switch (elf.identClass()) { |
| 12166 | 12173 | .NONE, _ => unreachable, |
| 12167 | 12174 | inline else => |class| { |
| ... | ... | @@ -12194,7 +12201,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad |
| 12194 | 12201 | // We also need to update all of the references from `.plt` to `.got.plt`. |
| 12195 | 12202 | // However, if there's also a flush pending for `.got.plt`, don't bother doing |
| 12196 | 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 | 12205 | return; |
| 12199 | 12206 | } |
| 12200 | 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 | 12217 | // We also need to update all of the references from `.plt` to `.got.plt`. |
| 12211 | 12218 | // However, if there's also a flush pending for `.plt`, don't bother doing |
| 12212 | 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 | 12221 | return; |
| 12215 | 12222 | } |
| 12216 | 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 | 12226 | // We are updating the references from `.plt` to `.got.plt`. |
| 12220 | 12227 | const got_plt_addr = elf.shndx.got_plt.vaddr(elf); |
| 12221 | 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 | 12230 | switch (elf.identClass()) { |
| 12224 | 12231 | .NONE, _ => unreachable, |
| 12225 | 12232 | inline else => |class| { |
| ... | ... | @@ -12657,7 +12664,7 @@ const VerdefAdapter = struct { |
| 12657 | 12664 | fn verdefId(elf: *Elf, version: String(.dynstr)) Error!u15 { |
| 12658 | 12665 | const gpa = elf.base.comp.gpa; |
| 12659 | 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 | 12668 | const gop = try elf.verdef.getOrPutAdapted(gpa, version, adapter); |
| 12662 | 12669 | |
| 12663 | 12670 | if (gop.found_existing) { |
| ... | ... | @@ -12766,7 +12773,7 @@ const VerneedAdapter = struct { |
| 12766 | 12773 | fn verneedId(elf: *Elf, file: String(.dynstr), version: String(.dynstr)) Error!u15 { |
| 12767 | 12774 | const gpa = elf.base.comp.gpa; |
| 12768 | 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)); |
| 12770 | 12777 | |
| 12771 | 12778 | if (elf.verneed.getIndexAdapted(@as(VerneedAdapter.Key, .{ |
| 12772 | 12779 | .file = file, |