aboutsummaryrefslogtreecommitdiff
path: root/src/link/Coff/Relocation.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-04-22 13:39:07 +0200
committerGitHub <noreply@github.com>2023-04-22 13:39:07 +0200
commitc4a63389e4eefb78c1ee2028047447094bb864dc (patch)
tree95edea0e36efa81c2a6ea8d0574feeb5ba90f25e /src/link/Coff/Relocation.zig
parent68e4a5784791f733774e161b72a283b69a75b0de (diff)
parent14dfbbc21365131c7ac85f08f543058f43fca0c2 (diff)
downloadzig-c4a63389e4eefb78c1ee2028047447094bb864dc.tar.gz
zig-c4a63389e4eefb78c1ee2028047447094bb864dc.zip
Merge pull request #15371 from ziglang/better-elf
link: make GOT (and other synthetic sections) handling common across linkers
Diffstat (limited to 'src/link/Coff/Relocation.zig')
-rw-r--r--src/link/Coff/Relocation.zig18
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;
}