| ... | ... | @@ -235,10 +235,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 235 | 235 | inline else => |target_sec| &@field(dwarf, @tagName(target_sec)).section, |
| 236 | 236 | }; |
| 237 | 237 | const target_unit = target_sec.getUnit(reloc.target_unit); |
| 238 | | const r_offset = unit.off + reloc.source_off + (if (reloc.source_entry.unwrap()) |source_entry| |
| 239 | | unit.header_len + unit.getEntry(source_entry).off |
| 240 | | else |
| 241 | | 0); |
| 238 | const r_offset = unit.off + reloc.source_off; |
| 242 | 239 | const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry| |
| 243 | 240 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off |
| 244 | 241 | else |
| ... | ... | @@ -257,23 +254,61 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 257 | 254 | }, self); |
| 258 | 255 | } |
| 259 | 256 | |
| 260 | | try relocs.ensureUnusedCapacity(gpa, unit.external_relocs.items.len); |
| 261 | | for (unit.external_relocs.items) |reloc| { |
| 262 | | const target_sym = self.symbol(reloc.target_sym); |
| 263 | | const r_offset = unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off; |
| 264 | | const r_addend: i64 = @intCast(reloc.target_off); |
| 265 | | const r_type = relocation.dwarf.externalRelocType(target_sym.*, dwarf.address_size, cpu_arch); |
| 266 | | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={}", .{ |
| 267 | | target_sym.name(elf_file), |
| 268 | | r_offset, |
| 269 | | r_addend, |
| 270 | | relocation.fmtRelocType(r_type, cpu_arch), |
| 271 | | }); |
| 272 | | atom_ptr.addRelocAssumeCapacity(.{ |
| 273 | | .r_offset = r_offset, |
| 274 | | .r_addend = r_addend, |
| 275 | | .r_info = (@as(u64, @intCast(reloc.target_sym)) << 32) | r_type, |
| 276 | | }, self); |
| 257 | for (unit.entries.items) |*entry| { |
| 258 | const entry_off = unit.off + unit.header_len + entry.off; |
| 259 | |
| 260 | try relocs.ensureUnusedCapacity(gpa, entry.cross_section_relocs.items.len); |
| 261 | for (entry.cross_section_relocs.items) |reloc| { |
| 262 | const target_sym_index = switch (reloc.target_sec) { |
| 263 | .debug_abbrev => self.debug_abbrev_index.?, |
| 264 | .debug_info => self.debug_info_index.?, |
| 265 | .debug_line => self.debug_line_index.?, |
| 266 | .debug_line_str => self.debug_line_str_index.?, |
| 267 | .debug_loclists => self.debug_loclists_index.?, |
| 268 | .debug_rnglists => self.debug_rnglists_index.?, |
| 269 | .debug_str => self.debug_str_index.?, |
| 270 | }; |
| 271 | const target_sec = switch (reloc.target_sec) { |
| 272 | inline else => |target_sec| &@field(dwarf, @tagName(target_sec)).section, |
| 273 | }; |
| 274 | const target_unit = target_sec.getUnit(reloc.target_unit); |
| 275 | const r_offset = entry_off + reloc.source_off; |
| 276 | const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry| |
| 277 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off |
| 278 | else |
| 279 | 0)); |
| 280 | const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch); |
| 281 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={}", .{ |
| 282 | self.symbol(target_sym_index).name(elf_file), |
| 283 | r_offset, |
| 284 | r_addend, |
| 285 | relocation.fmtRelocType(r_type, cpu_arch), |
| 286 | }); |
| 287 | atom_ptr.addRelocAssumeCapacity(.{ |
| 288 | .r_offset = r_offset, |
| 289 | .r_addend = r_addend, |
| 290 | .r_info = (@as(u64, @intCast(target_sym_index)) << 32) | r_type, |
| 291 | }, self); |
| 292 | } |
| 293 | |
| 294 | try relocs.ensureUnusedCapacity(gpa, entry.external_relocs.items.len); |
| 295 | for (entry.external_relocs.items) |reloc| { |
| 296 | const target_sym = self.symbol(reloc.target_sym); |
| 297 | const r_offset = entry_off + reloc.source_off; |
| 298 | const r_addend: i64 = @intCast(reloc.target_off); |
| 299 | const r_type = relocation.dwarf.externalRelocType(target_sym.*, dwarf.address_size, cpu_arch); |
| 300 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={}", .{ |
| 301 | target_sym.name(elf_file), |
| 302 | r_offset, |
| 303 | r_addend, |
| 304 | relocation.fmtRelocType(r_type, cpu_arch), |
| 305 | }); |
| 306 | atom_ptr.addRelocAssumeCapacity(.{ |
| 307 | .r_offset = r_offset, |
| 308 | .r_addend = r_addend, |
| 309 | .r_info = (@as(u64, @intCast(reloc.target_sym)) << 32) | r_type, |
| 310 | }, self); |
| 311 | } |
| 277 | 312 | } |
| 278 | 313 | } |
| 279 | 314 | |