| ... | ... | @@ -1967,17 +1967,6 @@ const Symbol = struct { |
| 1967 | 1967 | fn ptr(si: Symbol.Index, elf: *Elf) *Symbol { |
| 1968 | 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 | }; |
| 1982 | 1971 | |
| 1983 | 1972 | /// A `LocalIndex` is a raw index into the symtab like `Index`, but it guarantees that the |
| ... | ... | @@ -2064,7 +2053,7 @@ const Symbol = struct { |
| 2064 | 2053 | |
| 2065 | 2054 | // Re-apply relocations targeting this symbol |
| 2066 | 2055 | if (elf.ehdrField(.type) != .REL) { |
| 2067 | | sym_index.applyTargetRelocs(elf); |
| 2056 | sym_id.applyTargetRelocs(elf); |
| 2068 | 2057 | } |
| 2069 | 2058 | |
| 2070 | 2059 | // Update GOT entries targeting this symbol |
| ... | ... | @@ -2080,6 +2069,17 @@ const Symbol = struct { |
| 2080 | 2069 | } |
| 2081 | 2070 | } |
| 2082 | 2071 | |
| 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 | 2083 | /// Returns `true` if the target of `s` has moved, meaning the symbol's value will change at |
| 2084 | 2084 | /// some point due to a call to `flushMoved`. |
| 2085 | 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 | 4442 | elf.addPltEntry(name, global_ptr.dynsym_index); |
| 4443 | 4443 | // ...and therefore, we need to re-apply that symbol's relocations, as |
| 4444 | 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 | 6157 | // specific tracking for PLT relocations---instead just re-apply all relocations |
| 6158 | 6158 | // targeting symbols with PLT entries. |
| 6159 | 6159 | for (elf.plt.keys()) |sym| { |
| 6160 | | sym.index(elf).applyTargetRelocs(elf); |
| 6160 | sym.applyTargetRelocs(elf); |
| 6161 | 6161 | } |
| 6162 | 6162 | // We also need to update all of the references from `.plt.sec` to `.got.plt`. |
| 6163 | 6163 | // However, if there's also a flush pending for `.got.plt`, don't bother doing |