authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-12 12:17:24+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-16 09:30:27+01:00
logc6d7ab8a234cedf08cd63f14db6e020ee5bd6c34
tree82eee08b9d928dccf5feec6bef9b7cbc76d520e2
parent31500242f0c82b8d3b5e1d7a683a8a6f4c803bb2
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: delete some dead code


1 files changed, 1 insertions(+), 43 deletions(-)

src/link/Elf2.zig+1-43
...@@ -119,8 +119,6 @@ got: std.array_hash_map.Auto(GotKey, Section.RelaIndex.Optional),...@@ -119,8 +119,6 @@ got: std.array_hash_map.Auto(GotKey, Section.RelaIndex.Optional),
119plt: std.array_hash_map.Auto(String(.strtab), void),119plt: std.array_hash_map.Auto(String(.strtab), void),
120/// The `.plt` section contains zero or more symbol relocations starting at this index.120/// The `.plt` section contains zero or more symbol relocations starting at this index.
121plt_first_symbol_reloc: SymbolReloc.Index,121plt_first_symbol_reloc: SymbolReloc.Index,
122/// The `.dynamic` section contains zero or more symbol relocations starting at this index.
123dynamic_first_symbol_reloc: SymbolReloc.Index,
124122
125needed: std.array_hash_map.Auto(String(.dynstr), void),123needed: std.array_hash_map.Auto(String(.dynstr), void),
126inputs: std.ArrayList(struct {124inputs: std.ArrayList(struct {
...@@ -195,8 +193,6 @@ const Node = union(enum) {...@@ -195,8 +193,6 @@ const Node = union(enum) {
195 shdr,193 shdr,
196 segment: u32,194 segment: u32,
197 /// The section '.plt' may contain relocations via `elf.plt_first_symbol_reloc`.195 /// The section '.plt' may contain relocations via `elf.plt_first_symbol_reloc`.
198 ///
199 /// The section '.dynamic' may contain relocations via `elf.dynamic_first_symbol_reloc`.
200 section: Section.Index,196 section: Section.Index,
201 /// Only valid for static libraries, represents one non-zcu archive member.197 /// Only valid for static libraries, represents one non-zcu archive member.
202 input_member: InputIndex,198 input_member: InputIndex,
...@@ -634,11 +630,6 @@ const Section = struct {...@@ -634,11 +630,6 @@ const Section = struct {
634 const old_size = elf.targetLoad(&shdr.size);630 const old_size = elf.targetLoad(&shdr.size);
635 const new_size = old_size + ent_size;631 const new_size = old_size + ent_size;
636 elf.targetStore(&shdr.size, new_size);632 elf.targetStore(&shdr.size, new_size);
637 if (rela_shndx == elf.shndx.rela_dyn) {
638 elf.updateDynamicEntry(std.elf.DT_RELASZ, new_size);
639 } else if (rela_shndx == elf.shndx.rela_plt) {
640 elf.updateDynamicEntry(std.elf.DT_PLTRELSZ, new_size);
641 }
642 break :new_index @fromBackingInt(@intCast(@divExact(old_size, ent_size)));633 break :new_index @fromBackingInt(@intCast(@divExact(old_size, ent_size)));
643 };634 };
644 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(635 const relas: []class.ElfN().Rela = @ptrCast(@alignCast(
...@@ -3045,9 +3036,6 @@ const StringTable = struct {...@@ -3045,9 +3036,6 @@ const StringTable = struct {
3045 break :size .{ old_size, new_size };3036 break :size .{ old_size, new_size };
3046 },3037 },
3047 };3038 };
3048 if (shndx == elf.shndx.dynstr) {
3049 elf.updateDynamicEntry(std.elf.DT_STRSZ, new_size);
3050 }
3051 try elf.ensureNodeSize(ni, new_size);3039 try elf.ensureNodeSize(ni, new_size);
3052 const slice = ni.slice(&elf.mf)[old_size..];3040 const slice = ni.slice(&elf.mf)[old_size..];
3053 @memcpy(slice[0..key.len], key);3041 @memcpy(slice[0..key.len], key);
...@@ -3202,7 +3190,6 @@ fn create(...@@ -3202,7 +3190,6 @@ fn create(
3202 .got = .empty,3190 .got = .empty,
3203 .plt = .empty,3191 .plt = .empty,
3204 .plt_first_symbol_reloc = .none,3192 .plt_first_symbol_reloc = .none,
3205 .dynamic_first_symbol_reloc = .none,
3206 .needed = .empty,3193 .needed = .empty,
3207 .inputs = .empty,3194 .inputs = .empty,
3208 .input_pending_index = 0,3195 .input_pending_index = 0,
...@@ -5313,7 +5300,7 @@ fn loadObject(...@@ -5313,7 +5300,7 @@ fn loadObject(
5313 const old_size = elf.targetLoad(&shdr.size);5300 const old_size = elf.targetLoad(&shdr.size);
5314 const new_size = old_size + section.shdr.size;5301 const new_size = old_size + section.shdr.size;
5315 elf.targetStore(&shdr.size, @intCast(new_size));5302 elf.targetStore(&shdr.size, @intCast(new_size));
5316 elf.updateInitFiniArraySectionSize(shndx.*, init_fini_section_name, @"type", new_size);5303 elf.updateInitFiniArraySectionSize(shndx.*, init_fini_section_name);
5317 },5304 },
5318 }5305 }
5319 break :shndx shndx.*;5306 break :shndx shndx.*;
...@@ -5878,19 +5865,7 @@ fn updateInitFiniArraySectionSize(...@@ -5878,19 +5865,7 @@ fn updateInitFiniArraySectionSize(
5878 elf: *Elf,5865 elf: *Elf,
5879 shndx: Section.Index,5866 shndx: Section.Index,
5880 comptime name: []const u8,5867 comptime name: []const u8,
5881 @"type": std.elf.SHT,
5882 new_size: u64,
5883) void {5868) void {
5884 if (elf.shndx.dynamic != .UNDEF) {
5885 const arraysz_dyn_key: u32 = switch (@"type") {
5886 .INIT_ARRAY => std.elf.DT_INIT_ARRAYSZ,
5887 .FINI_ARRAY => std.elf.DT_FINI_ARRAYSZ,
5888 .PREINIT_ARRAY => std.elf.DT_PREINIT_ARRAYSZ,
5889 else => unreachable,
5890 };
5891 elf.updateDynamicEntry(arraysz_dyn_key, new_size);
5892 }
5893
5894 const end_vaddr: u64 = switch (elf.shdrPtr(shndx)) {5869 const end_vaddr: u64 = switch (elf.shdrPtr(shndx)) {
5895 inline else => |shdr| shndx.vaddr(elf) + elf.targetLoad(&shdr.size),5870 inline else => |shdr| shndx.vaddr(elf) + elf.targetLoad(&shdr.size),
5896 };5871 };
...@@ -7648,8 +7623,6 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void...@@ -7648,8 +7623,6 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
7648 elf.flushMovedPltSection(.got_plt, old_addr, addr);7623 elf.flushMovedPltSection(.got_plt, old_addr, addr);
7649 } else if (shndx == elf.shndx.plt_sec) {7624 } else if (shndx == elf.shndx.plt_sec) {
7650 elf.flushMovedPltSection(.plt_sec, old_addr, addr);7625 elf.flushMovedPltSection(.plt_sec, old_addr, addr);
7651 } else if (shndx == elf.shndx.dynamic) {
7652 elf.flushMovedNodeRelocs(ni, addr, elf.dynamic_first_symbol_reloc, .none);
7653 }7626 }
7654 },7627 },
7655 .input_member => {},7628 .input_member => {},
...@@ -7940,21 +7913,6 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!...@@ -7940,21 +7913,6 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!
7940 }7913 }
7941}7914}
79427915
7943fn updateDynamicEntry(elf: *Elf, key: u32, new_val: u64) void {
7944 switch (elf.shdrPtr(elf.shndx.dynamic)) {
7945 inline else => |shdr, class| {
7946 const dynamic_size = elf.targetLoad(&shdr.size);
7947 const dynamic_entries: [][2]class.ElfN().Addr = @ptrCast(@alignCast(
7948 elf.shndx.dynamic.get(elf).ni.slice(&elf.mf)[0..@intCast(dynamic_size)],
7949 ));
7950 for (dynamic_entries) |*dynamic_entry| {
7951 if (elf.targetLoad(&dynamic_entry[0]) == key) {
7952 elf.targetStore(&dynamic_entry[1], @intCast(new_val));
7953 }
7954 }
7955 },
7956 }
7957}
7958fn addPltEntry(elf: *Elf, global_name: String(.strtab), dynsym_index: u32) void {7916fn addPltEntry(elf: *Elf, global_name: String(.strtab), dynsym_index: u32) void {
7959 const target_endian = elf.targetEndian();7917 const target_endian = elf.targetEndian();
79607918