| ... | @@ -409,7 +409,7 @@ fn mapAndUpdateSections( | ... | @@ -409,7 +409,7 @@ fn mapAndUpdateSections( |
| 409 | const offset = mem.alignForwardGeneric(u64, target_sect.size, alignment); | 409 | const offset = mem.alignForwardGeneric(u64, target_sect.size, alignment); |
| 410 | const size = mem.alignForwardGeneric(u64, source_sect.inner.size, alignment); | 410 | const size = mem.alignForwardGeneric(u64, source_sect.inner.size, alignment); |
| 411 | | 411 | |
| 412 | log.debug("{s}: '{s},{s}' mapped to '{s},{s}' from 0x{x} to 0x{x}", .{ | 412 | log.warn("{s}: '{s},{s}' mapped to '{s},{s}' from 0x{x} to 0x{x}", .{ |
| 413 | object.name.?, | 413 | object.name.?, |
| 414 | parseName(&source_sect.inner.segname), | 414 | parseName(&source_sect.inner.segname), |
| 415 | parseName(&source_sect.inner.sectname), | 415 | parseName(&source_sect.inner.sectname), |
| ... | @@ -435,19 +435,17 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -435,19 +435,17 @@ fn updateMetadata(self: *Zld) !void { |
| 435 | const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment; | 435 | const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment; |
| 436 | | 436 | |
| 437 | // Create missing metadata | 437 | // Create missing metadata |
| 438 | for (object_seg.sections.items) |source_sect, sect_id| { | 438 | for (object.sections.items) |sect, sect_id| { |
| 439 | if (sect_id == object.text_section_index.?) continue; | 439 | const segname = sect.segname(); |
| 440 | const segname = parseName(&source_sect.segname); | 440 | const sectname = sect.sectname(); |
| 441 | const sectname = parseName(&source_sect.sectname); | | |
| 442 | const flags = source_sect.flags; | | |
| 443 | | 441 | |
| 444 | switch (flags) { | 442 | switch (sect.sectionType()) { |
| 445 | macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS => { | 443 | macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS, macho.S_LITERAL_POINTERS => { |
| 446 | if (self.text_section_index != null) continue; | 444 | if (self.text_const_section_index != null) continue; |
| 447 | | 445 | |
| 448 | self.text_section_index = @intCast(u16, text_seg.sections.items.len); | 446 | self.text_const_section_index = @intCast(u16, text_seg.sections.items.len); |
| 449 | try text_seg.addSection(self.allocator, .{ | 447 | try text_seg.addSection(self.allocator, .{ |
| 450 | .sectname = makeStaticString("__text"), | 448 | .sectname = makeStaticString("__const"), |
| 451 | .segname = makeStaticString("__TEXT"), | 449 | .segname = makeStaticString("__TEXT"), |
| 452 | .addr = 0, | 450 | .addr = 0, |
| 453 | .size = 0, | 451 | .size = 0, |
| ... | @@ -455,70 +453,12 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -455,70 +453,12 @@ fn updateMetadata(self: *Zld) !void { |
| 455 | .@"align" = 0, | 453 | .@"align" = 0, |
| 456 | .reloff = 0, | 454 | .reloff = 0, |
| 457 | .nreloc = 0, | 455 | .nreloc = 0, |
| 458 | .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, | 456 | .flags = macho.S_REGULAR, |
| 459 | .reserved1 = 0, | 457 | .reserved1 = 0, |
| 460 | .reserved2 = 0, | 458 | .reserved2 = 0, |
| 461 | .reserved3 = 0, | 459 | .reserved3 = 0, |
| 462 | }); | 460 | }); |
| 463 | }, | 461 | continue; |
| 464 | macho.S_REGULAR, macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS => { | | |
| 465 | if (mem.eql(u8, segname, "__TEXT")) { | | |
| 466 | if (mem.eql(u8, sectname, "__ustring")) { | | |
| 467 | if (self.ustring_section_index != null) continue; | | |
| 468 | | | |
| 469 | self.ustring_section_index = @intCast(u16, text_seg.sections.items.len); | | |
| 470 | try text_seg.addSection(self.allocator, .{ | | |
| 471 | .sectname = makeStaticString("__ustring"), | | |
| 472 | .segname = makeStaticString("__TEXT"), | | |
| 473 | .addr = 0, | | |
| 474 | .size = 0, | | |
| 475 | .offset = 0, | | |
| 476 | .@"align" = 0, | | |
| 477 | .reloff = 0, | | |
| 478 | .nreloc = 0, | | |
| 479 | .flags = macho.S_REGULAR, | | |
| 480 | .reserved1 = 0, | | |
| 481 | .reserved2 = 0, | | |
| 482 | .reserved3 = 0, | | |
| 483 | }); | | |
| 484 | } else { | | |
| 485 | if (self.text_const_section_index != null) continue; | | |
| 486 | | | |
| 487 | self.text_const_section_index = @intCast(u16, text_seg.sections.items.len); | | |
| 488 | try text_seg.addSection(self.allocator, .{ | | |
| 489 | .sectname = makeStaticString("__const"), | | |
| 490 | .segname = makeStaticString("__TEXT"), | | |
| 491 | .addr = 0, | | |
| 492 | .size = 0, | | |
| 493 | .offset = 0, | | |
| 494 | .@"align" = 0, | | |
| 495 | .reloff = 0, | | |
| 496 | .nreloc = 0, | | |
| 497 | .flags = macho.S_REGULAR, | | |
| 498 | .reserved1 = 0, | | |
| 499 | .reserved2 = 0, | | |
| 500 | .reserved3 = 0, | | |
| 501 | }); | | |
| 502 | } | | |
| 503 | } else if (mem.eql(u8, segname, "__DATA") or mem.eql(u8, segname, "__DATA_CONST")) { | | |
| 504 | if (self.data_const_section_index != null) continue; | | |
| 505 | | | |
| 506 | self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len); | | |
| 507 | try data_const_seg.addSection(self.allocator, .{ | | |
| 508 | .sectname = makeStaticString("__const"), | | |
| 509 | .segname = makeStaticString("__DATA_CONST"), | | |
| 510 | .addr = 0, | | |
| 511 | .size = 0, | | |
| 512 | .offset = 0, | | |
| 513 | .@"align" = 0, | | |
| 514 | .reloff = 0, | | |
| 515 | .nreloc = 0, | | |
| 516 | .flags = macho.S_REGULAR, | | |
| 517 | .reserved1 = 0, | | |
| 518 | .reserved2 = 0, | | |
| 519 | .reserved3 = 0, | | |
| 520 | }); | | |
| 521 | } | | |
| 522 | }, | 462 | }, |
| 523 | macho.S_CSTRING_LITERALS => { | 463 | macho.S_CSTRING_LITERALS => { |
| 524 | if (self.cstring_section_index != null) continue; | 464 | if (self.cstring_section_index != null) continue; |
| ... | @@ -538,6 +478,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -538,6 +478,7 @@ fn updateMetadata(self: *Zld) !void { |
| 538 | .reserved2 = 0, | 478 | .reserved2 = 0, |
| 539 | .reserved3 = 0, | 479 | .reserved3 = 0, |
| 540 | }); | 480 | }); |
| | 481 | continue; |
| 541 | }, | 482 | }, |
| 542 | macho.S_MOD_INIT_FUNC_POINTERS => { | 483 | macho.S_MOD_INIT_FUNC_POINTERS => { |
| 543 | if (self.mod_init_func_section_index != null) continue; | 484 | if (self.mod_init_func_section_index != null) continue; |
| ... | @@ -557,6 +498,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -557,6 +498,7 @@ fn updateMetadata(self: *Zld) !void { |
| 557 | .reserved2 = 0, | 498 | .reserved2 = 0, |
| 558 | .reserved3 = 0, | 499 | .reserved3 = 0, |
| 559 | }); | 500 | }); |
| | 501 | continue; |
| 560 | }, | 502 | }, |
| 561 | macho.S_MOD_TERM_FUNC_POINTERS => { | 503 | macho.S_MOD_TERM_FUNC_POINTERS => { |
| 562 | if (self.mod_term_func_section_index != null) continue; | 504 | if (self.mod_term_func_section_index != null) continue; |
| ... | @@ -576,6 +518,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -576,6 +518,7 @@ fn updateMetadata(self: *Zld) !void { |
| 576 | .reserved2 = 0, | 518 | .reserved2 = 0, |
| 577 | .reserved3 = 0, | 519 | .reserved3 = 0, |
| 578 | }); | 520 | }); |
| | 521 | continue; |
| 579 | }, | 522 | }, |
| 580 | macho.S_ZEROFILL => { | 523 | macho.S_ZEROFILL => { |
| 581 | if (mem.eql(u8, sectname, "__common")) { | 524 | if (mem.eql(u8, sectname, "__common")) { |
| ... | @@ -615,6 +558,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -615,6 +558,7 @@ fn updateMetadata(self: *Zld) !void { |
| 615 | .reserved3 = 0, | 558 | .reserved3 = 0, |
| 616 | }); | 559 | }); |
| 617 | } | 560 | } |
| | 561 | continue; |
| 618 | }, | 562 | }, |
| 619 | macho.S_THREAD_LOCAL_VARIABLES => { | 563 | macho.S_THREAD_LOCAL_VARIABLES => { |
| 620 | if (self.tlv_section_index != null) continue; | 564 | if (self.tlv_section_index != null) continue; |
| ... | @@ -634,6 +578,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -634,6 +578,7 @@ fn updateMetadata(self: *Zld) !void { |
| 634 | .reserved2 = 0, | 578 | .reserved2 = 0, |
| 635 | .reserved3 = 0, | 579 | .reserved3 = 0, |
| 636 | }); | 580 | }); |
| | 581 | continue; |
| 637 | }, | 582 | }, |
| 638 | macho.S_THREAD_LOCAL_REGULAR => { | 583 | macho.S_THREAD_LOCAL_REGULAR => { |
| 639 | if (self.tlv_data_section_index != null) continue; | 584 | if (self.tlv_data_section_index != null) continue; |
| ... | @@ -653,6 +598,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -653,6 +598,7 @@ fn updateMetadata(self: *Zld) !void { |
| 653 | .reserved2 = 0, | 598 | .reserved2 = 0, |
| 654 | .reserved3 = 0, | 599 | .reserved3 = 0, |
| 655 | }); | 600 | }); |
| | 601 | continue; |
| 656 | }, | 602 | }, |
| 657 | macho.S_THREAD_LOCAL_ZEROFILL => { | 603 | macho.S_THREAD_LOCAL_ZEROFILL => { |
| 658 | if (self.tlv_bss_section_index != null) continue; | 604 | if (self.tlv_bss_section_index != null) continue; |
| ... | @@ -672,58 +618,185 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -672,58 +618,185 @@ fn updateMetadata(self: *Zld) !void { |
| 672 | .reserved2 = 0, | 618 | .reserved2 = 0, |
| 673 | .reserved3 = 0, | 619 | .reserved3 = 0, |
| 674 | }); | 620 | }); |
| 675 | }, | | |
| 676 | macho.S_COALESCED | | | |
| 677 | macho.S_ATTR_NO_TOC | | | |
| 678 | macho.S_ATTR_STRIP_STATIC_SYMS | | | |
| 679 | macho.S_ATTR_LIVE_SUPPORT => { | | |
| 680 | log.debug("TODO __eh_frame section: type 0x{x}, name '{s},{s}'", .{ | | |
| 681 | flags, segname, sectname, | | |
| 682 | }); | | |
| 683 | continue; | 621 | continue; |
| 684 | }, | 622 | }, |
| 685 | macho.S_REGULAR | macho.S_ATTR_DEBUG => { | 623 | macho.S_COALESCED => { |
| 686 | if (mem.eql(u8, "__LD", segname) and mem.eql(u8, "__compact_unwind", sectname)) { | 624 | if (mem.eql(u8, "__TEXT", segname) and mem.eql(u8, "__eh_frame", sectname)) { |
| 687 | log.debug("TODO compact unwind section: type 0x{x}, name '{s},{s}'", .{ | 625 | log.debug("TODO __eh_frame section: type 0x{x}, name '{s},{s}'", .{ |
| 688 | flags, segname, sectname, | 626 | sect.flags(), segname, sectname, |
| 689 | }); | 627 | }); |
| | 628 | continue; |
| 690 | } | 629 | } |
| 691 | continue; | | |
| 692 | }, | 630 | }, |
| 693 | else => { | 631 | macho.S_REGULAR => { |
| | 632 | if (sect.isCode()) { |
| | 633 | if (self.text_section_index != null) continue; |
| | 634 | |
| | 635 | self.text_section_index = @intCast(u16, text_seg.sections.items.len); |
| | 636 | try text_seg.addSection(self.allocator, .{ |
| | 637 | .sectname = makeStaticString("__text"), |
| | 638 | .segname = makeStaticString("__TEXT"), |
| | 639 | .addr = 0, |
| | 640 | .size = 0, |
| | 641 | .offset = 0, |
| | 642 | .@"align" = 0, |
| | 643 | .reloff = 0, |
| | 644 | .nreloc = 0, |
| | 645 | .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, |
| | 646 | .reserved1 = 0, |
| | 647 | .reserved2 = 0, |
| | 648 | .reserved3 = 0, |
| | 649 | }); |
| | 650 | continue; |
| | 651 | } |
| | 652 | if (sect.isDebug()) { |
| | 653 | if (mem.eql(u8, "__LD", segname) and mem.eql(u8, "__compact_unwind", sectname)) { |
| | 654 | log.debug("TODO compact unwind section: type 0x{x}, name '{s},{s}'", .{ |
| | 655 | sect.flags(), segname, sectname, |
| | 656 | }); |
| | 657 | } |
| | 658 | continue; |
| | 659 | } |
| | 660 | |
| | 661 | if (mem.eql(u8, segname, "__TEXT")) { |
| | 662 | if (mem.eql(u8, sectname, "__ustring")) { |
| | 663 | if (self.ustring_section_index != null) continue; |
| | 664 | |
| | 665 | self.ustring_section_index = @intCast(u16, text_seg.sections.items.len); |
| | 666 | try text_seg.addSection(self.allocator, .{ |
| | 667 | .sectname = makeStaticString("__ustring"), |
| | 668 | .segname = makeStaticString("__TEXT"), |
| | 669 | .addr = 0, |
| | 670 | .size = 0, |
| | 671 | .offset = 0, |
| | 672 | .@"align" = 0, |
| | 673 | .reloff = 0, |
| | 674 | .nreloc = 0, |
| | 675 | .flags = macho.S_REGULAR, |
| | 676 | .reserved1 = 0, |
| | 677 | .reserved2 = 0, |
| | 678 | .reserved3 = 0, |
| | 679 | }); |
| | 680 | } else { |
| | 681 | if (self.text_const_section_index != null) continue; |
| | 682 | |
| | 683 | self.text_const_section_index = @intCast(u16, text_seg.sections.items.len); |
| | 684 | try text_seg.addSection(self.allocator, .{ |
| | 685 | .sectname = makeStaticString("__const"), |
| | 686 | .segname = makeStaticString("__TEXT"), |
| | 687 | .addr = 0, |
| | 688 | .size = 0, |
| | 689 | .offset = 0, |
| | 690 | .@"align" = 0, |
| | 691 | .reloff = 0, |
| | 692 | .nreloc = 0, |
| | 693 | .flags = macho.S_REGULAR, |
| | 694 | .reserved1 = 0, |
| | 695 | .reserved2 = 0, |
| | 696 | .reserved3 = 0, |
| | 697 | }); |
| | 698 | } |
| | 699 | continue; |
| | 700 | } |
| | 701 | |
| | 702 | if (mem.eql(u8, segname, "__DATA_CONST")) { |
| | 703 | if (self.data_const_section_index != null) continue; |
| | 704 | |
| | 705 | self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| | 706 | try data_const_seg.addSection(self.allocator, .{ |
| | 707 | .sectname = makeStaticString("__const"), |
| | 708 | .segname = makeStaticString("__DATA_CONST"), |
| | 709 | .addr = 0, |
| | 710 | .size = 0, |
| | 711 | .offset = 0, |
| | 712 | .@"align" = 0, |
| | 713 | .reloff = 0, |
| | 714 | .nreloc = 0, |
| | 715 | .flags = macho.S_REGULAR, |
| | 716 | .reserved1 = 0, |
| | 717 | .reserved2 = 0, |
| | 718 | .reserved3 = 0, |
| | 719 | }); |
| | 720 | continue; |
| | 721 | } |
| | 722 | |
| | 723 | if (mem.eql(u8, segname, "__DATA")) { |
| | 724 | if (mem.eql(u8, sectname, "__const")) { |
| | 725 | if (self.data_const_section_index != null) continue; |
| | 726 | |
| | 727 | self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| | 728 | try data_const_seg.addSection(self.allocator, .{ |
| | 729 | .sectname = makeStaticString("__const"), |
| | 730 | .segname = makeStaticString("__DATA_CONST"), |
| | 731 | .addr = 0, |
| | 732 | .size = 0, |
| | 733 | .offset = 0, |
| | 734 | .@"align" = 0, |
| | 735 | .reloff = 0, |
| | 736 | .nreloc = 0, |
| | 737 | .flags = macho.S_REGULAR, |
| | 738 | .reserved1 = 0, |
| | 739 | .reserved2 = 0, |
| | 740 | .reserved3 = 0, |
| | 741 | }); |
| | 742 | } else { |
| | 743 | if (self.data_section_index != null) continue; |
| | 744 | |
| | 745 | self.data_section_index = @intCast(u16, data_seg.sections.items.len); |
| | 746 | try data_seg.addSection(self.allocator, .{ |
| | 747 | .sectname = makeStaticString("__data"), |
| | 748 | .segname = makeStaticString("__DATA"), |
| | 749 | .addr = 0, |
| | 750 | .size = 0, |
| | 751 | .offset = 0, |
| | 752 | .@"align" = 0, |
| | 753 | .reloff = 0, |
| | 754 | .nreloc = 0, |
| | 755 | .flags = macho.S_REGULAR, |
| | 756 | .reserved1 = 0, |
| | 757 | .reserved2 = 0, |
| | 758 | .reserved3 = 0, |
| | 759 | }); |
| | 760 | } |
| | 761 | |
| | 762 | continue; |
| | 763 | } |
| | 764 | |
| 694 | if (mem.eql(u8, "__LLVM", segname) and mem.eql(u8, "__asm", sectname)) { | 765 | if (mem.eql(u8, "__LLVM", segname) and mem.eql(u8, "__asm", sectname)) { |
| 695 | log.debug("TODO LLVM bitcode section: type 0x{x}, name '{s},{s}'", .{ | 766 | log.debug("TODO LLVM asm section: type 0x{x}, name '{s},{s}'", .{ |
| 696 | flags, segname, sectname, | 767 | sect.flags(), segname, sectname, |
| 697 | }); | 768 | }); |
| 698 | continue; | 769 | continue; |
| 699 | } | 770 | } |
| 700 | log.err("unhandled section type 0x{x} for '{s},{s}'", .{ flags, segname, sectname }); | | |
| 701 | return error.UnhandledSection; | | |
| 702 | }, | 771 | }, |
| | 772 | else => {}, |
| 703 | } | 773 | } |
| | 774 | |
| | 775 | log.err("{s}: unhandled section type 0x{x} for '{s},{s}'", .{ |
| | 776 | object.name.?, |
| | 777 | sect.flags(), |
| | 778 | segname, |
| | 779 | sectname, |
| | 780 | }); |
| | 781 | return error.UnhandledSection; |
| 704 | } | 782 | } |
| 705 | | 783 | |
| 706 | // Find ideal section alignment. | 784 | // Find ideal section alignment. |
| 707 | for (object_seg.sections.items) |source_sect| { | 785 | for (object.sections.items) |sect| { |
| 708 | if (self.getMatchingSection(source_sect)) |res| { | 786 | if (self.getMatchingSection(sect)) |res| { |
| 709 | const target_seg = &self.load_commands.items[res.seg].Segment; | 787 | const target_seg = &self.load_commands.items[res.seg].Segment; |
| 710 | const target_sect = &target_seg.sections.items[res.sect]; | 788 | const target_sect = &target_seg.sections.items[res.sect]; |
| 711 | target_sect.@"align" = math.max(target_sect.@"align", source_sect.@"align"); | 789 | target_sect.@"align" = math.max(target_sect.@"align", sect.inner.@"align"); |
| 712 | } | 790 | } |
| 713 | } | 791 | } |
| 714 | | 792 | |
| 715 | // Update section mappings | 793 | // Update section mappings |
| 716 | for (object_seg.sections.items) |source_sect, sect_id| { | 794 | for (object.sections.items) |sect, sect_id| { |
| 717 | const source_sect_id = @intCast(u16, sect_id); | 795 | if (self.getMatchingSection(sect)) |res| { |
| 718 | if (self.getMatchingSection(source_sect)) |res| { | 796 | try self.mapAndUpdateSections(object, @intCast(u16, sect_id), res.seg, res.sect); |
| 719 | try self.mapAndUpdateSections(object, source_sect_id, res.seg, res.sect); | | |
| 720 | continue; | 797 | continue; |
| 721 | } | 798 | } |
| 722 | | 799 | log.warn("section '{s},{s}' will be unmapped", .{ sect.segname(), sect.sectname() }); |
| 723 | log.debug("section '{s},{s}' will be unmapped", .{ | | |
| 724 | parseName(&source_sect.segname), | | |
| 725 | parseName(&source_sect.sectname), | | |
| 726 | }); | | |
| 727 | } | 800 | } |
| 728 | } | 801 | } |
| 729 | | 802 | |
| ... | @@ -819,13 +892,13 @@ const MatchingSection = struct { | ... | @@ -819,13 +892,13 @@ const MatchingSection = struct { |
| 819 | sect: u16, | 892 | sect: u16, |
| 820 | }; | 893 | }; |
| 821 | | 894 | |
| 822 | fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { | 895 | fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection { |
| 823 | const segname = parseName(&section.segname); | 896 | const segname = sect.segname(); |
| 824 | const sectname = parseName(&section.sectname); | 897 | const sectname = sect.sectname(); |
| 825 | | 898 | |
| 826 | const res: ?MatchingSection = blk: { | 899 | const res: ?MatchingSection = blk: { |
| 827 | switch (section.flags) { | 900 | switch (sect.sectionType()) { |
| 828 | macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS => { | 901 | macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS, macho.S_LITERAL_POINTERS => { |
| 829 | break :blk .{ | 902 | break :blk .{ |
| 830 | .seg = self.text_segment_cmd_index.?, | 903 | .seg = self.text_segment_cmd_index.?, |
| 831 | .sect = self.text_const_section_index.?, | 904 | .sect = self.text_const_section_index.?, |
| ... | @@ -855,11 +928,12 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { | ... | @@ -855,11 +928,12 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { |
| 855 | .seg = self.data_segment_cmd_index.?, | 928 | .seg = self.data_segment_cmd_index.?, |
| 856 | .sect = self.common_section_index.?, | 929 | .sect = self.common_section_index.?, |
| 857 | }; | 930 | }; |
| | 931 | } else { |
| | 932 | break :blk .{ |
| | 933 | .seg = self.data_segment_cmd_index.?, |
| | 934 | .sect = self.bss_section_index.?, |
| | 935 | }; |
| 858 | } | 936 | } |
| 859 | break :blk .{ | | |
| 860 | .seg = self.data_segment_cmd_index.?, | | |
| 861 | .sect = self.bss_section_index.?, | | |
| 862 | }; | | |
| 863 | }, | 937 | }, |
| 864 | macho.S_THREAD_LOCAL_VARIABLES => { | 938 | macho.S_THREAD_LOCAL_VARIABLES => { |
| 865 | break :blk .{ | 939 | break :blk .{ |
| ... | @@ -879,31 +953,43 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { | ... | @@ -879,31 +953,43 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { |
| 879 | .sect = self.tlv_bss_section_index.?, | 953 | .sect = self.tlv_bss_section_index.?, |
| 880 | }; | 954 | }; |
| 881 | }, | 955 | }, |
| 882 | macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS => { | 956 | macho.S_COALESCED => { |
| 883 | break :blk .{ | 957 | // TODO coalesced sections |
| 884 | .seg = self.text_segment_cmd_index.?, | 958 | break :blk null; |
| 885 | .sect = self.text_section_index.?, | | |
| 886 | }; | | |
| 887 | }, | 959 | }, |
| 888 | macho.S_REGULAR => { | 960 | macho.S_REGULAR => { |
| | 961 | if (sect.isCode()) { |
| | 962 | break :blk .{ |
| | 963 | .seg = self.text_segment_cmd_index.?, |
| | 964 | .sect = self.text_section_index.?, |
| | 965 | }; |
| | 966 | } |
| | 967 | if (sect.isDebug()) { |
| | 968 | // TODO debug attributes |
| | 969 | break :blk null; |
| | 970 | } |
| | 971 | |
| 889 | if (mem.eql(u8, segname, "__TEXT")) { | 972 | if (mem.eql(u8, segname, "__TEXT")) { |
| 890 | if (mem.eql(u8, sectname, "__ustring")) { | 973 | if (mem.eql(u8, sectname, "__ustring")) { |
| 891 | break :blk .{ | 974 | break :blk .{ |
| 892 | .seg = self.text_segment_cmd_index.?, | 975 | .seg = self.text_segment_cmd_index.?, |
| 893 | .sect = self.ustring_section_index.?, | 976 | .sect = self.ustring_section_index.?, |
| 894 | }; | 977 | }; |
| | 978 | } else { |
| | 979 | break :blk .{ |
| | 980 | .seg = self.text_segment_cmd_index.?, |
| | 981 | .sect = self.text_const_section_index.?, |
| | 982 | }; |
| 895 | } | 983 | } |
| 896 | break :blk .{ | | |
| 897 | .seg = self.text_segment_cmd_index.?, | | |
| 898 | .sect = self.text_const_section_index.?, | | |
| 899 | }; | | |
| 900 | } | 984 | } |
| | 985 | |
| 901 | if (mem.eql(u8, segname, "__DATA_CONST")) { | 986 | if (mem.eql(u8, segname, "__DATA_CONST")) { |
| 902 | break :blk .{ | 987 | break :blk .{ |
| 903 | .seg = self.data_const_segment_cmd_index.?, | 988 | .seg = self.data_const_segment_cmd_index.?, |
| 904 | .sect = self.data_const_section_index.?, | 989 | .sect = self.data_const_section_index.?, |
| 905 | }; | 990 | }; |
| 906 | } | 991 | } |
| | 992 | |
| 907 | if (mem.eql(u8, segname, "__DATA")) { | 993 | if (mem.eql(u8, segname, "__DATA")) { |
| 908 | if (mem.eql(u8, sectname, "__const")) { | 994 | if (mem.eql(u8, sectname, "__const")) { |
| 909 | break :blk .{ | 995 | break :blk .{ |
| ... | @@ -916,11 +1002,10 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { | ... | @@ -916,11 +1002,10 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { |
| 916 | .sect = self.data_section_index.?, | 1002 | .sect = self.data_section_index.?, |
| 917 | }; | 1003 | }; |
| 918 | } | 1004 | } |
| | 1005 | |
| 919 | break :blk null; | 1006 | break :blk null; |
| 920 | }, | 1007 | }, |
| 921 | else => { | 1008 | else => break :blk null, |
| 922 | break :blk null; | | |
| 923 | }, | | |
| 924 | } | 1009 | } |
| 925 | }; | 1010 | }; |
| 926 | | 1011 | |