diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-03-28 10:40:19 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-03-28 13:28:48 +0200 |
| commit | fb3345e346d26cfac01e45e3662385c587ec3462 (patch) | |
| tree | 7e1d14e03b444e44ca163c7cb52f8426e66c01cc /src/link/Coff | |
| parent | 2a5c4ea8f08d212b10d4dc8748fbaf5beddecbb6 (diff) | |
| download | zig-fb3345e346d26cfac01e45e3662385c587ec3462.tar.gz zig-fb3345e346d26cfac01e45e3662385c587ec3462.zip | |
coff: do not use atoms for synthetic import address table
Instead, introduce a custom ImportTable structure which will
act as a thunk in the MachO linker, and we will use that to
calculate the address of a pointer on-the-fly.
Additionally, fix logic in writeImportTables to allow for multiple
DLLs.
Diffstat (limited to 'src/link/Coff')
| -rw-r--r-- | src/link/Coff/Relocation.zig | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/link/Coff/Relocation.zig b/src/link/Coff/Relocation.zig index 1ba1d7a1c1..5dcb0552fc 100644 --- a/src/link/Coff/Relocation.zig +++ b/src/link/Coff/Relocation.zig @@ -45,23 +45,25 @@ 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 itab = coff_file.import_tables.get(sym.value) orelse return null; + return itab.getImportAddress(coff_file, self.target); + }, } } @@ -73,9 +75,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})", .{ |
