| author | |
| committer | |
| log | 71384a383e0ec6d4c3f6e16571c36a9c44d1645c |
| tree | 97739c656cec520732feb5469d01230aafe5be2d |
| parent | db8020ac0d40caec099ef987c5c43ba637f87c97 |
3 files changed, 18 insertions(+), 14 deletions(-)
src/link/MachO/Object.zig+13-8| ... | @@ -703,20 +703,25 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { | ... | @@ -703,20 +703,25 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { |
| 703 | // Since there is no symbol to refer to this block, we create | 703 | // Since there is no symbol to refer to this block, we create |
| 704 | // a temp one, unless we already did that when working out the relocations | 704 | // a temp one, unless we already did that when working out the relocations |
| 705 | // of other text blocks. | 705 | // of other text blocks. |
| 706 | const block_local_sym_index = @intCast(u32, zld.locals.items.len); | ||
| 707 | const sym_name = try std.fmt.allocPrint(self.allocator, "l_{s}_{s}_{s}", .{ | 706 | const sym_name = try std.fmt.allocPrint(self.allocator, "l_{s}_{s}_{s}", .{ |
| 708 | self.name.?, | 707 | self.name.?, |
| 709 | segmentName(sect), | 708 | segmentName(sect), |
| 710 | sectionName(sect), | 709 | sectionName(sect), |
| 711 | }); | 710 | }); |
| 712 | defer self.allocator.free(sym_name); | 711 | defer self.allocator.free(sym_name); |
| 713 | try zld.locals.append(zld.allocator, .{ | 712 | |
| 714 | .n_strx = try zld.makeString(sym_name), | 713 | const block_local_sym_index = self.sections_as_symbols.get(sect_id) orelse blk: { |
| 715 | .n_type = macho.N_SECT, | 714 | const block_local_sym_index = @intCast(u32, zld.locals.items.len); |
| 716 | .n_sect = zld.sectionId(match), | 715 | try zld.locals.append(zld.allocator, .{ |
| 717 | .n_desc = 0, | 716 | .n_strx = try zld.makeString(sym_name), |
| 718 | .n_value = sect.addr, | 717 | .n_type = macho.N_SECT, |
| 719 | }); | 718 | .n_sect = zld.sectionId(match), |
| 719 | .n_desc = 0, | ||
| 720 | .n_value = sect.addr, | ||
| 721 | }); | ||
| 722 | try self.sections_as_symbols.putNoClobber(self.allocator, sect_id, block_local_sym_index); | ||
| 723 | break :blk block_local_sym_index; | ||
| 724 | }; | ||
| 720 | 725 | ||
| 721 | const block = try self.allocator.create(TextBlock); | 726 | const block = try self.allocator.create(TextBlock); |
| 722 | errdefer self.allocator.destroy(block); | 727 | errdefer self.allocator.destroy(block); |
src/link/MachO/TextBlock.zig+3-3| ... | @@ -548,6 +548,7 @@ fn initRelocFromObject(rel: macho.relocation_info, object: *Object, ctx: RelocCo | ... | @@ -548,6 +548,7 @@ fn initRelocFromObject(rel: macho.relocation_info, object: *Object, ctx: RelocCo |
| 548 | const local_sym_index = object.sections_as_symbols.get(sect_id) orelse blk: { | 548 | const local_sym_index = object.sections_as_symbols.get(sect_id) orelse blk: { |
| 549 | const seg = object.load_commands.items[object.segment_cmd_index.?].Segment; | 549 | const seg = object.load_commands.items[object.segment_cmd_index.?].Segment; |
| 550 | const sect = seg.sections.items[sect_id]; | 550 | const sect = seg.sections.items[sect_id]; |
| 551 | const match = (try ctx.zld.getMatchingSection(sect)) orelse unreachable; | ||
| 551 | const local_sym_index = @intCast(u32, ctx.zld.locals.items.len); | 552 | const local_sym_index = @intCast(u32, ctx.zld.locals.items.len); |
| 552 | const sym_name = try std.fmt.allocPrint(ctx.zld.allocator, "l_{s}_{s}_{s}", .{ | 553 | const sym_name = try std.fmt.allocPrint(ctx.zld.allocator, "l_{s}_{s}_{s}", .{ |
| 553 | object.name.?, | 554 | object.name.?, |
| ... | @@ -559,9 +560,9 @@ fn initRelocFromObject(rel: macho.relocation_info, object: *Object, ctx: RelocCo | ... | @@ -559,9 +560,9 @@ fn initRelocFromObject(rel: macho.relocation_info, object: *Object, ctx: RelocCo |
| 559 | try ctx.zld.locals.append(ctx.zld.allocator, .{ | 560 | try ctx.zld.locals.append(ctx.zld.allocator, .{ |
| 560 | .n_strx = try ctx.zld.makeString(sym_name), | 561 | .n_strx = try ctx.zld.makeString(sym_name), |
| 561 | .n_type = macho.N_SECT, | 562 | .n_type = macho.N_SECT, |
| 562 | .n_sect = 0, | 563 | .n_sect = ctx.zld.sectionId(match), |
| 563 | .n_desc = 0, | 564 | .n_desc = 0, |
| 564 | .n_value = 0, | 565 | .n_value = sect.addr, |
| 565 | }); | 566 | }); |
| 566 | try object.sections_as_symbols.putNoClobber(object.allocator, sect_id, local_sym_index); | 567 | try object.sections_as_symbols.putNoClobber(object.allocator, sect_id, local_sym_index); |
| 567 | break :blk local_sym_index; | 568 | break :blk local_sym_index; |
| ... | @@ -759,7 +760,6 @@ pub fn parseRelocsFromObject( | ... | @@ -759,7 +760,6 @@ pub fn parseRelocsFromObject( |
| 759 | } else if (parsed_rel.payload == .unsigned) { | 760 | } else if (parsed_rel.payload == .unsigned) { |
| 760 | switch (parsed_rel.where) { | 761 | switch (parsed_rel.where) { |
| 761 | .import => { | 762 | .import => { |
| 762 | log.warn("WAT {s}", .{ctx.zld.getString(ctx.zld.imports.items[parsed_rel.where_index].n_strx)}); | ||
| 763 | try self.bindings.append(.{ | 763 | try self.bindings.append(.{ |
| 764 | .local_sym_index = parsed_rel.where_index, | 764 | .local_sym_index = parsed_rel.where_index, |
| 765 | .offset = parsed_rel.offset, | 765 | .offset = parsed_rel.offset, |
src/link/MachO/Zld.zig+2-3| ... | @@ -232,6 +232,8 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg | ... | @@ -232,6 +232,8 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg |
| 232 | try self.parseInputFiles(files, args.syslibroot); | 232 | try self.parseInputFiles(files, args.syslibroot); |
| 233 | try self.parseLibs(args.libs, args.syslibroot); | 233 | try self.parseLibs(args.libs, args.syslibroot); |
| 234 | try self.resolveSymbols(); | 234 | try self.resolveSymbols(); |
| 235 | try self.parseTextBlocks(); | ||
| 236 | // try self.sortSections(); | ||
| 235 | 237 | ||
| 236 | log.warn("locals", .{}); | 238 | log.warn("locals", .{}); |
| 237 | for (self.locals.items) |sym, id| { | 239 | for (self.locals.items) |sym, id| { |
| ... | @@ -276,8 +278,6 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg | ... | @@ -276,8 +278,6 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg |
| 276 | } | 278 | } |
| 277 | } | 279 | } |
| 278 | 280 | ||
| 279 | try self.parseTextBlocks(); | ||
| 280 | |||
| 281 | var it = self.blocks.iterator(); | 281 | var it = self.blocks.iterator(); |
| 282 | while (it.next()) |entry| { | 282 | while (it.next()) |entry| { |
| 283 | const seg = self.load_commands.items[entry.key_ptr.seg].Segment; | 283 | const seg = self.load_commands.items[entry.key_ptr.seg].Segment; |
| ... | @@ -289,7 +289,6 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg | ... | @@ -289,7 +289,6 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg |
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | return error.TODO; | 291 | return error.TODO; |
| 292 | // try self.sortSections(); | ||
| 293 | // try self.addRpaths(args.rpaths); | 292 | // try self.addRpaths(args.rpaths); |
| 294 | // try self.addDataInCodeLC(); | 293 | // try self.addDataInCodeLC(); |
| 295 | // try self.addCodeSignatureLC(); | 294 | // try self.addCodeSignatureLC(); |