authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-17 09:57:35+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-26 11:50:09+01:00
log4e3520a2f750474471308c520af072631dc31a9d
treedfae0af754e29dd3c80d0937e67d5a5baddfae73
parent8450e6f156e365dd14756f74e748f755fc0cc5ab

stage2 macho: make page size target cpu arch dependent


1 files changed, 9 insertions(+), 4 deletions(-)

src/link/MachO.zig+9-4
......@@ -73,6 +73,10 @@ const LoadCommand = union(enum) {
7373
7474base: File,
7575
76/// Page size is dependent on the target cpu architecture.
77/// For x86_64 that's 4KB, whereas for aarch64, that's 16KB.
78page_size: u16,
79
7680/// Table of all load commands
7781load_commands: std.ArrayListUnmanaged(LoadCommand) = .{},
7882/// __PAGEZERO segment
......@@ -301,6 +305,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*MachO {
301305 .allocator = gpa,
302306 .file = null,
303307 },
308 .page_size = if (options.target.cpu.arch == .aarch64) 0x4000 else 0x1000,
304309 };
305310 return self;
306311}
......@@ -387,7 +392,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
387392 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
388393 const file_size = symtab.stroff + symtab.strsize - linkedit.fileoff;
389394 linkedit.filesize = file_size;
390 linkedit.vmsize = mem.alignForwardGeneric(u64, file_size, 0x4000);
395 linkedit.vmsize = mem.alignForwardGeneric(u64, file_size, self.page_size);
391396 }
392397
393398 if (self.cmd_table_dirty) {
......@@ -1163,8 +1168,8 @@ pub fn populateMissingMetadata(self: *MachO) !void {
11631168
11641169 // const program_code_size_hint = self.base.options.program_code_size_hint;
11651170 const program_code_size_hint = 128;
1166 const file_size = mem.alignForwardGeneric(u64, program_code_size_hint, 0x4000);
1167 const off = @intCast(u32, self.findFreeSpace(file_size, 0x4000)); // TODO maybe findFreeSpace should return u32 directly?
1171 const file_size = mem.alignForwardGeneric(u64, program_code_size_hint, self.page_size);
1172 const off = @intCast(u32, self.findFreeSpace(file_size, self.page_size)); // TODO maybe findFreeSpace should return u32 directly?
11681173 const flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS;
11691174
11701175 log.debug("found __text section free space 0x{x} to 0x{x}\n", .{ off, off + file_size });
......@@ -1237,7 +1242,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
12371242 .reserved3 = 0,
12381243 });
12391244
1240 const segment_size = mem.alignForwardGeneric(u64, file_size, 0x4000);
1245 const segment_size = mem.alignForwardGeneric(u64, file_size, self.page_size);
12411246 data_segment.vmsize = segment_size;
12421247 data_segment.filesize = segment_size;
12431248 data_segment.fileoff = off;