| ... | @@ -343,7 +343,7 @@ pub fn parseSections(self: *Object) !void { | ... | @@ -343,7 +343,7 @@ pub fn parseSections(self: *Object) !void { |
| 343 | } | 343 | } |
| 344 | } | 344 | } |
| 345 | | 345 | |
| 346 | pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { | 346 | pub fn parseTextBlocks(self: *Object, zld: *Zld) !*TextBlock { |
| 347 | const seg = self.load_commands.items[self.segment_cmd_index.?].Segment; | 347 | const seg = self.load_commands.items[self.segment_cmd_index.?].Segment; |
| 348 | | 348 | |
| 349 | log.warn("analysing {s}", .{self.name.?}); | 349 | log.warn("analysing {s}", .{self.name.?}); |
| ... | @@ -503,6 +503,54 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { | ... | @@ -503,6 +503,54 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { |
| 503 | } | 503 | } |
| 504 | } | 504 | } |
| 505 | | 505 | |
| | 506 | const SectionAsTextBlocksArgs = struct { |
| | 507 | sect: macho.section_64, |
| | 508 | code: []u8, |
| | 509 | subsections_via_symbols: bool = false, |
| | 510 | relocs: ?[]macho.relocation_info = null, |
| | 511 | segment_id: u16 = 0, |
| | 512 | section_id: u16 = 0, |
| | 513 | }; |
| | 514 | |
| | 515 | fn sectionAsTextBlocks(self: *Object, args: SectionAsTextBlocksArgs) !*TextBlock { |
| | 516 | const sect = args.sect; |
| | 517 | |
| | 518 | log.warn("putting section '{s},{s}' as a TextBlock", .{ segmentName(sect), sectionName(sect) }); |
| | 519 | |
| | 520 | // Section alignment will be the assumed alignment per symbol. |
| | 521 | const alignment = sect.@"align"; |
| | 522 | |
| | 523 | const first_block: *TextBlock = blk: { |
| | 524 | if (args.subsections_via_symbols) { |
| | 525 | return error.TODO; |
| | 526 | } else { |
| | 527 | const block = try self.allocator.create(TextBlock); |
| | 528 | errdefer self.allocator.destroy(block); |
| | 529 | |
| | 530 | block.* = .{ |
| | 531 | .ref = .{ |
| | 532 | .section = undefined, // Will be populated when we allocated final sections. |
| | 533 | }, |
| | 534 | .code = args.code, |
| | 535 | .relocs = null, |
| | 536 | .size = sect.size, |
| | 537 | .alignment = alignment, |
| | 538 | .segment_id = args.segment_id, |
| | 539 | .section_id = args.section_id, |
| | 540 | }; |
| | 541 | |
| | 542 | // TODO parse relocs |
| | 543 | if (args.relocs) |relocs| { |
| | 544 | block.relocs = try reloc.parse(self.allocator, self.arch.?, args.code, relocs, symbols); |
| | 545 | } |
| | 546 | |
| | 547 | break :blk block; |
| | 548 | } |
| | 549 | }; |
| | 550 | |
| | 551 | return first_block; |
| | 552 | } |
| | 553 | |
| 506 | pub fn parseInitializers(self: *Object) !void { | 554 | pub fn parseInitializers(self: *Object) !void { |
| 507 | const index = self.mod_init_func_section_index orelse return; | 555 | const index = self.mod_init_func_section_index orelse return; |
| 508 | const section = self.sections.items[index]; | 556 | const section = self.sections.items[index]; |