diff options
Diffstat (limited to 'src/link/Coff/Relocation.zig')
| -rw-r--r-- | src/link/Coff/Relocation.zig | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/link/Coff/Relocation.zig b/src/link/Coff/Relocation.zig index 2fafa0bbdc..4449691ac0 100644 --- a/src/link/Coff/Relocation.zig +++ b/src/link/Coff/Relocation.zig @@ -48,17 +48,16 @@ dirty: bool = true, /// Returns address of the target if any. pub fn getTargetAddress(self: Relocation, coff_file: *const Coff) ?u32 { switch (self.type) { - .got, .got_page, .got_pageoff, .direct, .page, .pageoff => { - const maybe_target_atom_index = switch (self.type) { - .got, .got_page, .got_pageoff => coff_file.getGotAtomIndexForSymbol(self.target), - .direct, .page, .pageoff => coff_file.getAtomIndexForSymbol(self.target), - else => unreachable, - }; - const target_atom_index = maybe_target_atom_index orelse return null; + .got, .got_page, .got_pageoff => { + const got_index = coff_file.got_table.lookup.get(self.target) orelse return null; + const header = coff_file.sections.items(.header)[coff_file.got_section_index.?]; + return header.virtual_address + got_index * coff_file.ptr_width.size(); + }, + .direct, .page, .pageoff => { + const target_atom_index = coff_file.getAtomIndexForSymbol(self.target) orelse return null; const target_atom = coff_file.getAtom(target_atom_index); return target_atom.getSymbol(coff_file).value; }, - .import, .import_page, .import_pageoff => { const sym = coff_file.getSymbol(self.target); const index = coff_file.import_tables.getIndex(sym.value) orelse return null; @@ -74,7 +73,8 @@ pub fn getTargetAddress(self: Relocation, coff_file: *const Coff) ?u32 { /// Returns true if and only if the reloc is dirty AND the target address is available. pub fn isResolvable(self: Relocation, coff_file: *Coff) bool { - _ = self.getTargetAddress(coff_file) orelse return false; + const addr = self.getTargetAddress(coff_file) orelse return false; + if (addr == 0) return false; return self.dirty; } |
