authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-15 22:46:52+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-20 23:36:41+02:00
log09820a96b691f79403291d9b2179adbae50fc33b
treeaac8065372bc1e5eb0e786e5e0f15e5a14a8a73d
parent13b403cbf728454ba4d57565485051a89bb70230

link/elf: move relocs indexes into Atom extras


2 files changed, 19 insertions(+), 13 deletions(-)

src/link/Elf/Atom.zig+15-10
......@@ -22,12 +22,6 @@ output_section_index: u32 = 0,
2222/// Index of the input section containing this atom's relocs.
2323relocs_section_index: u32 = 0,
2424
25/// Start index of the relocations belonging to this atom.
26rel_index: u32 = 0,
27
28/// Number of relocations belonging to this atom.
29rel_num: u32 = 0,
30
3125/// Index of this atom in the linker's atoms table.
3226atom_index: Index = 0,
3327
......@@ -304,11 +298,14 @@ pub fn free(self: *Atom, elf_file: *Elf) void {
304298
305299pub fn relocs(self: Atom, elf_file: *Elf) []const elf.Elf64_Rela {
306300 const shndx = self.relocsShndx() orelse return &[0]elf.Elf64_Rela{};
307 return switch (self.file(elf_file).?) {
308 .zig_object => |x| x.relocs.items[shndx].items,
309 .object => |x| x.relocs.items[self.rel_index..][0..self.rel_num],
301 switch (self.file(elf_file).?) {
302 .zig_object => |x| return x.relocs.items[shndx].items,
303 .object => |x| {
304 const extras = self.extra(elf_file).?;
305 return x.relocs.items[extras.rel_index..][0..extras.rel_count];
306 },
310307 else => unreachable,
311 };
308 }
312309}
313310
314311pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.Elf64_Rela)) !void {
......@@ -981,6 +978,8 @@ const AddExtraOpts = struct {
981978 thunk: ?u32 = null,
982979 fde_start: ?u32 = null,
983980 fde_count: ?u32 = null,
981 rel_index: ?u32 = null,
982 rel_count: ?u32 = null,
984983};
985984
986985pub fn addExtra(atom: *Atom, opts: AddExtraOpts, elf_file: *Elf) !void {
......@@ -2206,6 +2205,12 @@ pub const Extra = struct {
22062205
22072206 /// Count of FDEs referencing this atom.
22082207 fde_count: u32 = 0,
2208
2209 /// Start index of relocations belonging to this atom.
2210 rel_index: u32 = 0,
2211
2212 /// Count of relocations belonging to this atom.
2213 rel_count: u32 = 0,
22092214};
22102215
22112216const std = @import("std");
src/link/Elf/Object.zig+4-3
......@@ -242,11 +242,12 @@ fn initAtoms(self: *Object, allocator: Allocator, handle: std.fs.File, elf_file:
242242 const relocs = try self.preadRelocsAlloc(allocator, handle, @intCast(i));
243243 defer allocator.free(relocs);
244244 atom.relocs_section_index = @intCast(i);
245 atom.rel_index = @intCast(self.relocs.items.len);
246 atom.rel_num = @intCast(relocs.len);
245 const rel_index: u32 = @intCast(self.relocs.items.len);
246 const rel_count: u32 = @intCast(relocs.len);
247 try atom.addExtra(.{ .rel_index = rel_index, .rel_count = rel_count }, elf_file);
247248 try self.relocs.appendUnalignedSlice(allocator, relocs);
248249 if (elf_file.getTarget().cpu.arch == .riscv64) {
249 sortRelocs(self.relocs.items[atom.rel_index..][0..atom.rel_num]);
250 sortRelocs(self.relocs.items[rel_index..][0..rel_count]);
250251 }
251252 }
252253 },