aboutsummaryrefslogtreecommitdiff
path: root/src/link/Coff/Relocation.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-03-28 18:28:48 +0200
committerGitHub <noreply@github.com>2023-03-28 18:28:48 +0200
commit43487eb3ef0933c1da53b917c44ba6070d8e5a21 (patch)
treecc3af355efe42c4503d866322caed9fad5832961 /src/link/Coff/Relocation.zig
parent5d63d1115f0f18984ed7c517c2d85224aa4da444 (diff)
parent1c5f2557894539d7620933324dad48a43a16d0ef (diff)
downloadzig-43487eb3ef0933c1da53b917c44ba6070d8e5a21.tar.gz
zig-43487eb3ef0933c1da53b917c44ba6070d8e5a21.zip
Merge pull request #15102 from ziglang/fix-15075
coff: handle multiple DLLs
Diffstat (limited to 'src/link/Coff/Relocation.zig')
-rw-r--r--src/link/Coff/Relocation.zig43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/link/Coff/Relocation.zig b/src/link/Coff/Relocation.zig
index 1ba1d7a1c1..45f3a97052 100644
--- a/src/link/Coff/Relocation.zig
+++ b/src/link/Coff/Relocation.zig
@@ -45,23 +45,30 @@ pcrel: bool,
length: u2,
dirty: bool = true,
-/// Returns an Atom which is the target node of this relocation edge (if any).
-pub fn getTargetAtomIndex(self: Relocation, coff_file: *const Coff) ?Atom.Index {
+/// 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,
- => return coff_file.getGotAtomIndexForSymbol(self.target),
-
- .direct,
- .page,
- .pageoff,
- => return coff_file.getAtomIndexForSymbol(self.target),
-
- .import,
- .import_page,
- .import_pageoff,
- => return coff_file.getImportAtomIndexForSymbol(self.target),
+ .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;
+ 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;
+ const itab = coff_file.import_tables.values()[index];
+ return itab.getImportAddress(self.target, .{
+ .coff_file = coff_file,
+ .index = index,
+ .name_off = sym.value,
+ });
+ },
}
}
@@ -73,9 +80,7 @@ pub fn resolve(self: *Relocation, atom_index: Atom.Index, coff_file: *Coff) !voi
const file_offset = source_section.pointer_to_raw_data + source_sym.value - source_section.virtual_address;
- const target_atom_index = self.getTargetAtomIndex(coff_file) orelse return;
- const target_atom = coff_file.getAtom(target_atom_index);
- const target_vaddr = target_atom.getSymbol(coff_file).value;
+ const target_vaddr = self.getTargetAddress(coff_file) orelse return;
const target_vaddr_with_addend = target_vaddr + self.addend;
log.debug(" ({x}: [() => 0x{x} ({s})) ({s}) (in file at 0x{x})", .{