authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-25 10:51:09+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-25 10:51:09+02:00
logea4bd2b87962794233df1693cdea3da266e27b86
tree3dbac51107a0da2307e6014077ec343a716c32fa
parentaee6f14bcee7c96fcb65490cad96e06991caece7

macho: add routine for creating Got atoms


1 files changed, 47 insertions(+), 5 deletions(-)

src/link/MachO.zig+47-5
...@@ -1989,6 +1989,42 @@ fn allocateAtomStage1(self: *MachO, atom: *TextBlock, match: MatchingSection) !v...@@ -1989,6 +1989,42 @@ fn allocateAtomStage1(self: *MachO, atom: *TextBlock, match: MatchingSection) !v
1989 }1989 }
1990}1990}
19911991
1992fn createGotAtom(self: *MachO, key: GotIndirectionKey) !*TextBlock {
1993 const local_sym_index = @intCast(u32, self.locals.items.len);
1994 try self.locals.append(self.base.allocator, .{
1995 .n_strx = try self.makeString("got_entry"),
1996 .n_type = macho.N_SECT,
1997 .n_sect = 0,
1998 .n_desc = 0,
1999 .n_value = 0,
2000 });
2001 const atom = try self.createEmptyAtom(local_sym_index, @sizeOf(u64), 3);
2002 switch (key.where) {
2003 .local => {
2004 try atom.relocs.append(self.base.allocator, .{
2005 .offset = 0,
2006 .where = .local,
2007 .where_index = key.where_index,
2008 .payload = .{
2009 .unsigned = .{
2010 .subtractor = null,
2011 .addend = 0,
2012 .is_64bit = true,
2013 },
2014 },
2015 });
2016 try atom.rebases.append(self.base.allocator, 0);
2017 },
2018 .undef => {
2019 try atom.bindings.append(self.base.allocator, .{
2020 .local_sym_index = key.where_index,
2021 .offset = 0,
2022 });
2023 },
2024 }
2025 return atom;
2026}
2027
1992fn createDyldPrivateAtom(self: *MachO) !*TextBlock {2028fn createDyldPrivateAtom(self: *MachO) !*TextBlock {
1993 const local_sym_index = @intCast(u32, self.locals.items.len);2029 const local_sym_index = @intCast(u32, self.locals.items.len);
1994 try self.locals.append(self.base.allocator, .{2030 try self.locals.append(self.base.allocator, .{
...@@ -2777,13 +2813,19 @@ fn resolveDyldStubBinder(self: *MachO) !void {...@@ -2777,13 +2813,19 @@ fn resolveDyldStubBinder(self: *MachO) !void {
2777 try self.got_entries.append(self.base.allocator, got_entry);2813 try self.got_entries.append(self.base.allocator, got_entry);
2778 try self.got_entries_map.putNoClobber(self.base.allocator, got_entry, got_index);2814 try self.got_entries_map.putNoClobber(self.base.allocator, got_entry, got_index);
27792815
2780 self.binding_info_dirty = true;2816 const atom = try self.createGotAtom(got_entry);
2781 self.got_entries_count_dirty = true;2817 const match = MatchingSection{
27822818 .seg = self.data_const_segment_cmd_index.?,
2819 .sect = self.got_section_index.?,
2820 };
2821 // TODO remove once we can incrementally update in stage1 too.
2783 if (!(build_options.is_stage1 and self.base.options.use_stage1)) {2822 if (!(build_options.is_stage1 and self.base.options.use_stage1)) {
2784 // TODO remove once we can incrementally update in stage1 too.2823 _ = try self.allocateAtom(atom, match);
2785 try self.writeGotEntry(got_index);2824 try self.writeAtom(atom, match);
2825 } else {
2826 try self.allocateAtomStage1(atom, match);
2786 }2827 }
2828 self.binding_info_dirty = true;
2787}2829}
27882830
2789fn parseTextBlocks(self: *MachO) !void {2831fn parseTextBlocks(self: *MachO) !void {