authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-20 22:19:36+02:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-21 01:43:21-04:00
logb17bbf9e6cf9862dabac4402d9dab5cbeb3063a1
tree7556965e7b02692193003a7b4167ec61e342719f
parent6c731be3a1710f3c70a955624c30467616f1d1c0

elf: fixes after rebase


1 files changed, 56 insertions(+), 21 deletions(-)

src/link/Elf/ZigObject.zig+56-21
......@@ -235,10 +235,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
235235 inline else => |target_sec| &@field(dwarf, @tagName(target_sec)).section,
236236 };
237237 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;
242239 const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry|
243240 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off
244241 else
......@@ -257,23 +254,61 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
257254 }, self);
258255 }
259256
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 }
277312 }
278313 }
279314