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,
3131/// Index of this atom in the linker's atoms table.
3232atom_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
4034/// Points to the previous and next neighbors, based on the `text_offset`.
4135/// This can be used to find, for example, the capacity of this `TextBlock`.
4236prev_index: Index = 0,
......@@ -360,9 +354,10 @@ pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.El
360354}
361355
362356pub 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).?;
364359 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];
366361}
367362
368363pub fn markFdesDead(self: Atom, elf_file: *Elf) void {
......@@ -984,6 +979,8 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any
984979
985980const AddExtraOpts = struct {
986981 thunk: ?u32 = null,
982 fde_start: ?u32 = null,
983 fde_count: ?u32 = null,
987984};
988985
989986pub fn addExtra(atom: *Atom, opts: AddExtraOpts, elf_file: *Elf) !void {
......@@ -1046,12 +1043,13 @@ fn format2(
10461043 atom.atom_index, atom.name(elf_file), atom.address(elf_file),
10471044 atom.output_section_index, atom.alignment, atom.size,
10481045 });
1049 if (atom.fde_start != atom.fde_end) {
1046 if (atom.flags.fde) {
10501047 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| {
10521050 try writer.print("{d}", .{i});
10531051 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(", ");
10551053 }
10561054 try writer.writeAll(" }");
10571055 }
......@@ -1069,8 +1067,11 @@ pub const Flags = packed struct {
10691067 /// Specifies if the atom has been visited during garbage collection.
10701068 visited: bool = false,
10711069
1072 /// Whether this symbol has a range extension thunk.
1070 /// Whether this atom has a range extension thunk.
10731071 thunk: bool = false,
1072
1073 /// Whether this atom has FDE records.
1074 fde: bool = false,
10741075};
10751076
10761077const x86_64 = struct {
......@@ -2197,7 +2198,14 @@ const RelocsIterator = struct {
21972198};
21982199
21992200pub const Extra = struct {
2201 /// Index of the range extension thunk of this atom.
22002202 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,
22012209};
22022210
22032211const 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:
445445 while (i < self.fdes.items.len) {
446446 const fde = self.fdes.items[i];
447447 const atom = fde.atom(elf_file);
448 atom.fde_start = i;
448 const start = i;
449449 i += 1;
450450 while (i < self.fdes.items.len) : (i += 1) {
451451 const next_fde = self.fdes.items[i];
452452 if (atom.atom_index != next_fde.atom(elf_file).atom_index) break;
453453 }
454 atom.fde_end = i;
454 try atom.addExtra(.{ .fde_start = start, .fde_count = i - start }, elf_file);
455 atom.flags.fde = true;
455456 }
456457}
457458