| ... | @@ -138,6 +138,8 @@ got_section_index: ?u8 = null, | ... | @@ -138,6 +138,8 @@ got_section_index: ?u8 = null, |
| 138 | data_const_section_index: ?u8 = null, | 138 | data_const_section_index: ?u8 = null, |
| 139 | la_symbol_ptr_section_index: ?u8 = null, | 139 | la_symbol_ptr_section_index: ?u8 = null, |
| 140 | data_section_index: ?u8 = null, | 140 | data_section_index: ?u8 = null, |
| | 141 | tls_vars_section_index: ?u8 = null, |
| | 142 | tls_data_section_index: ?u8 = null, |
| 141 | | 143 | |
| 142 | locals: std.ArrayListUnmanaged(macho.nlist_64) = .{}, | 144 | locals: std.ArrayListUnmanaged(macho.nlist_64) = .{}, |
| 143 | globals: std.ArrayListUnmanaged(SymbolWithLoc) = .{}, | 145 | globals: std.ArrayListUnmanaged(SymbolWithLoc) = .{}, |
| ... | @@ -2366,6 +2368,7 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 { | ... | @@ -2366,6 +2368,7 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 { |
| 2366 | const val = decl.val; | 2368 | const val = decl.val; |
| 2367 | const zig_ty = ty.zigTypeTag(); | 2369 | const zig_ty = ty.zigTypeTag(); |
| 2368 | const mode = self.base.options.optimize_mode; | 2370 | const mode = self.base.options.optimize_mode; |
| | 2371 | const single_threaded = self.base.options.single_threaded; |
| 2369 | const sect_id: u8 = blk: { | 2372 | const sect_id: u8 = blk: { |
| 2370 | // TODO finish and audit this function | 2373 | // TODO finish and audit this function |
| 2371 | if (val.isUndefDeep()) { | 2374 | if (val.isUndefDeep()) { |
| ... | @@ -2376,7 +2379,10 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 { | ... | @@ -2376,7 +2379,10 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 { |
| 2376 | } | 2379 | } |
| 2377 | } | 2380 | } |
| 2378 | | 2381 | |
| 2379 | if (val.castTag(.variable)) |_| { | 2382 | if (val.castTag(.variable)) |variable| { |
| | 2383 | if (variable.data.is_threadlocal and !single_threaded) { |
| | 2384 | break :blk self.tls_data_section_index.?; |
| | 2385 | } |
| 2380 | break :blk self.data_section_index.?; | 2386 | break :blk self.data_section_index.?; |
| 2381 | } | 2387 | } |
| 2382 | | 2388 | |
| ... | @@ -2800,6 +2806,28 @@ fn populateMissingMetadata(self: *MachO) !void { | ... | @@ -2800,6 +2806,28 @@ fn populateMissingMetadata(self: *MachO) !void { |
| 2800 | self.segment_table_dirty = true; | 2806 | self.segment_table_dirty = true; |
| 2801 | } | 2807 | } |
| 2802 | | 2808 | |
| | 2809 | if (!self.base.options.single_threaded) { |
| | 2810 | if (self.tls_vars_section_index == null) { |
| | 2811 | self.tls_vars_section_index = try self.allocateSection("__DATA2", "__thread_vars", .{ |
| | 2812 | .size = @sizeOf(u64) * 3, |
| | 2813 | .alignment = @alignOf(u64), |
| | 2814 | .flags = macho.S_THREAD_LOCAL_VARIABLES, |
| | 2815 | .prot = macho.PROT.READ | macho.PROT.WRITE, |
| | 2816 | }); |
| | 2817 | self.segment_table_dirty = true; |
| | 2818 | } |
| | 2819 | |
| | 2820 | if (self.tls_data_section_index == null) { |
| | 2821 | self.tls_data_section_index = try self.allocateSection("__DATA3", "__thread_data", .{ |
| | 2822 | .size = @sizeOf(u64), |
| | 2823 | .alignment = @alignOf(u64), |
| | 2824 | .flags = macho.S_THREAD_LOCAL_REGULAR, |
| | 2825 | .prot = macho.PROT.READ | macho.PROT.WRITE, |
| | 2826 | }); |
| | 2827 | self.segment_table_dirty = true; |
| | 2828 | } |
| | 2829 | } |
| | 2830 | |
| 2803 | if (self.linkedit_segment_cmd_index == null) { | 2831 | if (self.linkedit_segment_cmd_index == null) { |
| 2804 | self.linkedit_segment_cmd_index = @intCast(u8, self.segments.items.len); | 2832 | self.linkedit_segment_cmd_index = @intCast(u8, self.segments.items.len); |
| 2805 | | 2833 | |