| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const MachO = @This(); |
| 2 | | |
| 3 | 2 | const std = @import("std"); |
| 4 | 3 | const Allocator = std.mem.Allocator; |
| 5 | 4 | const assert = std.debug.assert; |
| ... | ... | @@ -375,6 +374,12 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 375 | 374 | try self.writeSymbolTable(); |
| 376 | 375 | try self.writeStringTable(); |
| 377 | 376 | |
| 377 | { |
| 378 | // Seal __DATA,__got section size |
| 379 | const got = &self.sections.items[self.got_section_index.?]; |
| 380 | got.size = @intCast(u32, self.offset_table.items.len * @sizeOf(u64)); |
| 381 | } |
| 382 | |
| 378 | 383 | { |
| 379 | 384 | // TODO rework how we preallocate space for the entire __LINKEDIT segment instead of |
| 380 | 385 | // doing dynamic updates like this. |
| ... | ... | @@ -947,7 +952,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void { |
| 947 | 952 | }, |
| 948 | 953 | }; |
| 949 | 954 | |
| 950 | | const required_alignment = typed_value.ty.abiAlignment(self.base.options.target); |
| 955 | // const required_alignment = typed_value.ty.abiAlignment(self.base.options.target); |
| 956 | const required_alignment = 4; |
| 951 | 957 | assert(decl.link.macho.local_sym_index != 0); // Caller forgot to call allocateDeclIndexes() |
| 952 | 958 | const symbol = &self.local_symbols.items[decl.link.macho.local_sym_index]; |
| 953 | 959 | |
| ... | ... | @@ -997,7 +1003,6 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void { |
| 997 | 1003 | const text_section = self.sections.items[self.text_section_index.?]; |
| 998 | 1004 | const section_offset = symbol.n_value - text_section.addr; |
| 999 | 1005 | const file_offset = text_section.offset + section_offset; |
| 1000 | | |
| 1001 | 1006 | try self.base.file.?.pwriteAll(code, file_offset); |
| 1002 | 1007 | |
| 1003 | 1008 | // Since we updated the vaddr and the size, each corresponding export symbol also needs to be updated. |
| ... | ... | @@ -1168,7 +1173,7 @@ pub fn populateMissingMetadata(self: *MachO) !void { |
| 1168 | 1173 | .addr = text_segment.vmaddr + off, |
| 1169 | 1174 | .size = file_size, |
| 1170 | 1175 | .offset = off, |
| 1171 | | .@"align" = 12, // 2^12 = 4096 |
| 1176 | .@"align" = 2, // 2^12 = 4096 |
| 1172 | 1177 | .reloff = 0, |
| 1173 | 1178 | .nreloc = 0, |
| 1174 | 1179 | .flags = flags, |
| ... | ... | @@ -1193,7 +1198,7 @@ pub fn populateMissingMetadata(self: *MachO) !void { |
| 1193 | 1198 | .segname = makeStaticString("__DATA"), |
| 1194 | 1199 | .vmaddr = text_segment.vmaddr + text_segment.vmsize, |
| 1195 | 1200 | .vmsize = 0, |
| 1196 | | .fileoff = 0, |
| 1201 | .fileoff = text_segment.fileoff + text_segment.filesize, |
| 1197 | 1202 | .filesize = 0, |
| 1198 | 1203 | .maxprot = maxprot, |
| 1199 | 1204 | .initprot = initprot, |
| ... | ... | @@ -1210,7 +1215,8 @@ pub fn populateMissingMetadata(self: *MachO) !void { |
| 1210 | 1215 | data_segment.nsects += 1; |
| 1211 | 1216 | |
| 1212 | 1217 | const file_size = @sizeOf(u64) * self.base.options.symbol_count_hint; |
| 1213 | | const off = @intCast(u32, self.findFreeSpace(file_size, 0x1000)); |
| 1218 | // const off = @intCast(u32, self.findFreeSpace(file_size, 0x1000)); |
| 1219 | const off = @intCast(u32, data_segment.fileoff); |
| 1214 | 1220 | |
| 1215 | 1221 | log.debug("found __got section free space 0x{x} to 0x{x}\n", .{ off, off + file_size }); |
| 1216 | 1222 | |