diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-04-15 22:46:52 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-04-20 23:36:41 +0200 |
| commit | 09820a96b691f79403291d9b2179adbae50fc33b (patch) | |
| tree | aac8065372bc1e5eb0e786e5e0f15e5a14a8a73d /src | |
| parent | 13b403cbf728454ba4d57565485051a89bb70230 (diff) | |
| download | zig-09820a96b691f79403291d9b2179adbae50fc33b.tar.gz zig-09820a96b691f79403291d9b2179adbae50fc33b.zip | |
link/elf: move relocs indexes into Atom extras
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf/Atom.zig | 25 | ||||
| -rw-r--r-- | src/link/Elf/Object.zig | 7 |
2 files changed, 19 insertions, 13 deletions
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index 0637e1a812..68b1f701dc 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -22,12 +22,6 @@ output_section_index: u32 = 0, /// Index of the input section containing this atom's relocs. relocs_section_index: u32 = 0, -/// Start index of the relocations belonging to this atom. -rel_index: u32 = 0, - -/// Number of relocations belonging to this atom. -rel_num: u32 = 0, - /// Index of this atom in the linker's atoms table. atom_index: Index = 0, @@ -304,11 +298,14 @@ pub fn free(self: *Atom, elf_file: *Elf) void { pub fn relocs(self: Atom, elf_file: *Elf) []const elf.Elf64_Rela { const shndx = self.relocsShndx() orelse return &[0]elf.Elf64_Rela{}; - return switch (self.file(elf_file).?) { - .zig_object => |x| x.relocs.items[shndx].items, - .object => |x| x.relocs.items[self.rel_index..][0..self.rel_num], + switch (self.file(elf_file).?) { + .zig_object => |x| return x.relocs.items[shndx].items, + .object => |x| { + const extras = self.extra(elf_file).?; + return x.relocs.items[extras.rel_index..][0..extras.rel_count]; + }, else => unreachable, - }; + } } pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.Elf64_Rela)) !void { @@ -981,6 +978,8 @@ const AddExtraOpts = struct { thunk: ?u32 = null, fde_start: ?u32 = null, fde_count: ?u32 = null, + rel_index: ?u32 = null, + rel_count: ?u32 = null, }; pub fn addExtra(atom: *Atom, opts: AddExtraOpts, elf_file: *Elf) !void { @@ -2206,6 +2205,12 @@ pub const Extra = struct { /// Count of FDEs referencing this atom. fde_count: u32 = 0, + + /// Start index of relocations belonging to this atom. + rel_index: u32 = 0, + + /// Count of relocations belonging to this atom. + rel_count: u32 = 0, }; const std = @import("std"); diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index b196da4667..9bbc503238 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -242,11 +242,12 @@ fn initAtoms(self: *Object, allocator: Allocator, handle: std.fs.File, elf_file: const relocs = try self.preadRelocsAlloc(allocator, handle, @intCast(i)); defer allocator.free(relocs); atom.relocs_section_index = @intCast(i); - atom.rel_index = @intCast(self.relocs.items.len); - atom.rel_num = @intCast(relocs.len); + const rel_index: u32 = @intCast(self.relocs.items.len); + const rel_count: u32 = @intCast(relocs.len); + try atom.addExtra(.{ .rel_index = rel_index, .rel_count = rel_count }, elf_file); try self.relocs.appendUnalignedSlice(allocator, relocs); if (elf_file.getTarget().cpu.arch == .riscv64) { - sortRelocs(self.relocs.items[atom.rel_index..][0..atom.rel_num]); + sortRelocs(self.relocs.items[rel_index..][0..rel_count]); } } }, |
