authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 09:13:49+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 09:13:49+01:00
log9fdc32c96e3961ae2f5287483c9638051df34180
tree6e6d6ca89cf83d91e46f16da58fc92d1a315aca1
parentc430e9afa7b050400b9703360a0af4ab824335ce

link: clean up type resolution in Elf.Atom and MachO.Atom


3 files changed, 12 insertions(+), 12 deletions(-)

src/link/Coff/Atom.zig+1-1
...@@ -119,7 +119,7 @@ pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void...@@ -119,7 +119,7 @@ pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void
119 try gop.value_ptr.append(gpa, offset);119 try gop.value_ptr.append(gpa, offset);
120}120}
121121
122pub fn freeRelocations(coff_file: *Coff, atom_index: Atom.Index) void {122pub fn freeRelocations(coff_file: *Coff, atom_index: Index) void {
123 const gpa = coff_file.base.allocator;123 const gpa = coff_file.base.allocator;
124 var removed_relocs = coff_file.relocs.fetchRemove(atom_index);124 var removed_relocs = coff_file.relocs.fetchRemove(atom_index);
125 if (removed_relocs) |*relocs| relocs.value.deinit(gpa);125 if (removed_relocs) |*relocs| relocs.value.deinit(gpa);
src/link/Elf/Atom.zig+2-2
...@@ -20,8 +20,8 @@ offset_table_index: u32,...@@ -20,8 +20,8 @@ offset_table_index: u32,
2020
21/// Points to the previous and next neighbors, based on the `text_offset`.21/// Points to the previous and next neighbors, based on the `text_offset`.
22/// This can be used to find, for example, the capacity of this `TextBlock`.22/// This can be used to find, for example, the capacity of this `TextBlock`.
23prev_index: ?Atom.Index,23prev_index: ?Index,
24next_index: ?Atom.Index,24next_index: ?Index,
2525
26dbg_info_atom: Dwarf.Atom,26dbg_info_atom: Dwarf.Atom,
2727
src/link/MachO/Atom.zig+9-9
...@@ -40,8 +40,8 @@ alignment: u32,...@@ -40,8 +40,8 @@ alignment: u32,
4040
41/// Points to the previous and next neighbours41/// Points to the previous and next neighbours
42/// TODO use the same trick as with symbols: reserve index 0 as null atom42/// TODO use the same trick as with symbols: reserve index 0 as null atom
43next_index: ?Atom.Index,43next_index: ?Index,
44prev_index: ?Atom.Index,44prev_index: ?Index,
4545
46dbg_info_atom: Dwarf.Atom,46dbg_info_atom: Dwarf.Atom,
4747
...@@ -119,13 +119,13 @@ pub fn freeListEligible(self: Atom, macho_file: *MachO) bool {...@@ -119,13 +119,13 @@ pub fn freeListEligible(self: Atom, macho_file: *MachO) bool {
119 return surplus >= MachO.min_text_capacity;119 return surplus >= MachO.min_text_capacity;
120}120}
121121
122pub fn addRelocation(macho_file: *MachO, atom_index: Atom.Index, reloc: Relocation) !void {122pub fn addRelocation(macho_file: *MachO, atom_index: Index, reloc: Relocation) !void {
123 return addRelocations(macho_file, atom_index, 1, .{reloc});123 return addRelocations(macho_file, atom_index, 1, .{reloc});
124}124}
125125
126pub fn addRelocations(126pub fn addRelocations(
127 macho_file: *MachO,127 macho_file: *MachO,
128 atom_index: Atom.Index,128 atom_index: Index,
129 comptime count: comptime_int,129 comptime count: comptime_int,
130 relocs: [count]Relocation,130 relocs: [count]Relocation,
131) !void {131) !void {
...@@ -145,7 +145,7 @@ pub fn addRelocations(...@@ -145,7 +145,7 @@ pub fn addRelocations(
145 }145 }
146}146}
147147
148pub fn addRebase(macho_file: *MachO, atom_index: Atom.Index, offset: u32) !void {148pub fn addRebase(macho_file: *MachO, atom_index: Index, offset: u32) !void {
149 const gpa = macho_file.base.allocator;149 const gpa = macho_file.base.allocator;
150 const atom = macho_file.getAtom(atom_index);150 const atom = macho_file.getAtom(atom_index);
151 log.debug(" (adding rebase at offset 0x{x} in %{?d})", .{ offset, atom.getSymbolIndex() });151 log.debug(" (adding rebase at offset 0x{x} in %{?d})", .{ offset, atom.getSymbolIndex() });
...@@ -156,7 +156,7 @@ pub fn addRebase(macho_file: *MachO, atom_index: Atom.Index, offset: u32) !void...@@ -156,7 +156,7 @@ pub fn addRebase(macho_file: *MachO, atom_index: Atom.Index, offset: u32) !void
156 try gop.value_ptr.append(gpa, offset);156 try gop.value_ptr.append(gpa, offset);
157}157}
158158
159pub fn addBinding(macho_file: *MachO, atom_index: Atom.Index, binding: Binding) !void {159pub fn addBinding(macho_file: *MachO, atom_index: Index, binding: Binding) !void {
160 const gpa = macho_file.base.allocator;160 const gpa = macho_file.base.allocator;
161 const atom = macho_file.getAtom(atom_index);161 const atom = macho_file.getAtom(atom_index);
162 log.debug(" (adding binding to symbol {s} at offset 0x{x} in %{?d})", .{162 log.debug(" (adding binding to symbol {s} at offset 0x{x} in %{?d})", .{
...@@ -171,7 +171,7 @@ pub fn addBinding(macho_file: *MachO, atom_index: Atom.Index, binding: Binding)...@@ -171,7 +171,7 @@ pub fn addBinding(macho_file: *MachO, atom_index: Atom.Index, binding: Binding)
171 try gop.value_ptr.append(gpa, binding);171 try gop.value_ptr.append(gpa, binding);
172}172}
173173
174pub fn addLazyBinding(macho_file: *MachO, atom_index: Atom.Index, binding: Binding) !void {174pub fn addLazyBinding(macho_file: *MachO, atom_index: Index, binding: Binding) !void {
175 const gpa = macho_file.base.allocator;175 const gpa = macho_file.base.allocator;
176 const atom = macho_file.getAtom(atom_index);176 const atom = macho_file.getAtom(atom_index);
177 log.debug(" (adding lazy binding to symbol {s} at offset 0x{x} in %{?d})", .{177 log.debug(" (adding lazy binding to symbol {s} at offset 0x{x} in %{?d})", .{
...@@ -186,7 +186,7 @@ pub fn addLazyBinding(macho_file: *MachO, atom_index: Atom.Index, binding: Bindi...@@ -186,7 +186,7 @@ pub fn addLazyBinding(macho_file: *MachO, atom_index: Atom.Index, binding: Bindi
186 try gop.value_ptr.append(gpa, binding);186 try gop.value_ptr.append(gpa, binding);
187}187}
188188
189pub fn resolveRelocations(macho_file: *MachO, atom_index: Atom.Index) !void {189pub fn resolveRelocations(macho_file: *MachO, atom_index: Index) !void {
190 const atom = macho_file.getAtom(atom_index);190 const atom = macho_file.getAtom(atom_index);
191 const relocs = macho_file.relocs.get(atom_index) orelse return;191 const relocs = macho_file.relocs.get(atom_index) orelse return;
192 const source_sym = atom.getSymbol(macho_file);192 const source_sym = atom.getSymbol(macho_file);
...@@ -203,7 +203,7 @@ pub fn resolveRelocations(macho_file: *MachO, atom_index: Atom.Index) !void {...@@ -203,7 +203,7 @@ pub fn resolveRelocations(macho_file: *MachO, atom_index: Atom.Index) !void {
203 }203 }
204}204}
205205
206pub fn freeRelocations(macho_file: *MachO, atom_index: Atom.Index) void {206pub fn freeRelocations(macho_file: *MachO, atom_index: Index) void {
207 const gpa = macho_file.base.allocator;207 const gpa = macho_file.base.allocator;
208 var removed_relocs = macho_file.relocs.fetchOrderedRemove(atom_index);208 var removed_relocs = macho_file.relocs.fetchOrderedRemove(atom_index);
209 if (removed_relocs) |*relocs| relocs.value.deinit(gpa);209 if (removed_relocs) |*relocs| relocs.value.deinit(gpa);