aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-03-01 22:03:18 +0100
committerJakub Konka <kubkon@jakubkonka.com>2022-03-01 22:03:18 +0100
commite8eb9778cccd2f2d23027d9e0d73d7053bf92efe (patch)
treea658c7381f29593222e059ad541d006afd9e310c /src/link.zig
parent543bee0adf2d3b036654fa0983c16ff7023f504c (diff)
downloadzig-e8eb9778cccd2f2d23027d9e0d73d7053bf92efe.tar.gz
zig-e8eb9778cccd2f2d23027d9e0d73d7053bf92efe.zip
codegen: lower field_ptr to memory across linking backends
This requires generating an addend for the target relocation as the field pointer might point at a field inner to the container.
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/link.zig b/src/link.zig
index 46314327d9..996622443a 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -685,16 +685,22 @@ pub const File = struct {
}
}
+ pub const RelocInfo = struct {
+ parent_atom_index: u32,
+ offset: u64,
+ addend: u32,
+ };
+
/// Get allocated `Decl`'s address in virtual memory.
/// The linker is passed information about the containing atom, `parent_atom_index`, and offset within it's
/// memory buffer, `offset`, so that it can make a note of potential relocation sites, should the
/// `Decl`'s address was not yet resolved, or the containing atom gets moved in virtual memory.
- pub fn getDeclVAddr(base: *File, decl: *const Module.Decl, parent_atom_index: u32, offset: u64) !u64 {
+ pub fn getDeclVAddr(base: *File, decl: *const Module.Decl, reloc_info: RelocInfo) !u64 {
switch (base.tag) {
- .coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl, parent_atom_index, offset),
- .elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl, parent_atom_index, offset),
- .macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl, parent_atom_index, offset),
- .plan9 => return @fieldParentPtr(Plan9, "base", base).getDeclVAddr(decl, parent_atom_index, offset),
+ .coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl, reloc_info),
+ .elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl, reloc_info),
+ .macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl, reloc_info),
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).getDeclVAddr(decl, reloc_info),
.c => unreachable,
.wasm => unreachable,
.spirv => unreachable,