| ... | ... | @@ -646,6 +646,26 @@ fn updateMetadata(self: *Zld) !void { |
| 646 | 646 | }); |
| 647 | 647 | continue; |
| 648 | 648 | } |
| 649 | |
| 650 | // TODO audit this: is this the right mapping? |
| 651 | if (self.data_const_section_index != null) continue; |
| 652 | |
| 653 | self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| 654 | try data_const_seg.addSection(self.allocator, .{ |
| 655 | .sectname = makeStaticString("__const"), |
| 656 | .segname = makeStaticString("__DATA_CONST"), |
| 657 | .addr = 0, |
| 658 | .size = 0, |
| 659 | .offset = 0, |
| 660 | .@"align" = 0, |
| 661 | .reloff = 0, |
| 662 | .nreloc = 0, |
| 663 | .flags = macho.S_REGULAR, |
| 664 | .reserved1 = 0, |
| 665 | .reserved2 = 0, |
| 666 | .reserved3 = 0, |
| 667 | }); |
| 668 | continue; |
| 649 | 669 | }, |
| 650 | 670 | macho.S_REGULAR => { |
| 651 | 671 | if (sect.isCode()) { |
| ... | ... | @@ -999,7 +1019,10 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection { |
| 999 | 1019 | }; |
| 1000 | 1020 | } |
| 1001 | 1021 | |
| 1002 | | break :blk null; |
| 1022 | break :blk .{ |
| 1023 | .seg = self.data_const_segment_cmd_index.?, |
| 1024 | .sect = self.data_const_section_index.?, |
| 1025 | }; |
| 1003 | 1026 | }, |
| 1004 | 1027 | macho.S_REGULAR => { |
| 1005 | 1028 | if (sect.isCode()) { |
| ... | ... | @@ -2001,7 +2024,15 @@ fn resolveRelocsAndWriteSections(self: *Zld) !void { |
| 2001 | 2024 | const dc_seg = self.load_commands.items[self.data_const_segment_cmd_index.?].Segment; |
| 2002 | 2025 | const got = dc_seg.sections.items[self.got_section_index.?]; |
| 2003 | 2026 | const final = rel.target.symbol.getTopmostAlias(); |
| 2004 | | args.target_addr = got.addr + final.got_index.? * @sizeOf(u64); |
| 2027 | const got_index = final.got_index orelse { |
| 2028 | // TODO remove this when we can link against TAPI files. |
| 2029 | log.err("undefined reference to symbol '{s}'", .{final.name}); |
| 2030 | log.err(" | referenced in {s}", .{ |
| 2031 | rel.target.symbol.cast(Symbol.Unresolved).?.file.name.?, |
| 2032 | }); |
| 2033 | return error.UndefinedSymbolReference; |
| 2034 | }; |
| 2035 | args.target_addr = got.addr + got_index * @sizeOf(u64); |
| 2005 | 2036 | }, |
| 2006 | 2037 | else => |tt| { |
| 2007 | 2038 | if (tt == .signed and rel.target == .section) { |
| ... | ... | @@ -2067,7 +2098,15 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T |
| 2067 | 2098 | log.debug(" | symbol stub '{s}'", .{sym.name}); |
| 2068 | 2099 | const segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment; |
| 2069 | 2100 | const stubs = segment.sections.items[self.stubs_section_index.?]; |
| 2070 | | break :blk stubs.addr + proxy.base.stubs_index.? * stubs.reserved2; |
| 2101 | const stubs_index = proxy.base.stubs_index orelse { |
| 2102 | // TODO remove this when we can link against TAPI files. |
| 2103 | log.err("undefined reference to symbol '{s}'", .{final.name}); |
| 2104 | log.err(" | referenced in {s}", .{ |
| 2105 | sym.cast(Symbol.Unresolved).?.file.name.?, |
| 2106 | }); |
| 2107 | return error.UndefinedSymbolReference; |
| 2108 | }; |
| 2109 | break :blk stubs.addr + stubs_index * stubs.reserved2; |
| 2071 | 2110 | } else { |
| 2072 | 2111 | log.err("failed to resolve symbol '{s}' as a relocation target", .{sym.name}); |
| 2073 | 2112 | return error.FailedToResolveRelocationTarget; |