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