authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-27 14:43:10+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-28 09:03:09+01:00
logb12c0de096b22b1ce17c73c466b645ed0631e818
treecb7918524295876c82695bd2dc8601fc3f51dd0d
parent98165680582b4d592adb0a057ae2e00d74922e61
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: move applyTargetRelocs to Symbol.Id

This is just a little more efficient since it may avoid some hashmap lookups when applying relocations.

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

src/link/Elf2.zig+14-14
......@@ -1967,17 +1967,6 @@ const Symbol = struct {
19671967 fn ptr(si: Symbol.Index, elf: *Elf) *Symbol {
19681968 return &elf.symtab.items[@intFromEnum(si)];
19691969 }
1970
1971 fn applyTargetRelocs(si: Symbol.Index, elf: *Elf) void {
1972 assert(elf.ehdrField(.type) != .REL);
1973 var ri = si.ptr(elf).first_target_reloc;
1974 while (ri != .none) {
1975 const reloc = ri.get(elf);
1976 assert(reloc.target.index(elf) == si);
1977 reloc.apply(elf);
1978 ri = reloc.next;
1979 }
1980 }
19811970 };
19821971
19831972 /// A `LocalIndex` is a raw index into the symtab like `Index`, but it guarantees that the
......@@ -2064,7 +2053,7 @@ const Symbol = struct {
20642053
20652054 // Re-apply relocations targeting this symbol
20662055 if (elf.ehdrField(.type) != .REL) {
2067 sym_index.applyTargetRelocs(elf);
2056 sym_id.applyTargetRelocs(elf);
20682057 }
20692058
20702059 // Update GOT entries targeting this symbol
......@@ -2080,6 +2069,17 @@ const Symbol = struct {
20802069 }
20812070 }
20822071
2072 fn applyTargetRelocs(sym_id: Symbol.Id, elf: *Elf) void {
2073 assert(elf.ehdrField(.type) != .REL);
2074 var ri = sym_id.index(elf).ptr(elf).first_target_reloc;
2075 while (ri != .none) {
2076 const reloc = ri.get(elf);
2077 assert(reloc.target == sym_id);
2078 reloc.apply(elf);
2079 ri = reloc.next;
2080 }
2081 }
2082
20832083 /// Returns `true` if the target of `s` has moved, meaning the symbol's value will change at
20842084 /// some point due to a call to `flushMoved`.
20852085 fn hasMoved(s: Symbol.Id, elf: *Elf) bool {
......@@ -4442,7 +4442,7 @@ fn loadDso(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) !void {
44424442 elf.addPltEntry(name, global_ptr.dynsym_index);
44434443 // ...and therefore, we need to re-apply that symbol's relocations, as
44444444 // some might be targeting its PLT entry.
4445 global_ptr.symtab_index.applyTargetRelocs(elf);
4445 Symbol.Id.global(name).applyTargetRelocs(elf);
44464446 }
44474447 }
44484448 }
......@@ -6157,7 +6157,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
61576157 // specific tracking for PLT relocations---instead just re-apply all relocations
61586158 // targeting symbols with PLT entries.
61596159 for (elf.plt.keys()) |sym| {
6160 sym.index(elf).applyTargetRelocs(elf);
6160 sym.applyTargetRelocs(elf);
61616161 }
61626162 // We also need to update all of the references from `.plt.sec` to `.got.plt`.
61636163 // However, if there's also a flush pending for `.got.plt`, don't bother doing