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 {...@@ -1967,17 +1967,6 @@ const Symbol = struct {
1967 fn ptr(si: Symbol.Index, elf: *Elf) *Symbol {1967 fn ptr(si: Symbol.Index, elf: *Elf) *Symbol {
1968 return &elf.symtab.items[@intFromEnum(si)];1968 return &elf.symtab.items[@intFromEnum(si)];
1969 }1969 }
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 }
1981 };1970 };
19821971
1983 /// A `LocalIndex` is a raw index into the symtab like `Index`, but it guarantees that the1972 /// A `LocalIndex` is a raw index into the symtab like `Index`, but it guarantees that the
...@@ -2064,7 +2053,7 @@ const Symbol = struct {...@@ -2064,7 +2053,7 @@ const Symbol = struct {
20642053
2065 // Re-apply relocations targeting this symbol2054 // Re-apply relocations targeting this symbol
2066 if (elf.ehdrField(.type) != .REL) {2055 if (elf.ehdrField(.type) != .REL) {
2067 sym_index.applyTargetRelocs(elf);2056 sym_id.applyTargetRelocs(elf);
2068 }2057 }
20692058
2070 // Update GOT entries targeting this symbol2059 // Update GOT entries targeting this symbol
...@@ -2080,6 +2069,17 @@ const Symbol = struct {...@@ -2080,6 +2069,17 @@ const Symbol = struct {
2080 }2069 }
2081 }2070 }
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
2083 /// Returns `true` if the target of `s` has moved, meaning the symbol's value will change at2083 /// Returns `true` if the target of `s` has moved, meaning the symbol's value will change at
2084 /// some point due to a call to `flushMoved`.2084 /// some point due to a call to `flushMoved`.
2085 fn hasMoved(s: Symbol.Id, elf: *Elf) bool {2085 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 {...@@ -4442,7 +4442,7 @@ fn loadDso(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) !void {
4442 elf.addPltEntry(name, global_ptr.dynsym_index);4442 elf.addPltEntry(name, global_ptr.dynsym_index);
4443 // ...and therefore, we need to re-apply that symbol's relocations, as4443 // ...and therefore, we need to re-apply that symbol's relocations, as
4444 // some might be targeting its PLT entry.4444 // some might be targeting its PLT entry.
4445 global_ptr.symtab_index.applyTargetRelocs(elf);4445 Symbol.Id.global(name).applyTargetRelocs(elf);
4446 }4446 }
4447 }4447 }
4448 }4448 }
...@@ -6157,7 +6157,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -6157,7 +6157,7 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
6157 // specific tracking for PLT relocations---instead just re-apply all relocations6157 // specific tracking for PLT relocations---instead just re-apply all relocations
6158 // targeting symbols with PLT entries.6158 // targeting symbols with PLT entries.
6159 for (elf.plt.keys()) |sym| {6159 for (elf.plt.keys()) |sym| {
6160 sym.index(elf).applyTargetRelocs(elf);6160 sym.applyTargetRelocs(elf);
6161 }6161 }
6162 // We also need to update all of the references from `.plt.sec` to `.got.plt`.6162 // We also need to update all of the references from `.plt.sec` to `.got.plt`.
6163 // However, if there's also a flush pending for `.got.plt`, don't bother doing6163 // However, if there's also a flush pending for `.got.plt`, don't bother doing