| author | |
| committer | |
| log | 4f72ac265acac682541f170a1189a06350009431 |
| tree | 4724681222846d5303f56e63886e4d4ba4fe7e09 |
| parent | 414fcea162a751435f0194ed4a01785b3a0913a0 |
| signature |
This also fixes performing relocations for data symbols
of which the target symbol exists in an external object file.
We do this by checking if the target symbol was discarded,
and if so: get the new location so that we can find the
corresponding atom that belongs to said new location. Previously
it would always assume the symbol would live in the same file
as the atom/symbol that is doing the relocation.2 files changed, 6 insertions(+), 7 deletions(-)
src/arch/wasm/CodeGen.zig+1-3| ... | @@ -2355,7 +2355,7 @@ fn lowerDeclRefValue(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index) | ... | @@ -2355,7 +2355,7 @@ fn lowerDeclRefValue(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index) |
| 2355 | 2355 | ||
| 2356 | const module = self.bin_file.base.options.module.?; | 2356 | const module = self.bin_file.base.options.module.?; |
| 2357 | const decl = module.declPtr(decl_index); | 2357 | const decl = module.declPtr(decl_index); |
| 2358 | if (decl.ty.zigTypeTag() != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime()) { | 2358 | if (!decl.ty.hasRuntimeBitsIgnoreComptime()) { |
| 2359 | return WValue{ .imm32 = 0xaaaaaaaa }; | 2359 | return WValue{ .imm32 = 0xaaaaaaaa }; |
| 2360 | } | 2360 | } |
| 2361 | 2361 | ||
| ... | @@ -2394,9 +2394,7 @@ fn lowerConstant(self: *Self, val: Value, ty: Type) InnerError!WValue { | ... | @@ -2394,9 +2394,7 @@ fn lowerConstant(self: *Self, val: Value, ty: Type) InnerError!WValue { |
| 2394 | const decl_index = decl_ref_mut.data.decl_index; | 2394 | const decl_index = decl_ref_mut.data.decl_index; |
| 2395 | return self.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl_index); | 2395 | return self.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl_index); |
| 2396 | } | 2396 | } |
| 2397 | |||
| 2398 | const target = self.target; | 2397 | const target = self.target; |
| 2399 | |||
| 2400 | switch (ty.zigTypeTag()) { | 2398 | switch (ty.zigTypeTag()) { |
| 2401 | .Void => return WValue{ .none = {} }, | 2399 | .Void => return WValue{ .none = {} }, |
| 2402 | .Int => { | 2400 | .Int => { |
src/link/Wasm/Atom.zig+5-4| ... | @@ -174,13 +174,14 @@ fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wa | ... | @@ -174,13 +174,14 @@ fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wa |
| 174 | => { | 174 | => { |
| 175 | std.debug.assert(symbol.tag == .data and !symbol.isUndefined()); | 175 | std.debug.assert(symbol.tag == .data and !symbol.isUndefined()); |
| 176 | const merge_segment = wasm_bin.base.options.output_mode != .Obj; | 176 | const merge_segment = wasm_bin.base.options.output_mode != .Obj; |
| 177 | const segment_info = if (self.file) |object_index| blk: { | 177 | const target_atom_loc = wasm_bin.discarded.get(target_loc) orelse target_loc; |
| 178 | const target_atom = wasm_bin.symbol_atom.get(target_atom_loc).?; | ||
| 179 | const segment_info = if (target_atom.file) |object_index| blk: { | ||
| 178 | break :blk wasm_bin.objects.items[object_index].segment_info; | 180 | break :blk wasm_bin.objects.items[object_index].segment_info; |
| 179 | } else wasm_bin.segment_info.items; | 181 | } else wasm_bin.segment_info.items; |
| 180 | const segment_name = segment_info[symbol.index].outputName(merge_segment); | 182 | const segment_name = segment_info[symbol.index].outputName(merge_segment); |
| 181 | const atom_index = wasm_bin.data_segments.get(segment_name).?; | 183 | const segment_index = wasm_bin.data_segments.get(segment_name).?; |
| 182 | const target_atom = wasm_bin.symbol_atom.get(target_loc).?; | 184 | const segment = wasm_bin.segments.items[segment_index]; |
| 183 | const segment = wasm_bin.segments.items[atom_index]; | ||
| 184 | return target_atom.offset + segment.offset + (relocation.addend orelse 0); | 185 | return target_atom.offset + segment.offset + (relocation.addend orelse 0); |
| 185 | }, | 186 | }, |
| 186 | .R_WASM_EVENT_INDEX_LEB => return symbol.index, | 187 | .R_WASM_EVENT_INDEX_LEB => return symbol.index, |