| ... | @@ -131,7 +131,6 @@ pub const TextBlock = struct { | ... | @@ -131,7 +131,6 @@ pub const TextBlock = struct { |
| 131 | size: u64, | 131 | size: u64, |
| 132 | alignment: u32, | 132 | alignment: u32, |
| 133 | rebases: std.ArrayList(u64), | 133 | rebases: std.ArrayList(u64), |
| 134 | tlv_offsets: std.ArrayList(TlvOffset), | | |
| 135 | next: ?*TextBlock = null, | 134 | next: ?*TextBlock = null, |
| 136 | prev: ?*TextBlock = null, | 135 | prev: ?*TextBlock = null, |
| 137 | | 136 | |
| ... | @@ -140,11 +139,6 @@ pub const TextBlock = struct { | ... | @@ -140,11 +139,6 @@ pub const TextBlock = struct { |
| 140 | offset: u64, | 139 | offset: u64, |
| 141 | }; | 140 | }; |
| 142 | | 141 | |
| 143 | pub const TlvOffset = struct { | | |
| 144 | local_sym_index: u32, | | |
| 145 | offset: u64, | | |
| 146 | }; | | |
| 147 | | | |
| 148 | pub fn init(allocator: *Allocator) TextBlock { | 142 | pub fn init(allocator: *Allocator) TextBlock { |
| 149 | return .{ | 143 | return .{ |
| 150 | .allocator = allocator, | 144 | .allocator = allocator, |
| ... | @@ -155,7 +149,6 @@ pub const TextBlock = struct { | ... | @@ -155,7 +149,6 @@ pub const TextBlock = struct { |
| 155 | .size = undefined, | 149 | .size = undefined, |
| 156 | .alignment = undefined, | 150 | .alignment = undefined, |
| 157 | .rebases = std.ArrayList(u64).init(allocator), | 151 | .rebases = std.ArrayList(u64).init(allocator), |
| 158 | .tlv_offsets = std.ArrayList(TextBlock.TlvOffset).init(allocator), | | |
| 159 | }; | 152 | }; |
| 160 | } | 153 | } |
| 161 | | 154 | |
| ... | @@ -170,7 +163,6 @@ pub const TextBlock = struct { | ... | @@ -170,7 +163,6 @@ pub const TextBlock = struct { |
| 170 | self.allocator.free(self.code); | 163 | self.allocator.free(self.code); |
| 171 | self.relocs.deinit(); | 164 | self.relocs.deinit(); |
| 172 | self.rebases.deinit(); | 165 | self.rebases.deinit(); |
| 173 | self.tlv_offsets.deinit(); | | |
| 174 | } | 166 | } |
| 175 | | 167 | |
| 176 | pub fn resolveRelocs(self: *TextBlock, zld: *Zld) !void { | 168 | pub fn resolveRelocs(self: *TextBlock, zld: *Zld) !void { |
| ... | @@ -210,9 +202,6 @@ pub const TextBlock = struct { | ... | @@ -210,9 +202,6 @@ pub const TextBlock = struct { |
| 210 | if (self.rebases.items.len > 0) { | 202 | if (self.rebases.items.len > 0) { |
| 211 | log.warn(" | rebases: {any}", .{self.rebases.items}); | 203 | log.warn(" | rebases: {any}", .{self.rebases.items}); |
| 212 | } | 204 | } |
| 213 | if (self.tlv_offsets.items.len > 0) { | | |
| 214 | log.warn(" | TLV offsets: {any}", .{self.tlv_offsets.items}); | | |
| 215 | } | | |
| 216 | log.warn(" | size = {}", .{self.size}); | 205 | log.warn(" | size = {}", .{self.size}); |
| 217 | log.warn(" | align = {}", .{self.alignment}); | 206 | log.warn(" | align = {}", .{self.alignment}); |
| 218 | } | 207 | } |
| ... | @@ -1120,10 +1109,7 @@ fn writeTextBlocks(self: *Zld) !void { | ... | @@ -1120,10 +1109,7 @@ fn writeTextBlocks(self: *Zld) !void { |
| 1120 | var code = try self.allocator.alloc(u8, sect.size); | 1109 | var code = try self.allocator.alloc(u8, sect.size); |
| 1121 | defer self.allocator.free(code); | 1110 | defer self.allocator.free(code); |
| 1122 | | 1111 | |
| 1123 | if (sect_type == macho.S_ZEROFILL or | 1112 | if (sect_type == macho.S_ZEROFILL or sect_type == macho.S_THREAD_LOCAL_ZEROFILL) { |
| 1124 | sect_type == macho.S_THREAD_LOCAL_ZEROFILL or | | |
| 1125 | sect_type == macho.S_THREAD_LOCAL_VARIABLES) | | |
| 1126 | { | | |
| 1127 | mem.set(u8, code, 0); | 1113 | mem.set(u8, code, 0); |
| 1128 | } else { | 1114 | } else { |
| 1129 | var base_off: u64 = sect.size; | 1115 | var base_off: u64 = sect.size; |
| ... | @@ -2051,41 +2037,6 @@ fn flush(self: *Zld) !void { | ... | @@ -2051,41 +2037,6 @@ fn flush(self: *Zld) !void { |
| 2051 | sect.offset = 0; | 2037 | sect.offset = 0; |
| 2052 | } | 2038 | } |
| 2053 | | 2039 | |
| 2054 | if (self.tlv_section_index) |index| { | | |
| 2055 | // TODO this should be part of relocation resolution routine. | | |
| 2056 | const seg = self.load_commands.items[self.data_segment_cmd_index.?].Segment; | | |
| 2057 | const sect = &seg.sections.items[index]; | | |
| 2058 | | | |
| 2059 | const base_addr = if (self.tlv_data_section_index) |i| | | |
| 2060 | seg.sections.items[i].addr | | |
| 2061 | else | | |
| 2062 | seg.sections.items[self.tlv_bss_section_index.?].addr; | | |
| 2063 | | | |
| 2064 | var block: *TextBlock = self.blocks.get(.{ | | |
| 2065 | .seg = self.data_segment_cmd_index.?, | | |
| 2066 | .sect = index, | | |
| 2067 | }) orelse unreachable; | | |
| 2068 | | | |
| 2069 | var buffer = try self.allocator.alloc(u8, @intCast(usize, sect.size)); | | |
| 2070 | defer self.allocator.free(buffer); | | |
| 2071 | _ = try self.file.?.preadAll(buffer, sect.offset); | | |
| 2072 | | | |
| 2073 | while (true) { | | |
| 2074 | for (block.tlv_offsets.items) |tlv_offset| { | | |
| 2075 | const sym = self.locals.items[tlv_offset.local_sym_index]; | | |
| 2076 | assert(sym.payload == .regular); | | |
| 2077 | const offset = sym.payload.regular.address - base_addr; | | |
| 2078 | mem.writeIntLittle(u64, buffer[tlv_offset.offset..][0..@sizeOf(u64)], offset); | | |
| 2079 | } | | |
| 2080 | | | |
| 2081 | if (block.prev) |prev| { | | |
| 2082 | block = prev; | | |
| 2083 | } else break; | | |
| 2084 | } | | |
| 2085 | | | |
| 2086 | try self.file.?.pwriteAll(buffer, sect.offset); | | |
| 2087 | } | | |
| 2088 | | | |
| 2089 | try self.writeGotEntries(); | 2040 | try self.writeGotEntries(); |
| 2090 | try self.setEntryPoint(); | 2041 | try self.setEntryPoint(); |
| 2091 | try self.writeRebaseInfoTable(); | 2042 | try self.writeRebaseInfoTable(); |