aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-08-25 10:51:09 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-08-25 10:51:09 +0200
commitea4bd2b87962794233df1693cdea3da266e27b86 (patch)
tree3dbac51107a0da2307e6014077ec343a716c32fa /src
parentaee6f14bcee7c96fcb65490cad96e06991caece7 (diff)
downloadzig-ea4bd2b87962794233df1693cdea3da266e27b86.tar.gz
zig-ea4bd2b87962794233df1693cdea3da266e27b86.zip
macho: add routine for creating Got atoms
Diffstat (limited to 'src')
-rw-r--r--src/link/MachO.zig52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index b6b70060a9..ba21e2476f 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -1989,6 +1989,42 @@ fn allocateAtomStage1(self: *MachO, atom: *TextBlock, match: MatchingSection) !v
}
}
+fn createGotAtom(self: *MachO, key: GotIndirectionKey) !*TextBlock {
+ const local_sym_index = @intCast(u32, self.locals.items.len);
+ try self.locals.append(self.base.allocator, .{
+ .n_strx = try self.makeString("got_entry"),
+ .n_type = macho.N_SECT,
+ .n_sect = 0,
+ .n_desc = 0,
+ .n_value = 0,
+ });
+ const atom = try self.createEmptyAtom(local_sym_index, @sizeOf(u64), 3);
+ switch (key.where) {
+ .local => {
+ try atom.relocs.append(self.base.allocator, .{
+ .offset = 0,
+ .where = .local,
+ .where_index = key.where_index,
+ .payload = .{
+ .unsigned = .{
+ .subtractor = null,
+ .addend = 0,
+ .is_64bit = true,
+ },
+ },
+ });
+ try atom.rebases.append(self.base.allocator, 0);
+ },
+ .undef => {
+ try atom.bindings.append(self.base.allocator, .{
+ .local_sym_index = key.where_index,
+ .offset = 0,
+ });
+ },
+ }
+ return atom;
+}
+
fn createDyldPrivateAtom(self: *MachO) !*TextBlock {
const local_sym_index = @intCast(u32, self.locals.items.len);
try self.locals.append(self.base.allocator, .{
@@ -2777,13 +2813,19 @@ fn resolveDyldStubBinder(self: *MachO) !void {
try self.got_entries.append(self.base.allocator, got_entry);
try self.got_entries_map.putNoClobber(self.base.allocator, got_entry, got_index);
- self.binding_info_dirty = true;
- self.got_entries_count_dirty = true;
-
+ const atom = try self.createGotAtom(got_entry);
+ const match = MatchingSection{
+ .seg = self.data_const_segment_cmd_index.?,
+ .sect = self.got_section_index.?,
+ };
+ // TODO remove once we can incrementally update in stage1 too.
if (!(build_options.is_stage1 and self.base.options.use_stage1)) {
- // TODO remove once we can incrementally update in stage1 too.
- try self.writeGotEntry(got_index);
+ _ = try self.allocateAtom(atom, match);
+ try self.writeAtom(atom, match);
+ } else {
+ try self.allocateAtomStage1(atom, match);
}
+ self.binding_info_dirty = true;
}
fn parseTextBlocks(self: *MachO) !void {