elf: start unraveling Dwarf relocs into Elf relocs

This commit is contained in:
Jakub Konka 2024-08-18 15:35:18 +02:00 committed by Jacob Young
parent 56e1ae21e4
commit 517721bbcc
2 changed files with 13 additions and 3 deletions

View File

@ -415,7 +415,7 @@ const Unit = struct {
return entry;
}
fn getEntry(unit: *Unit, entry: Entry.Index) *Entry {
pub fn getEntry(unit: *Unit, entry: Entry.Index) *Entry {
return &unit.entries.items[@intFromEnum(entry)];
}

View File

@ -180,6 +180,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
if (self.dwarf) |*dwarf| {
const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
try dwarf.flushModule(pt);
try dwarf.resolveRelocs();
// TODO invert this logic so that we manage the output section with the atom, not the
// other way around
@ -213,8 +214,17 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
const relocs = &self.relocs.items[atom_ptr.relocsShndx().?];
_ = relocs;
for (sect.units.items) |unit| {
_ = unit;
for (sect.units.items) |*unit| {
for (unit.external_relocs.items) |reloc| {
const tsym = self.symbol(reloc.target_sym);
const r_offset = unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off;
const r_addend = reloc.target_off;
std.debug.print("{s} <- r_off={x}, r_add={x}\n", .{
tsym.name(elf_file),
r_offset,
r_addend,
});
}
}
}