| ... | ... | @@ -1032,7 +1032,7 @@ pub const Symbol = struct { |
| 1032 | 1032 | const sym = si.get(coff); |
| 1033 | 1033 | sym.rva = coff.computeNodeRva(sym.ni) + sym.nodeOffset(coff); |
| 1034 | 1034 | si.applyLocationRelocs(coff); |
| 1035 | | si.applyTargetRelocs(coff); |
| 1035 | si.applyTargetRelocs(coff, .none); |
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | 1038 | pub fn flushSymbolTableIndex(si: Symbol.Index, coff: *Coff) void { |
| ... | ... | @@ -1065,7 +1065,7 @@ pub const Symbol = struct { |
| 1065 | 1065 | } |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | | pub fn applyTargetRelocs(si: Symbol.Index, coff: *Coff) void { |
| 1068 | pub fn applyTargetRelocs(si: Symbol.Index, coff: *Coff, end: Reloc.Index) void { |
| 1069 | 1069 | const sym = si.get(coff); |
| 1070 | 1070 | |
| 1071 | 1071 | // TODO: Would this be better modeled using an actual reloc? Would need a si for the header |
| ... | ... | @@ -1075,7 +1075,7 @@ pub const Symbol = struct { |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | var ri = sym.target_relocs; |
| 1078 | | while (ri != .none) { |
| 1078 | while (ri != end) { |
| 1079 | 1079 | const reloc = ri.get(coff); |
| 1080 | 1080 | assert(reloc.target == si); |
| 1081 | 1081 | reloc.apply(coff); |
| ... | ... | @@ -3403,7 +3403,7 @@ pub fn addReloc( |
| 3403 | 3403 | const target = target_si.get(coff); |
| 3404 | 3404 | |
| 3405 | 3405 | const ri: Reloc.Index = @enumFromInt(coff.relocs.items.len); |
| 3406 | | log.debug("addReloc({d}@{d}+{d} -> {d}@{d}+{d}{s}) = {d}", .{ |
| 3406 | log.debug("addReloc({d}@{d}+0x{x} -> {d}@{d}+0x{x}{s}) = {d}", .{ |
| 3407 | 3407 | loc_si, |
| 3408 | 3408 | loc_si.get(coff).section_number, |
| 3409 | 3409 | offset, |
| ... | ... | @@ -4306,15 +4306,15 @@ fn loadObject( |
| 4306 | 4306 | else => {}, |
| 4307 | 4307 | } |
| 4308 | 4308 | |
| 4309 | | defer log.debug("addInputSymbol({s}, 0x{x}, {t}=0x{x}, {d}) = n{d} {d}@{d}", .{ |
| 4309 | defer log.debug("addInputSymbol({s}, 0x{x}@{d}, {t}=0x{x}) = n{d} {d}@{d}", .{ |
| 4310 | 4310 | symbol.name.toSlice(coff), |
| 4311 | 4311 | index, |
| 4312 | symbol.section_number, |
| 4312 | 4313 | symbol.value, |
| 4313 | 4314 | switch (symbol.value) { |
| 4314 | 4315 | .weak_external_aux => unreachable, |
| 4315 | 4316 | inline else => |v| v, |
| 4316 | 4317 | }, |
| 4317 | | symbol.section_number, |
| 4318 | 4318 | symbol.si.get(coff).ni, |
| 4319 | 4319 | symbol.si, |
| 4320 | 4320 | symbol.si.get(coff).section_number, |
| ... | ... | @@ -5799,10 +5799,18 @@ fn aliasGlobal(coff: *Coff, gmi: Node.GlobalMapIndex, alias_si: Symbol.Index) !v |
| 5799 | 5799 | const gn = gmi.globalName(coff); |
| 5800 | 5800 | const si = gmi.symbol(coff); |
| 5801 | 5801 | const sym = si.get(coff); |
| 5802 | const alias_sym = alias_si.get(coff); |
| 5802 | 5803 | assert(sym.section_number == .UNDEFINED); |
| 5803 | 5804 | assert(sym.loc_relocs == .none); |
| 5804 | 5805 | |
| 5805 | | const alias_sym = alias_si.get(coff); |
| 5806 | log.debug("aliasGlobal({s}, {?s}) {d}->{d} ({?s})", .{ |
| 5807 | gn.name.toSlice(coff), |
| 5808 | gn.lib_name.toSlice(coff), |
| 5809 | si, |
| 5810 | alias_si, |
| 5811 | if (alias_sym.gmi != .none) alias_sym.gmi.globalName(coff).name.toSlice(coff) else null, |
| 5812 | }); |
| 5813 | |
| 5806 | 5814 | var ri = sym.target_relocs; |
| 5807 | 5815 | while (ri != .none) { |
| 5808 | 5816 | const reloc = ri.get(coff); |
| ... | ... | @@ -5812,22 +5820,19 @@ fn aliasGlobal(coff: *Coff, gmi: Node.GlobalMapIndex, alias_si: Symbol.Index) !v |
| 5812 | 5820 | reloc.next = alias_sym.target_relocs; |
| 5813 | 5821 | if (alias_sym.target_relocs != .none) |
| 5814 | 5822 | alias_sym.target_relocs.get(coff).prev = ri; |
| 5823 | break; |
| 5815 | 5824 | } |
| 5816 | 5825 | ri = reloc.next; |
| 5817 | 5826 | } |
| 5818 | 5827 | |
| 5828 | const prev_target_relocs = alias_sym.target_relocs; |
| 5829 | if (sym.target_relocs != .none) |
| 5830 | alias_sym.target_relocs = sym.target_relocs; |
| 5819 | 5831 | sym.target_relocs = .none; |
| 5820 | 5832 | sym.gmi = alias_sym.gmi; |
| 5821 | 5833 | coff.globals.values()[gmi.unwrap().?] = alias_si; |
| 5822 | | alias_si.applyTargetRelocs(coff); |
| 5823 | | |
| 5824 | | log.debug("aliasGlobal({s}, {?s}) {d}->{d} ({?s})", .{ |
| 5825 | | gn.name.toSlice(coff), |
| 5826 | | gn.lib_name.toSlice(coff), |
| 5827 | | si, |
| 5828 | | alias_si, |
| 5829 | | if (alias_sym.gmi != .none) alias_sym.gmi.globalName(coff).name.toSlice(coff) else null, |
| 5830 | | }); |
| 5834 | // Only apply the new relocs |
| 5835 | alias_si.applyTargetRelocs(coff, prev_target_relocs); |
| 5831 | 5836 | } |
| 5832 | 5837 | |
| 5833 | 5838 | fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| ... | ... | @@ -5839,8 +5844,8 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 5839 | 5844 | const is_late = gmi.unwrap().? < coff.global_pending_index; |
| 5840 | 5845 | |
| 5841 | 5846 | log.debug( |
| 5842 | | "flushGlobal({s}, {?s}, {}) = {d} ({d})", |
| 5843 | | .{ gn.name.toSlice(coff), gn.lib_name.toSlice(coff), is_late, si, sym.ni }, |
| 5847 | "flushGlobal({s}, {?s}, {}) = n{d} {d}@{d}", |
| 5848 | .{ gn.name.toSlice(coff), gn.lib_name.toSlice(coff), is_late, sym.ni, si, sym.section_number }, |
| 5844 | 5849 | ); |
| 5845 | 5850 | |
| 5846 | 5851 | if (!coff.isImage()) { |
| ... | ... | @@ -6759,7 +6764,7 @@ fn updateExportsInner( |
| 6759 | 6764 | export_sym.rva = exported_sym.rva; |
| 6760 | 6765 | export_sym.setValue(.{ .size = exported_sym.value.size }); |
| 6761 | 6766 | export_sym.section_number = exported_sym.section_number; |
| 6762 | | defer export_si.applyTargetRelocs(coff); |
| 6767 | defer export_si.applyTargetRelocs(coff, .none); |
| 6763 | 6768 | |
| 6764 | 6769 | if (coff.isImage()) { |
| 6765 | 6770 | if (@"export".opts.name.eqlSlice("_tls_used", ip)) { |