| ... | ... | @@ -137,8 +137,9 @@ got_section_index: ?u8 = null, |
| 137 | 137 | data_const_section_index: ?u8 = null, |
| 138 | 138 | la_symbol_ptr_section_index: ?u8 = null, |
| 139 | 139 | data_section_index: ?u8 = null, |
| 140 | | tls_vars_section_index: ?u8 = null, |
| 141 | | tls_data_section_index: ?u8 = null, |
| 140 | thread_ptr_section_index: ?u8 = null, |
| 141 | thread_vars_section_index: ?u8 = null, |
| 142 | thread_data_section_index: ?u8 = null, |
| 142 | 143 | |
| 143 | 144 | locals: std.ArrayListUnmanaged(macho.nlist_64) = .{}, |
| 144 | 145 | globals: std.ArrayListUnmanaged(SymbolWithLoc) = .{}, |
| ... | ... | @@ -1365,6 +1366,7 @@ pub fn createGotAtom(self: *MachO, target: SymbolWithLoc) !Atom.Index { |
| 1365 | 1366 | } else { |
| 1366 | 1367 | try Atom.addRebase(self, atom_index, 0); |
| 1367 | 1368 | } |
| 1369 | try self.writePtrWidthAtom(atom_index); |
| 1368 | 1370 | |
| 1369 | 1371 | return atom_index; |
| 1370 | 1372 | } |
| ... | ... | @@ -2071,7 +2073,7 @@ fn addGotEntry(self: *MachO, target: SymbolWithLoc) !void { |
| 2071 | 2073 | const got_atom_index = try self.createGotAtom(target); |
| 2072 | 2074 | const got_atom = self.getAtom(got_atom_index); |
| 2073 | 2075 | self.got_table.entries.items[got_index].sym_index = got_atom.getSymbolIndex().?; |
| 2074 | | try self.writePtrWidthAtom(got_atom_index); |
| 2076 | self.markRelocsDirtyByTarget(target); |
| 2075 | 2077 | } |
| 2076 | 2078 | |
| 2077 | 2079 | fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void { |
| ... | ... | @@ -2087,6 +2089,10 @@ fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void { |
| 2087 | 2089 | self.markRelocsDirtyByTarget(target); |
| 2088 | 2090 | } |
| 2089 | 2091 | |
| 2092 | fn addTlvEntry(self: *MachO, target: SymbolWithLoc) !void { |
| 2093 | if (self.tlvp_table.lookup.contains(target)) return; |
| 2094 | } |
| 2095 | |
| 2090 | 2096 | pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { |
| 2091 | 2097 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 2092 | 2098 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| ... | ... | @@ -2366,7 +2372,6 @@ fn updateLazySymbolAtom( |
| 2366 | 2372 | symbol.n_value = vaddr; |
| 2367 | 2373 | |
| 2368 | 2374 | try self.addGotEntry(.{ .sym_index = local_sym_index }); |
| 2369 | | self.markRelocsDirtyByTarget(atom.getSymbolWithLoc()); |
| 2370 | 2375 | try self.writeAtom(atom_index, code); |
| 2371 | 2376 | } |
| 2372 | 2377 | |
| ... | ... | @@ -2413,7 +2418,7 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 { |
| 2413 | 2418 | |
| 2414 | 2419 | if (val.castTag(.variable)) |variable| { |
| 2415 | 2420 | if (variable.data.is_threadlocal and !single_threaded) { |
| 2416 | | break :blk self.tls_data_section_index.?; |
| 2421 | break :blk self.thread_data_section_index.?; |
| 2417 | 2422 | } |
| 2418 | 2423 | break :blk self.data_section_index.?; |
| 2419 | 2424 | } |
| ... | ... | @@ -2501,7 +2506,6 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []u8) !u64 |
| 2501 | 2506 | try self.addGotEntry(.{ .sym_index = sym_index }); |
| 2502 | 2507 | } |
| 2503 | 2508 | |
| 2504 | | self.markRelocsDirtyByTarget(atom.getSymbolWithLoc()); |
| 2505 | 2509 | try self.writeAtom(atom_index, code); |
| 2506 | 2510 | |
| 2507 | 2511 | return atom.getSymbol(self).n_value; |
| ... | ... | @@ -2835,8 +2839,17 @@ fn populateMissingMetadata(self: *MachO) !void { |
| 2835 | 2839 | } |
| 2836 | 2840 | |
| 2837 | 2841 | if (!self.base.options.single_threaded) { |
| 2838 | | if (self.tls_vars_section_index == null) { |
| 2839 | | self.tls_vars_section_index = try self.allocateSection("__DATA2", "__thread_vars", .{ |
| 2842 | if (self.thread_ptr_section_index == null) { |
| 2843 | self.thread_ptr_section_index = try self.allocateSection("__DATA2", "__thread_ptrs", .{ |
| 2844 | .size = @sizeOf(u64), |
| 2845 | .alignment = @alignOf(u64), |
| 2846 | .flags = macho.S_THREAD_LOCAL_VARIABLE_POINTERS, |
| 2847 | .prot = macho.PROT.READ | macho.PROT.WRITE, |
| 2848 | }); |
| 2849 | self.segment_table_dirty = true; |
| 2850 | } |
| 2851 | if (self.thread_vars_section_index == null) { |
| 2852 | self.thread_vars_section_index = try self.allocateSection("__DATA3", "__thread_vars", .{ |
| 2840 | 2853 | .size = @sizeOf(u64) * 3, |
| 2841 | 2854 | .alignment = @alignOf(u64), |
| 2842 | 2855 | .flags = macho.S_THREAD_LOCAL_VARIABLES, |
| ... | ... | @@ -2845,8 +2858,8 @@ fn populateMissingMetadata(self: *MachO) !void { |
| 2845 | 2858 | self.segment_table_dirty = true; |
| 2846 | 2859 | } |
| 2847 | 2860 | |
| 2848 | | if (self.tls_data_section_index == null) { |
| 2849 | | self.tls_data_section_index = try self.allocateSection("__DATA3", "__thread_data", .{ |
| 2861 | if (self.thread_data_section_index == null) { |
| 2862 | self.thread_data_section_index = try self.allocateSection("__DATA4", "__thread_data", .{ |
| 2850 | 2863 | .size = @sizeOf(u64), |
| 2851 | 2864 | .alignment = @alignOf(u64), |
| 2852 | 2865 | .flags = macho.S_THREAD_LOCAL_REGULAR, |