authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-18 15:35:18+02:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-21 01:43:21-04:00
log517721bbccbbbe571c90226197948a9ae2430d8f
tree8e727b31609dcc56b94a3304d79a2d7734e98c82
parent56e1ae21e42b63ea4409b68950691fb89bfd1d21

elf: start unraveling Dwarf relocs into Elf relocs


2 files changed, 13 insertions(+), 3 deletions(-)

src/link/Dwarf.zig+1-1
...@@ -415,7 +415,7 @@ const Unit = struct {...@@ -415,7 +415,7 @@ const Unit = struct {
415 return entry;415 return entry;
416 }416 }
417417
418 fn getEntry(unit: *Unit, entry: Entry.Index) *Entry {418 pub fn getEntry(unit: *Unit, entry: Entry.Index) *Entry {
419 return &unit.entries.items[@intFromEnum(entry)];419 return &unit.entries.items[@intFromEnum(entry)];
420 }420 }
421421
src/link/Elf/ZigObject.zig+12-2
...@@ -180,6 +180,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi...@@ -180,6 +180,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
180 if (self.dwarf) |*dwarf| {180 if (self.dwarf) |*dwarf| {
181 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };181 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
182 try dwarf.flushModule(pt);182 try dwarf.flushModule(pt);
183 try dwarf.resolveRelocs();
183184
184 // TODO invert this logic so that we manage the output section with the atom, not the185 // TODO invert this logic so that we manage the output section with the atom, not the
185 // other way around186 // other way around
...@@ -213,8 +214,17 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi...@@ -213,8 +214,17 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
213214
214 const relocs = &self.relocs.items[atom_ptr.relocsShndx().?];215 const relocs = &self.relocs.items[atom_ptr.relocsShndx().?];
215 _ = relocs;216 _ = relocs;
216 for (sect.units.items) |unit| {217 for (sect.units.items) |*unit| {
217 _ = unit;218 for (unit.external_relocs.items) |reloc| {
219 const tsym = self.symbol(reloc.target_sym);
220 const r_offset = unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off;
221 const r_addend = reloc.target_off;
222 std.debug.print("{s} <- r_off={x}, r_add={x}\n", .{
223 tsym.name(elf_file),
224 r_offset,
225 r_addend,
226 });
227 }
218 }228 }
219 }229 }
220230