| ... | ... | @@ -227,22 +227,21 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct { |
| 227 | 227 | |
| 228 | 228 | // Find containing atom |
| 229 | 229 | log.debug(" | locating symbol by address @{x} in section {d}", .{ address_in_section, sect_id }); |
| 230 | | const sym_index = object.getSymbolByAddress(address_in_section, sect_id); |
| 231 | | break :sym_index sym_index; |
| 230 | const candidate = object.getSymbolByAddress(address_in_section, sect_id); |
| 231 | // Make sure we are not dealing with a local alias. |
| 232 | const atom_index = object.getAtomIndexForSymbol(candidate) orelse break :sym_index candidate; |
| 233 | const atom = zld.getAtom(atom_index); |
| 234 | break :sym_index atom.sym_index; |
| 232 | 235 | } else object.reverse_symtab_lookup[ctx.rel.r_symbolnum]; |
| 233 | 236 | |
| 234 | 237 | const sym_loc = SymbolWithLoc{ .sym_index = sym_index, .file = ctx.object_id + 1 }; |
| 235 | 238 | const sym = zld.getSymbol(sym_loc); |
| 236 | | const target = target: { |
| 237 | | if (sym.sect() and !sym.ext()) { |
| 238 | | // Make sure we are not dealing with a local alias. |
| 239 | | const atom_index = object.getAtomIndexForSymbol(sym_index) orelse break :target sym_loc; |
| 240 | | const atom = zld.getAtom(atom_index); |
| 241 | | break :target atom.getSymbolWithLoc(); |
| 242 | | } else if (object.getGlobal(sym_index)) |global_index| { |
| 243 | | break :target zld.globals.items[global_index]; |
| 244 | | } else break :target sym_loc; |
| 245 | | }; |
| 239 | const target = if (sym.sect() and !sym.ext()) |
| 240 | sym_loc |
| 241 | else if (object.getGlobal(sym_index)) |global_index| |
| 242 | zld.globals.items[global_index] |
| 243 | else |
| 244 | sym_loc; |
| 246 | 245 | log.debug(" | target %{d} ('{s}') in object({?d})", .{ |
| 247 | 246 | target.sym_index, |
| 248 | 247 | zld.getSymbolName(target), |
| ... | ... | @@ -752,7 +751,7 @@ fn resolveRelocsArm64( |
| 752 | 751 | mem.readIntLittle(i32, atom_code[rel_offset..][0..4]); |
| 753 | 752 | |
| 754 | 753 | if (rel.r_extern == 0) { |
| 755 | | const base_addr = if (target.sym_index > object.source_address_lookup.len) |
| 754 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| 756 | 755 | @intCast(i64, object.getSourceSection(@intCast(u8, rel.r_symbolnum - 1)).addr) |
| 757 | 756 | else |
| 758 | 757 | object.source_address_lookup[target.sym_index]; |
| ... | ... | @@ -902,7 +901,7 @@ fn resolveRelocsX86( |
| 902 | 901 | var addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]) + correction; |
| 903 | 902 | |
| 904 | 903 | if (rel.r_extern == 0) { |
| 905 | | const base_addr = if (target.sym_index > object.source_address_lookup.len) |
| 904 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| 906 | 905 | @intCast(i64, object.getSourceSection(@intCast(u8, rel.r_symbolnum - 1)).addr) |
| 907 | 906 | else |
| 908 | 907 | object.source_address_lookup[target.sym_index]; |
| ... | ... | @@ -925,7 +924,7 @@ fn resolveRelocsX86( |
| 925 | 924 | mem.readIntLittle(i32, atom_code[rel_offset..][0..4]); |
| 926 | 925 | |
| 927 | 926 | if (rel.r_extern == 0) { |
| 928 | | const base_addr = if (target.sym_index > object.source_address_lookup.len) |
| 927 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| 929 | 928 | @intCast(i64, object.getSourceSection(@intCast(u8, rel.r_symbolnum - 1)).addr) |
| 930 | 929 | else |
| 931 | 930 | object.source_address_lookup[target.sym_index]; |