| ... | @@ -65,9 +65,9 @@ stub_helper_section_index: ?u16 = null, | ... | @@ -65,9 +65,9 @@ stub_helper_section_index: ?u16 = null, |
| 65 | text_const_section_index: ?u16 = null, | 65 | text_const_section_index: ?u16 = null, |
| 66 | cstring_section_index: ?u16 = null, | 66 | cstring_section_index: ?u16 = null, |
| 67 | ustring_section_index: ?u16 = null, | 67 | ustring_section_index: ?u16 = null, |
| 68 | gcc_except_tab: ?u16 = null, | 68 | gcc_except_tab_section_index: ?u16 = null, |
| 69 | unwind_info: ?u16 = null, | 69 | unwind_info_section_index: ?u16 = null, |
| 70 | eh_frame: ?u16 = null, | 70 | eh_frame_section_index: ?u16 = null, |
| 71 | | 71 | |
| 72 | // __DATA_CONST segment sections | 72 | // __DATA_CONST segment sections |
| 73 | got_section_index: ?u16 = null, | 73 | got_section_index: ?u16 = null, |
| ... | @@ -412,7 +412,7 @@ fn mapAndUpdateSections( | ... | @@ -412,7 +412,7 @@ fn mapAndUpdateSections( |
| 412 | const offset = mem.alignForwardGeneric(u64, target_sect.size, alignment); | 412 | const offset = mem.alignForwardGeneric(u64, target_sect.size, alignment); |
| 413 | const size = mem.alignForwardGeneric(u64, source_sect.inner.size, alignment); | 413 | const size = mem.alignForwardGeneric(u64, source_sect.inner.size, alignment); |
| 414 | | 414 | |
| 415 | log.warn("{s}: '{s},{s}' mapped to '{s},{s}' from 0x{x} to 0x{x}", .{ | 415 | log.debug("{s}: '{s},{s}' mapped to '{s},{s}' from 0x{x} to 0x{x}", .{ |
| 416 | object.name.?, | 416 | object.name.?, |
| 417 | parseName(&source_sect.inner.segname), | 417 | parseName(&source_sect.inner.segname), |
| 418 | parseName(&source_sect.inner.sectname), | 418 | parseName(&source_sect.inner.sectname), |
| ... | @@ -625,8 +625,24 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -625,8 +625,24 @@ fn updateMetadata(self: *Zld) !void { |
| 625 | }, | 625 | }, |
| 626 | macho.S_COALESCED => { | 626 | macho.S_COALESCED => { |
| 627 | if (mem.eql(u8, "__TEXT", segname) and mem.eql(u8, "__eh_frame", sectname)) { | 627 | if (mem.eql(u8, "__TEXT", segname) and mem.eql(u8, "__eh_frame", sectname)) { |
| 628 | log.debug("TODO __eh_frame section: type 0x{x}, name '{s},{s}'", .{ | 628 | // TODO I believe __eh_frame is currently part of __unwind_info section |
| 629 | sect.flags(), segname, sectname, | 629 | // in the latest ld64 output. |
| | 630 | if (self.eh_frame_section_index != null) continue; |
| | 631 | |
| | 632 | self.eh_frame_section_index = @intCast(u16, text_seg.sections.items.len); |
| | 633 | try text_seg.addSection(self.allocator, .{ |
| | 634 | .sectname = makeStaticString("__eh_frame"), |
| | 635 | .segname = makeStaticString("__TEXT"), |
| | 636 | .addr = 0, |
| | 637 | .size = 0, |
| | 638 | .offset = 0, |
| | 639 | .@"align" = 0, |
| | 640 | .reloff = 0, |
| | 641 | .nreloc = 0, |
| | 642 | .flags = macho.S_REGULAR, |
| | 643 | .reserved1 = 0, |
| | 644 | .reserved2 = 0, |
| | 645 | .reserved3 = 0, |
| 630 | }); | 646 | }); |
| 631 | continue; | 647 | continue; |
| 632 | } | 648 | } |
| ... | @@ -682,9 +698,9 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -682,9 +698,9 @@ fn updateMetadata(self: *Zld) !void { |
| 682 | .reserved3 = 0, | 698 | .reserved3 = 0, |
| 683 | }); | 699 | }); |
| 684 | } else if (mem.eql(u8, sectname, "__gcc_except_tab")) { | 700 | } else if (mem.eql(u8, sectname, "__gcc_except_tab")) { |
| 685 | if (self.gcc_except_tab != null) continue; | 701 | if (self.gcc_except_tab_section_index != null) continue; |
| 686 | | 702 | |
| 687 | self.gcc_except_tab = @intCast(u16, text_seg.sections.items.len); | 703 | self.gcc_except_tab_section_index = @intCast(u16, text_seg.sections.items.len); |
| 688 | try text_seg.addSection(self.allocator, .{ | 704 | try text_seg.addSection(self.allocator, .{ |
| 689 | .sectname = makeStaticString("__gcc_except_tab"), | 705 | .sectname = makeStaticString("__gcc_except_tab"), |
| 690 | .segname = makeStaticString("__TEXT"), | 706 | .segname = makeStaticString("__TEXT"), |
| ... | @@ -818,7 +834,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -818,7 +834,7 @@ fn updateMetadata(self: *Zld) !void { |
| 818 | try self.mapAndUpdateSections(object, @intCast(u16, sect_id), res.seg, res.sect); | 834 | try self.mapAndUpdateSections(object, @intCast(u16, sect_id), res.seg, res.sect); |
| 819 | continue; | 835 | continue; |
| 820 | } | 836 | } |
| 821 | log.warn("section '{s},{s}' will be unmapped", .{ sect.segname(), sect.sectname() }); | 837 | log.debug("section '{s},{s}' will be unmapped", .{ sect.segname(), sect.sectname() }); |
| 822 | } | 838 | } |
| 823 | } | 839 | } |
| 824 | | 840 | |
| ... | @@ -976,7 +992,13 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection { | ... | @@ -976,7 +992,13 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection { |
| 976 | }; | 992 | }; |
| 977 | }, | 993 | }, |
| 978 | macho.S_COALESCED => { | 994 | macho.S_COALESCED => { |
| 979 | // TODO coalesced sections | 995 | if (mem.eql(u8, "__TEXT", segname) and mem.eql(u8, "__eh_frame", sectname)) { |
| | 996 | break :blk .{ |
| | 997 | .seg = self.text_segment_cmd_index.?, |
| | 998 | .sect = self.eh_frame_section_index.?, |
| | 999 | }; |
| | 1000 | } |
| | 1001 | |
| 980 | break :blk null; | 1002 | break :blk null; |
| 981 | }, | 1003 | }, |
| 982 | macho.S_REGULAR => { | 1004 | macho.S_REGULAR => { |
| ... | @@ -1000,7 +1022,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection { | ... | @@ -1000,7 +1022,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection { |
| 1000 | } else if (mem.eql(u8, sectname, "__gcc_except_tab")) { | 1022 | } else if (mem.eql(u8, sectname, "__gcc_except_tab")) { |
| 1001 | break :blk .{ | 1023 | break :blk .{ |
| 1002 | .seg = self.text_segment_cmd_index.?, | 1024 | .seg = self.text_segment_cmd_index.?, |
| 1003 | .sect = self.gcc_except_tab.?, | 1025 | .sect = self.gcc_except_tab_section_index.?, |
| 1004 | }; | 1026 | }; |
| 1005 | } else { | 1027 | } else { |
| 1006 | break :blk .{ | 1028 | break :blk .{ |
| ... | @@ -1058,10 +1080,11 @@ fn sortSections(self: *Zld) !void { | ... | @@ -1058,10 +1080,11 @@ fn sortSections(self: *Zld) !void { |
| 1058 | &self.text_section_index, | 1080 | &self.text_section_index, |
| 1059 | &self.stubs_section_index, | 1081 | &self.stubs_section_index, |
| 1060 | &self.stub_helper_section_index, | 1082 | &self.stub_helper_section_index, |
| 1061 | &self.gcc_except_tab, | 1083 | &self.gcc_except_tab_section_index, |
| 1062 | &self.text_const_section_index, | | |
| 1063 | &self.cstring_section_index, | 1084 | &self.cstring_section_index, |
| 1064 | &self.ustring_section_index, | 1085 | &self.ustring_section_index, |
| | 1086 | &self.text_const_section_index, |
| | 1087 | &self.eh_frame_section_index, |
| 1065 | }; | 1088 | }; |
| 1066 | for (indices) |maybe_index| { | 1089 | for (indices) |maybe_index| { |
| 1067 | const new_index: u16 = if (maybe_index.*) |index| blk: { | 1090 | const new_index: u16 = if (maybe_index.*) |index| blk: { |
| ... | @@ -1846,7 +1869,7 @@ fn resolveStubsAndGotEntries(self: *Zld) !void { | ... | @@ -1846,7 +1869,7 @@ fn resolveStubsAndGotEntries(self: *Zld) !void { |
| 1846 | for (relocs) |rel| { | 1869 | for (relocs) |rel| { |
| 1847 | switch (rel.@"type") { | 1870 | switch (rel.@"type") { |
| 1848 | .unsigned => continue, | 1871 | .unsigned => continue, |
| 1849 | .got_page, .got_page_off, .got_load, .got => { | 1872 | .got_page, .got_page_off, .got_load, .got, .pointer_to_got => { |
| 1850 | const sym = rel.target.symbol.getTopmostAlias(); | 1873 | const sym = rel.target.symbol.getTopmostAlias(); |
| 1851 | if (sym.got_index != null) continue; | 1874 | if (sym.got_index != null) continue; |
| 1852 | | 1875 | |
| ... | @@ -1864,9 +1887,6 @@ fn resolveStubsAndGotEntries(self: *Zld) !void { | ... | @@ -1864,9 +1887,6 @@ fn resolveStubsAndGotEntries(self: *Zld) !void { |
| 1864 | | 1887 | |
| 1865 | if (sym.stubs_index != null) continue; | 1888 | if (sym.stubs_index != null) continue; |
| 1866 | if (sym.@"type" != .proxy) continue; | 1889 | if (sym.@"type" != .proxy) continue; |
| 1867 | // if (sym.cast(Symbol.Regular)) |reg| { | | |
| 1868 | // if (!reg.weak_ref) continue; | | |
| 1869 | // } | | |
| 1870 | | 1890 | |
| 1871 | const index = @intCast(u32, self.stubs.items.len); | 1891 | const index = @intCast(u32, self.stubs.items.len); |
| 1872 | sym.stubs_index = index; | 1892 | sym.stubs_index = index; |
| ... | @@ -1977,7 +1997,7 @@ fn resolveRelocsAndWriteSections(self: *Zld) !void { | ... | @@ -1977,7 +1997,7 @@ fn resolveRelocsAndWriteSections(self: *Zld) !void { |
| 1977 | }); | 1997 | }); |
| 1978 | } | 1998 | } |
| 1979 | }, | 1999 | }, |
| 1980 | .got_page, .got_page_off, .got_load, .got => { | 2000 | .got_page, .got_page_off, .got_load, .got, .pointer_to_got => { |
| 1981 | const dc_seg = self.load_commands.items[self.data_const_segment_cmd_index.?].Segment; | 2001 | const dc_seg = self.load_commands.items[self.data_const_segment_cmd_index.?].Segment; |
| 1982 | const got = dc_seg.sections.items[self.got_section_index.?]; | 2002 | const got = dc_seg.sections.items[self.got_section_index.?]; |
| 1983 | const final = rel.target.symbol.getTopmostAlias(); | 2003 | const final = rel.target.symbol.getTopmostAlias(); |