diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-09-03 11:47:58 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-09-03 11:47:58 +0200 |
| commit | 7536a2f8cfdd66fc3b277514ec28ccbedfe83fc1 (patch) | |
| tree | 8c458b0af035a8da1281ab6b15131d32ecf848d3 /src | |
| parent | a783f3a36952449f11b7e763490bdb4076bd62c0 (diff) | |
| download | zig-7536a2f8cfdd66fc3b277514ec28ccbedfe83fc1.tar.gz zig-7536a2f8cfdd66fc3b277514ec28ccbedfe83fc1.zip | |
macho: minor fixes to allow the linker to output malformed stage1
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO.zig | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index e9b98d6ca9..dfd70c4492 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1710,7 +1710,8 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64 const old_base_addr = sect.addr; sect.size = 0; const padding: ?u64 = if (match.seg == self.text_segment_cmd_index.?) self.header_pad else null; - const new_offset = @intCast(u32, seg.findFreeSpace(needed_size, atom.alignment, padding)); + const atom_alignment = try math.powi(u64, 2, atom.alignment); + const new_offset = @intCast(u32, seg.findFreeSpace(needed_size, atom_alignment, padding)); sect.offset = new_offset; sect.addr = seg.inner.vmaddr + sect.offset - seg.inner.fileoff; log.debug(" (found new {s},{s} free space from 0x{x} to 0x{x})", .{ @@ -2741,6 +2742,7 @@ fn setEntryPoint(self: *MachO) !void { const ec = &self.load_commands.items[self.main_cmd_index.?].Main; ec.entryoff = @intCast(u32, sym.n_value - seg.inner.vmaddr); ec.stacksize = self.base.options.stack_size_override orelse 0; + self.entry_addr = sym.n_value; self.load_commands_dirty = true; } @@ -3234,15 +3236,7 @@ pub fn updateDeclExports( n_type |= macho.N_PEXT; n_desc |= macho.N_WEAK_DEF; }, - .Strong => { - // Check if the export is _main, and note if os. - // Otherwise, don't do anything since we already have all the flags - // set that we need for global (strong) linkage. - // n_type == N_SECT | N_EXT - if (mem.eql(u8, exp_name, "_main")) { - self.entry_addr = decl_sym.n_value; - } - }, + .Strong => {}, .Weak => { // Weak linkage is specified as part of n_desc field. // Symbol's n_type is like for a symbol with strong linkage. @@ -4244,7 +4238,14 @@ fn relocateSymbolTable(self: *MachO) !void { new_symoff + existing_size, }); - const amt = try self.base.file.?.copyRangeAll(symtab.symoff, self.base.file.?, new_symoff, existing_size); + // TODO copyRangeAll doesn't seem to extend the file beyond its allocated size + try self.base.file.?.pwriteAll(&[_]u8{0}, new_symoff + existing_size - 1); + const amt = try self.base.file.?.copyRangeAll( + symtab.symoff, + self.base.file.?, + new_symoff, + existing_size, + ); if (amt != existing_size) return error.InputOutput; symtab.symoff = @intCast(u32, new_symoff); self.strtab_needs_relocation = true; |
