| ... | ... | @@ -3092,6 +3092,37 @@ fn collectRebaseData(self: *MachO, rebase: *Rebase) !void { |
| 3092 | 3092 | try rebase.finalize(gpa); |
| 3093 | 3093 | } |
| 3094 | 3094 | |
| 3095 | fn collectBindDataFromTableSection(self: *MachO, sect_id: u8, bind: anytype, table: anytype) !void { |
| 3096 | const segment_index = self.sections.items(.segment_index)[sect_id]; |
| 3097 | |
| 3098 | try bind.entries.ensureUnusedCapacity(self.base.allocator, table.entries.items.len); |
| 3099 | |
| 3100 | for (table.entries.items, 0..) |entry, i| { |
| 3101 | if (!table.lookup.contains(entry)) continue; |
| 3102 | |
| 3103 | const bind_sym = self.getSymbol(entry); |
| 3104 | if (!bind_sym.undf()) continue; |
| 3105 | |
| 3106 | const offset = i * @sizeOf(u64); |
| 3107 | |
| 3108 | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ |
| 3109 | offset, |
| 3110 | self.getSymbolName(entry), |
| 3111 | @divTrunc(@bitCast(i16, bind_sym.n_desc), macho.N_SYMBOL_RESOLVER), |
| 3112 | }); |
| 3113 | if (bind_sym.weakRef()) { |
| 3114 | log.debug(" | marking as weak ref ", .{}); |
| 3115 | } |
| 3116 | |
| 3117 | bind.entries.appendAssumeCapacity(.{ |
| 3118 | .target = entry, |
| 3119 | .offset = offset, |
| 3120 | .segment_id = segment_index, |
| 3121 | .addend = 0, |
| 3122 | }); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3095 | 3126 | fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3096 | 3127 | const gpa = self.base.allocator; |
| 3097 | 3128 | const slice = self.sections.slice(); |
| ... | ... | @@ -3134,67 +3165,13 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3134 | 3165 | } |
| 3135 | 3166 | |
| 3136 | 3167 | // Gather GOT pointers |
| 3137 | | try bind.entries.ensureUnusedCapacity(gpa, self.got_table.entries.items.len); |
| 3138 | | const segment_index = self.sections.items(.segment_index)[self.got_section_index.?]; |
| 3139 | | for (self.got_table.entries.items, 0..) |entry, i| { |
| 3140 | | if (!self.got_table.lookup.contains(entry)) continue; |
| 3141 | | const sym = self.getSymbol(entry); |
| 3142 | | if (!sym.undf()) continue; |
| 3143 | | const offset = i * @sizeOf(u64); |
| 3144 | | const bind_sym = self.getSymbol(entry); |
| 3145 | | const bind_sym_name = self.getSymbolName(entry); |
| 3146 | | const dylib_ordinal = @divTrunc( |
| 3147 | | @bitCast(i16, bind_sym.n_desc), |
| 3148 | | macho.N_SYMBOL_RESOLVER, |
| 3149 | | ); |
| 3150 | | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ |
| 3151 | | offset, |
| 3152 | | bind_sym_name, |
| 3153 | | dylib_ordinal, |
| 3154 | | }); |
| 3155 | | bind.entries.appendAssumeCapacity(.{ |
| 3156 | | .target = entry, |
| 3157 | | .offset = offset, |
| 3158 | | .segment_id = segment_index, |
| 3159 | | .addend = 0, |
| 3160 | | }); |
| 3161 | | } |
| 3162 | | |
| 3168 | try self.collectBindDataFromTableSection(self.got_section_index.?, bind, self.got_table); |
| 3163 | 3169 | try bind.finalize(gpa, self); |
| 3164 | 3170 | } |
| 3165 | 3171 | |
| 3166 | 3172 | fn collectLazyBindData(self: *MachO, bind: anytype) !void { |
| 3167 | | const gpa = self.base.allocator; |
| 3168 | | |
| 3169 | | try bind.entries.ensureUnusedCapacity(gpa, self.stub_table.entries.items.len); |
| 3170 | | const segment_index = self.sections.items(.segment_index)[self.la_symbol_ptr_section_index.?]; |
| 3171 | | for (self.stub_table.entries.items, 0..) |entry, i| { |
| 3172 | | if (!self.stub_table.lookup.contains(entry)) continue; |
| 3173 | | const bind_sym = self.getSymbol(entry); |
| 3174 | | assert(bind_sym.undf()); |
| 3175 | | const bind_sym_name = self.getSymbolName(entry); |
| 3176 | | const offset = i * @sizeOf(u64); |
| 3177 | | const dylib_ordinal = @divTrunc( |
| 3178 | | @bitCast(i16, bind_sym.n_desc), |
| 3179 | | macho.N_SYMBOL_RESOLVER, |
| 3180 | | ); |
| 3181 | | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ |
| 3182 | | offset, |
| 3183 | | bind_sym_name, |
| 3184 | | dylib_ordinal, |
| 3185 | | }); |
| 3186 | | if (bind_sym.weakRef()) { |
| 3187 | | log.debug(" | marking as weak ref ", .{}); |
| 3188 | | } |
| 3189 | | bind.entries.appendAssumeCapacity(.{ |
| 3190 | | .target = entry, |
| 3191 | | .offset = offset, |
| 3192 | | .segment_id = segment_index, |
| 3193 | | .addend = 0, |
| 3194 | | }); |
| 3195 | | } |
| 3196 | | |
| 3197 | | try bind.finalize(gpa, self); |
| 3173 | try self.collectBindDataFromTableSection(self.la_symbol_ptr_section_index.?, bind, self.stub_table); |
| 3174 | try bind.finalize(self.base.allocator, self); |
| 3198 | 3175 | } |
| 3199 | 3176 | |
| 3200 | 3177 | fn collectExportData(self: *MachO, trie: *Trie) !void { |