aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-21 10:32:06 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-01-24 12:34:42 +0100
commit3a6410959ca6df6f020547c58845730753dc9e97 (patch)
treea8e3f8b35f617fcd903d97be7c478527edb65632 /src/link/MachO.zig
parent411c7f6669ed2eb758f371dfde59e03abf05aa0a (diff)
downloadzig-3a6410959ca6df6f020547c58845730753dc9e97.tar.gz
zig-3a6410959ca6df6f020547c58845730753dc9e97.zip
macho: actually lower TLS variables
Diffstat (limited to 'src/link/MachO.zig')
-rw-r--r--src/link/MachO.zig17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index cba79e1262..9a4bdfcc86 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -606,7 +606,10 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
if (!atom.flags.alive) continue;
const sect = &self.sections.items(.header)[atom.out_n_sect];
if (sect.isZerofill()) continue;
- const code = zo.getAtomDataAlloc(self, atom.*) catch |err| switch (err) {
+ if (mem.indexOf(u8, sect.segName(), "ZIG") == null) continue; // Non-Zig sections are handled separately
+ // TODO: we will resolve and write ZigObject's TLS data twice:
+ // once here, and once in writeAtoms
+ const code = zo.getAtomDataAlloc(self, gpa, atom.*) catch |err| switch (err) {
error.InputOutput => {
try self.reportUnexpectedError("fetching code for '{s}' failed", .{
atom.getName(self),
@@ -1806,7 +1809,7 @@ fn initOutputSections(self: *MachO) !void {
.aarch64 => 2,
else => unreachable,
},
- .flags = macho.S_SYMBOL_STUBS |
+ .flags = macho.S_REGULAR |
macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
});
}
@@ -2545,6 +2548,9 @@ fn writeAtoms(self: *MachO) !void {
defer tracy.end();
const gpa = self.base.comp.gpa;
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+
const cpu_arch = self.getTarget().cpu.arch;
const slice = self.sections.slice();
@@ -2562,7 +2568,12 @@ fn writeAtoms(self: *MachO) !void {
const atom = self.getAtom(atom_index).?;
assert(atom.flags.alive);
const off = atom.value - header.addr;
- @memcpy(buffer[off..][0..atom.size], atom.getFile(self).object.getAtomData(atom.*));
+ const data = switch (atom.getFile(self)) {
+ .object => |x| x.getAtomData(atom.*),
+ .zig_object => |x| try x.getAtomDataAlloc(self, arena.allocator(), atom.*),
+ else => unreachable,
+ };
+ @memcpy(buffer[off..][0..atom.size], data);
atom.resolveRelocs(self, buffer[off..][0..atom.size]) catch |err| switch (err) {
error.ResolveFailed => has_resolve_error = true,
else => |e| return e,