| ... | @@ -195,15 +195,15 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi | ... | @@ -195,15 +195,15 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 195 | self.debug_line_str_index.?, | 195 | self.debug_line_str_index.?, |
| 196 | self.debug_loclists_index.?, | 196 | self.debug_loclists_index.?, |
| 197 | self.debug_rnglists_index.?, | 197 | self.debug_rnglists_index.?, |
| 198 | }, [_]Dwarf.Section{ | 198 | }, [_]*Dwarf.Section{ |
| 199 | dwarf.debug_info.section, | 199 | &dwarf.debug_info.section, |
| 200 | dwarf.debug_abbrev.section, | 200 | &dwarf.debug_abbrev.section, |
| 201 | dwarf.debug_str.section, | 201 | &dwarf.debug_str.section, |
| 202 | dwarf.debug_aranges.section, | 202 | &dwarf.debug_aranges.section, |
| 203 | dwarf.debug_line.section, | 203 | &dwarf.debug_line.section, |
| 204 | dwarf.debug_line_str.section, | 204 | &dwarf.debug_line_str.section, |
| 205 | dwarf.debug_loclists.section, | 205 | &dwarf.debug_loclists.section, |
| 206 | dwarf.debug_rnglists.section, | 206 | &dwarf.debug_rnglists.section, |
| 207 | }) |sym_index, sect| { | 207 | }) |sym_index, sect| { |
| 208 | const sym = self.symbol(sym_index); | 208 | const sym = self.symbol(sym_index); |
| 209 | const atom_ptr = self.atom(sym.ref.index).?; | 209 | const atom_ptr = self.atom(sym.ref.index).?; |
| ... | @@ -215,11 +215,52 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi | ... | @@ -215,11 +215,52 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 215 | atom_ptr.size = shdr.sh_size; | 215 | atom_ptr.size = shdr.sh_size; |
| 216 | atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(shdr.sh_addralign); | 216 | atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(shdr.sh_addralign); |
| 217 | | 217 | |
| | 218 | log.debug("parsing relocs in {s}", .{sym.name(elf_file)}); |
| | 219 | |
| 218 | const relocs = &self.relocs.items[atom_ptr.relocsShndx().?]; | 220 | const relocs = &self.relocs.items[atom_ptr.relocsShndx().?]; |
| 219 | for (sect.units.items) |*unit| { | 221 | for (sect.units.items) |*unit| { |
| | 222 | try relocs.ensureUnusedCapacity(gpa, unit.cross_section_relocs.items.len); |
| | 223 | for (unit.cross_section_relocs.items) |reloc| { |
| | 224 | const target_sym_index = switch (reloc.target_sec) { |
| | 225 | .debug_abbrev => self.debug_abbrev_index.?, |
| | 226 | .debug_info => self.debug_info_index.?, |
| | 227 | .debug_line => self.debug_line_index.?, |
| | 228 | .debug_line_str => self.debug_line_str_index.?, |
| | 229 | .debug_loclists => self.debug_loclists_index.?, |
| | 230 | .debug_rnglists => self.debug_rnglists_index.?, |
| | 231 | .debug_str => self.debug_str_index.?, |
| | 232 | }; |
| | 233 | const target_sec = switch (reloc.target_sec) { |
| | 234 | inline else => |target_sec| &@field(dwarf, @tagName(target_sec)).section, |
| | 235 | }; |
| | 236 | const target_unit = target_sec.getUnit(reloc.target_unit); |
| | 237 | const r_offset = unit.off + reloc.source_off + (if (reloc.source_entry.unwrap()) |source_entry| |
| | 238 | unit.header_len + unit.getEntry(source_entry).off |
| | 239 | else |
| | 240 | 0); |
| | 241 | const r_addend: i64 = @intCast(reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry| |
| | 242 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off |
| | 243 | else |
| | 244 | 0)); |
| | 245 | const r_type: elf.R_X86_64 = switch (dwarf.format) { |
| | 246 | .@"32" => .@"32", |
| | 247 | .@"64" => .@"64", |
| | 248 | }; |
| | 249 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={s}", .{ |
| | 250 | self.symbol(target_sym_index).name(elf_file), |
| | 251 | r_offset, |
| | 252 | r_addend, |
| | 253 | @tagName(r_type), |
| | 254 | }); |
| | 255 | atom_ptr.addRelocAssumeCapacity(.{ |
| | 256 | .r_offset = r_offset, |
| | 257 | .r_addend = r_addend, |
| | 258 | .r_info = (@as(u64, @intCast(target_sym_index)) << 32) | @intFromEnum(r_type), |
| | 259 | }, self); |
| | 260 | } |
| | 261 | |
| 220 | try relocs.ensureUnusedCapacity(gpa, unit.external_relocs.items.len); | 262 | try relocs.ensureUnusedCapacity(gpa, unit.external_relocs.items.len); |
| 221 | for (unit.external_relocs.items) |reloc| { | 263 | for (unit.external_relocs.items) |reloc| { |
| 222 | const tsym = self.symbol(reloc.target_sym); | | |
| 223 | const r_offset = unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off; | 264 | const r_offset = unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off; |
| 224 | const r_addend: i64 = @intCast(reloc.target_off); | 265 | const r_addend: i64 = @intCast(reloc.target_off); |
| 225 | const r_type: elf.R_X86_64 = switch (dwarf.address_size) { | 266 | const r_type: elf.R_X86_64 = switch (dwarf.address_size) { |
| ... | @@ -227,8 +268,8 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi | ... | @@ -227,8 +268,8 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 227 | .@"64" => .@"64", | 268 | .@"64" => .@"64", |
| 228 | else => unreachable, | 269 | else => unreachable, |
| 229 | }; | 270 | }; |
| 230 | log.debug("{s} <- r_off={x}, r_add={x}, r_type={s}\n", .{ | 271 | log.debug(" {s} <- r_off={x}, r_add={x}, r_type={s}", .{ |
| 231 | tsym.name(elf_file), | 272 | self.symbol(reloc.target_sym).name(elf_file), |
| 232 | r_offset, | 273 | r_offset, |
| 233 | r_addend, | 274 | r_addend, |
| 234 | @tagName(r_type), | 275 | @tagName(r_type), |