authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-08 12:11:55+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-08 12:11:55+01:00
logd8b1ef9430e0e383769ffa0a43750515aaa32280
tree5cf2af5e08af7ee558ff8fa3053cdc0dd2a312bd
parentae08f9bfe9c2ab5488b375ffd949609016658450

elf: adjust r_addend with offset of the original input section ref'd via STT_SECTION


1 files changed, 11 insertions(+), 5 deletions(-)

src/link/Elf/Atom.zig+11-5
...@@ -311,11 +311,17 @@ pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.El...@@ -311,11 +311,17 @@ pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.El
311 else => |r_type| r_type,311 else => |r_type| r_type,
312 };312 };
313 const r_offset = self.value + rel.r_offset;313 const r_offset = self.value + rel.r_offset;
314 const r_addend = rel.r_addend;314 var r_addend = rel.r_addend;
315 const r_sym = switch (target.type(elf_file)) {315 var r_sym: u32 = 0;
316 elf.STT_SECTION => elf_file.sectionSymbolOutputSymtabIndex(target.outputShndx().?),316 switch (target.type(elf_file)) {
317 else => target.outputSymtabIndex(elf_file),317 elf.STT_SECTION => {
318 };318 r_addend += @intCast(target.value);
319 r_sym = elf_file.sectionSymbolOutputSymtabIndex(target.outputShndx().?);
320 },
321 else => {
322 r_sym = target.outputSymtabIndex(elf_file);
323 },
324 }
319325
320 relocs_log.debug(" {s}: [{x} => {d}({s})] + {x}", .{326 relocs_log.debug(" {s}: [{x} => {d}({s})] + {x}", .{
321 fmtRelocType(r_type),327 fmtRelocType(r_type),