| ... | @@ -481,8 +481,7 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -481,8 +481,7 @@ fn updateMetadata(self: *Zld) !void { |
| 481 | .reserved3 = 0, | 481 | .reserved3 = 0, |
| 482 | }); | 482 | }); |
| 483 | } | 483 | } |
| 484 | } else if (mem.eql(u8, segname, "__DATA")) { | 484 | } else if (mem.eql(u8, segname, "__DATA") or mem.eql(u8, segname, "__DATA_CONST")) { |
| 485 | if (!mem.eql(u8, sectname, "__const")) continue; | | |
| 486 | if (self.data_const_section_index != null) continue; | 485 | if (self.data_const_section_index != null) continue; |
| 487 | | 486 | |
| 488 | self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len); | 487 | self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| ... | @@ -503,7 +502,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -503,7 +502,6 @@ fn updateMetadata(self: *Zld) !void { |
| 503 | } | 502 | } |
| 504 | }, | 503 | }, |
| 505 | macho.S_CSTRING_LITERALS => { | 504 | macho.S_CSTRING_LITERALS => { |
| 506 | if (!mem.eql(u8, segname, "__TEXT")) continue; | | |
| 507 | if (self.cstring_section_index != null) continue; | 505 | if (self.cstring_section_index != null) continue; |
| 508 | | 506 | |
| 509 | self.cstring_section_index = @intCast(u16, text_seg.sections.items.len); | 507 | self.cstring_section_index = @intCast(u16, text_seg.sections.items.len); |
| ... | @@ -523,7 +521,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -523,7 +521,6 @@ fn updateMetadata(self: *Zld) !void { |
| 523 | }); | 521 | }); |
| 524 | }, | 522 | }, |
| 525 | macho.S_MOD_INIT_FUNC_POINTERS => { | 523 | macho.S_MOD_INIT_FUNC_POINTERS => { |
| 526 | if (!mem.eql(u8, segname, "__DATA")) continue; | | |
| 527 | if (self.mod_init_func_section_index != null) continue; | 524 | if (self.mod_init_func_section_index != null) continue; |
| 528 | | 525 | |
| 529 | self.mod_init_func_section_index = @intCast(u16, data_const_seg.sections.items.len); | 526 | self.mod_init_func_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| ... | @@ -543,7 +540,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -543,7 +540,6 @@ fn updateMetadata(self: *Zld) !void { |
| 543 | }); | 540 | }); |
| 544 | }, | 541 | }, |
| 545 | macho.S_MOD_TERM_FUNC_POINTERS => { | 542 | macho.S_MOD_TERM_FUNC_POINTERS => { |
| 546 | if (!mem.eql(u8, segname, "__DATA")) continue; | | |
| 547 | if (self.mod_term_func_section_index != null) continue; | 543 | if (self.mod_term_func_section_index != null) continue; |
| 548 | | 544 | |
| 549 | self.mod_term_func_section_index = @intCast(u16, data_const_seg.sections.items.len); | 545 | self.mod_term_func_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| ... | @@ -563,7 +559,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -563,7 +559,6 @@ fn updateMetadata(self: *Zld) !void { |
| 563 | }); | 559 | }); |
| 564 | }, | 560 | }, |
| 565 | macho.S_ZEROFILL => { | 561 | macho.S_ZEROFILL => { |
| 566 | if (!mem.eql(u8, segname, "__DATA")) continue; | | |
| 567 | if (mem.eql(u8, sectname, "__common")) { | 562 | if (mem.eql(u8, sectname, "__common")) { |
| 568 | if (self.common_section_index != null) continue; | 563 | if (self.common_section_index != null) continue; |
| 569 | | 564 | |
| ... | @@ -603,7 +598,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -603,7 +598,6 @@ fn updateMetadata(self: *Zld) !void { |
| 603 | } | 598 | } |
| 604 | }, | 599 | }, |
| 605 | macho.S_THREAD_LOCAL_VARIABLES => { | 600 | macho.S_THREAD_LOCAL_VARIABLES => { |
| 606 | if (!mem.eql(u8, segname, "__DATA")) continue; | | |
| 607 | if (self.tlv_section_index != null) continue; | 601 | if (self.tlv_section_index != null) continue; |
| 608 | | 602 | |
| 609 | self.tlv_section_index = @intCast(u16, data_seg.sections.items.len); | 603 | self.tlv_section_index = @intCast(u16, data_seg.sections.items.len); |
| ... | @@ -623,7 +617,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -623,7 +617,6 @@ fn updateMetadata(self: *Zld) !void { |
| 623 | }); | 617 | }); |
| 624 | }, | 618 | }, |
| 625 | macho.S_THREAD_LOCAL_REGULAR => { | 619 | macho.S_THREAD_LOCAL_REGULAR => { |
| 626 | if (!mem.eql(u8, segname, "__DATA")) continue; | | |
| 627 | if (self.tlv_data_section_index != null) continue; | 620 | if (self.tlv_data_section_index != null) continue; |
| 628 | | 621 | |
| 629 | self.tlv_data_section_index = @intCast(u16, data_seg.sections.items.len); | 622 | self.tlv_data_section_index = @intCast(u16, data_seg.sections.items.len); |
| ... | @@ -643,7 +636,6 @@ fn updateMetadata(self: *Zld) !void { | ... | @@ -643,7 +636,6 @@ fn updateMetadata(self: *Zld) !void { |
| 643 | }); | 636 | }); |
| 644 | }, | 637 | }, |
| 645 | macho.S_THREAD_LOCAL_ZEROFILL => { | 638 | macho.S_THREAD_LOCAL_ZEROFILL => { |
| 646 | if (!mem.eql(u8, segname, "__DATA")) continue; | | |
| 647 | if (self.tlv_bss_section_index != null) continue; | 639 | if (self.tlv_bss_section_index != null) continue; |
| 648 | | 640 | |
| 649 | self.tlv_bss_section_index = @intCast(u16, data_seg.sections.items.len); | 641 | self.tlv_bss_section_index = @intCast(u16, data_seg.sections.items.len); |
| ... | @@ -863,6 +855,12 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { | ... | @@ -863,6 +855,12 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { |
| 863 | .sect = self.text_const_section_index.?, | 855 | .sect = self.text_const_section_index.?, |
| 864 | }; | 856 | }; |
| 865 | } | 857 | } |
| | 858 | if (mem.eql(u8, segname, "__DATA_CONST")) { |
| | 859 | break :blk .{ |
| | 860 | .seg = self.data_const_segment_cmd_index.?, |
| | 861 | .sect = self.data_const_section_index.?, |
| | 862 | }; |
| | 863 | } |
| 866 | if (mem.eql(u8, segname, "__DATA")) { | 864 | if (mem.eql(u8, segname, "__DATA")) { |
| 867 | if (mem.eql(u8, sectname, "__const")) { | 865 | if (mem.eql(u8, sectname, "__const")) { |
| 868 | break :blk .{ | 866 | break :blk .{ |
| ... | @@ -1900,7 +1898,12 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T | ... | @@ -1900,7 +1898,12 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T |
| 1900 | } | 1898 | } |
| 1901 | }, | 1899 | }, |
| 1902 | .section => |sect_id| { | 1900 | .section => |sect_id| { |
| | 1901 | log.debug(" | section offset", .{}); |
| 1903 | const source_sect = object.sections.items[sect_id]; | 1902 | const source_sect = object.sections.items[sect_id]; |
| | 1903 | log.debug(" | section '{s},{s}'", .{ |
| | 1904 | parseName(&source_sect.inner.segname), |
| | 1905 | parseName(&source_sect.inner.sectname), |
| | 1906 | }); |
| 1904 | const target_map = source_sect.target_map orelse unreachable; | 1907 | const target_map = source_sect.target_map orelse unreachable; |
| 1905 | const target_seg = self.load_commands.items[target_map.segment_id].Segment; | 1908 | const target_seg = self.load_commands.items[target_map.segment_id].Segment; |
| 1906 | const target_sect = target_seg.sections.items[target_map.section_id]; | 1909 | const target_sect = target_seg.sections.items[target_map.section_id]; |