authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-15 22:33:09+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
loga9e3088d9ce9edd61765e610e5d1a5ea8a5f6733
treeba949fb4a1d8a8e2401745e15821b8f34cf78d42
parent103c16c87955facd373bd20435100fa7eb322349

macho: extract testing logic for TLS into a helper


1 files changed, 14 insertions(+), 15 deletions(-)

src/link/MachO/ZigObject.zig+14-15
......@@ -958,14 +958,11 @@ pub fn updateDecl(
958958 return;
959959 },
960960 };
961 const sect_index = try self.getDeclOutputSection(macho_file, decl, code);
962 const is_threadlocal = switch (macho_file.sections.items(.header)[sect_index].type()) {
963 macho.S_THREAD_LOCAL_ZEROFILL, macho.S_THREAD_LOCAL_REGULAR => true,
964 else => false,
965 };
966 if (is_threadlocal) {
961 if (isThreadlocal(macho_file, decl_index)) {
962 const sect_index = try self.getDeclOutputSection(macho_file, decl, code);
967963 try self.updateTlv(macho_file, pt, decl_index, sym_index, sect_index, code);
968964 } else {
965 const sect_index = try self.getDeclOutputSection(macho_file, decl, code);
969966 try self.updateDeclCode(macho_file, pt, decl_index, sym_index, sect_index, code);
970967 }
971968
......@@ -1590,17 +1587,11 @@ pub fn getOrCreateMetadataForDecl(
15901587 const gpa = macho_file.base.comp.gpa;
15911588 const gop = try self.decls.getOrPut(gpa, decl_index);
15921589 if (!gop.found_existing) {
1593 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
15941590 const sym_index = try self.newSymbolWithAtom(gpa, 0, macho_file);
15951591 const sym = &self.symbols.items[sym_index];
1596 const mod = macho_file.base.comp.module.?;
1597 const decl = mod.declPtr(decl_index);
1598 if (decl.getOwnedVariable(mod)) |variable| {
1599 if (variable.is_threadlocal and any_non_single_threaded) {
1600 sym.flags.tlv = true;
1601 }
1602 }
1603 if (!sym.flags.tlv) {
1592 if (isThreadlocal(macho_file, decl_index)) {
1593 sym.flags.tlv = true;
1594 } else {
16041595 sym.flags.needs_zig_got = true;
16051596 }
16061597 gop.value_ptr.* = .{ .symbol_index = sym_index };
......@@ -1649,6 +1640,14 @@ pub fn getOrCreateMetadataForLazySymbol(
16491640 return symbol_index;
16501641}
16511642
1643fn isThreadlocal(macho_file: *MachO, decl_index: InternPool.DeclIndex) bool {
1644 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
1645 const zcu = macho_file.base.comp.module.?;
1646 const decl = zcu.declPtr(decl_index);
1647 const variable = decl.getOwnedVariable(zcu) orelse return false;
1648 return variable.is_threadlocal and any_non_single_threaded;
1649}
1650
16521651fn addAtom(self: *ZigObject, allocator: Allocator) !Atom.Index {
16531652 try self.atoms.ensureUnusedCapacity(allocator, 1);
16541653 try self.atoms_extra.ensureUnusedCapacity(allocator, 1);