authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-15 22:20:45+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-20 23:36:41+02:00
log13b403cbf728454ba4d57565485051a89bb70230
tree1a08d8d82ea5bcb7e64b125fe4c1abde0a63b8b0
parentd5fdb7315f2f5742c58af547909437401651ffd5

link/elf: move fde record indexes into Atom extras


2 files changed, 23 insertions(+), 14 deletions(-)

src/link/Elf/Atom.zig+20-12
...@@ -31,12 +31,6 @@ rel_num: u32 = 0,...@@ -31,12 +31,6 @@ rel_num: u32 = 0,
31/// Index of this atom in the linker's atoms table.31/// Index of this atom in the linker's atoms table.
32atom_index: Index = 0,32atom_index: Index = 0,
3333
34/// Start index of FDEs referencing this atom.
35fde_start: u32 = 0,
36
37/// End index of FDEs referencing this atom.
38fde_end: u32 = 0,
39
40/// Points to the previous and next neighbors, based on the `text_offset`.34/// Points to the previous and next neighbors, based on the `text_offset`.
41/// This can be used to find, for example, the capacity of this `TextBlock`.35/// This can be used to find, for example, the capacity of this `TextBlock`.
42prev_index: Index = 0,36prev_index: Index = 0,
...@@ -360,9 +354,10 @@ pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.El...@@ -360,9 +354,10 @@ pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.El
360}354}
361355
362pub fn fdes(self: Atom, elf_file: *Elf) []Fde {356pub fn fdes(self: Atom, elf_file: *Elf) []Fde {
363 if (self.fde_start == self.fde_end) return &[0]Fde{};357 if (!self.flags.fde) return &[0]Fde{};
358 const extras = self.extra(elf_file).?;
364 const object = self.file(elf_file).?.object;359 const object = self.file(elf_file).?.object;
365 return object.fdes.items[self.fde_start..self.fde_end];360 return object.fdes.items[extras.fde_start..][0..extras.fde_count];
366}361}
367362
368pub fn markFdesDead(self: Atom, elf_file: *Elf) void {363pub fn markFdesDead(self: Atom, elf_file: *Elf) void {
...@@ -984,6 +979,8 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any...@@ -984,6 +979,8 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any
984979
985const AddExtraOpts = struct {980const AddExtraOpts = struct {
986 thunk: ?u32 = null,981 thunk: ?u32 = null,
982 fde_start: ?u32 = null,
983 fde_count: ?u32 = null,
987};984};
988985
989pub fn addExtra(atom: *Atom, opts: AddExtraOpts, elf_file: *Elf) !void {986pub fn addExtra(atom: *Atom, opts: AddExtraOpts, elf_file: *Elf) !void {
...@@ -1046,12 +1043,13 @@ fn format2(...@@ -1046,12 +1043,13 @@ fn format2(
1046 atom.atom_index, atom.name(elf_file), atom.address(elf_file),1043 atom.atom_index, atom.name(elf_file), atom.address(elf_file),
1047 atom.output_section_index, atom.alignment, atom.size,1044 atom.output_section_index, atom.alignment, atom.size,
1048 });1045 });
1049 if (atom.fde_start != atom.fde_end) {1046 if (atom.flags.fde) {
1050 try writer.writeAll(" : fdes{ ");1047 try writer.writeAll(" : fdes{ ");
1051 for (atom.fdes(elf_file), atom.fde_start..) |fde, i| {1048 const extras = atom.extra(elf_file).?;
1049 for (atom.fdes(elf_file), extras.fde_start..) |fde, i| {
1052 try writer.print("{d}", .{i});1050 try writer.print("{d}", .{i});
1053 if (!fde.alive) try writer.writeAll("([*])");1051 if (!fde.alive) try writer.writeAll("([*])");
1054 if (i < atom.fde_end - 1) try writer.writeAll(", ");1052 if (i - extras.fde_start < extras.fde_count - 1) try writer.writeAll(", ");
1055 }1053 }
1056 try writer.writeAll(" }");1054 try writer.writeAll(" }");
1057 }1055 }
...@@ -1069,8 +1067,11 @@ pub const Flags = packed struct {...@@ -1069,8 +1067,11 @@ pub const Flags = packed struct {
1069 /// Specifies if the atom has been visited during garbage collection.1067 /// Specifies if the atom has been visited during garbage collection.
1070 visited: bool = false,1068 visited: bool = false,
10711069
1072 /// Whether this symbol has a range extension thunk.1070 /// Whether this atom has a range extension thunk.
1073 thunk: bool = false,1071 thunk: bool = false,
1072
1073 /// Whether this atom has FDE records.
1074 fde: bool = false,
1074};1075};
10751076
1076const x86_64 = struct {1077const x86_64 = struct {
...@@ -2197,7 +2198,14 @@ const RelocsIterator = struct {...@@ -2197,7 +2198,14 @@ const RelocsIterator = struct {
2197};2198};
21982199
2199pub const Extra = struct {2200pub const Extra = struct {
2201 /// Index of the range extension thunk of this atom.
2200 thunk: u32 = 0,2202 thunk: u32 = 0,
2203
2204 /// Start index of FDEs referencing this atom.
2205 fde_start: u32 = 0,
2206
2207 /// Count of FDEs referencing this atom.
2208 fde_count: u32 = 0,
2201};2209};
22022210
2203const std = @import("std");2211const std = @import("std");
src/link/Elf/Object.zig+3-2
...@@ -445,13 +445,14 @@ fn parseEhFrame(self: *Object, allocator: Allocator, handle: std.fs.File, shndx:...@@ -445,13 +445,14 @@ fn parseEhFrame(self: *Object, allocator: Allocator, handle: std.fs.File, shndx:
445 while (i < self.fdes.items.len) {445 while (i < self.fdes.items.len) {
446 const fde = self.fdes.items[i];446 const fde = self.fdes.items[i];
447 const atom = fde.atom(elf_file);447 const atom = fde.atom(elf_file);
448 atom.fde_start = i;448 const start = i;
449 i += 1;449 i += 1;
450 while (i < self.fdes.items.len) : (i += 1) {450 while (i < self.fdes.items.len) : (i += 1) {
451 const next_fde = self.fdes.items[i];451 const next_fde = self.fdes.items[i];
452 if (atom.atom_index != next_fde.atom(elf_file).atom_index) break;452 if (atom.atom_index != next_fde.atom(elf_file).atom_index) break;
453 }453 }
454 atom.fde_end = i;454 try atom.addExtra(.{ .fde_start = start, .fde_count = i - start }, elf_file);
455 atom.flags.fde = true;
455 }456 }
456}457}
457458