diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-07-15 22:33:09 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-07-18 09:13:08 +0200 |
| commit | a9e3088d9ce9edd61765e610e5d1a5ea8a5f6733 (patch) | |
| tree | ba949fb4a1d8a8e2401745e15821b8f34cf78d42 /src | |
| parent | 103c16c87955facd373bd20435100fa7eb322349 (diff) | |
| download | zig-a9e3088d9ce9edd61765e610e5d1a5ea8a5f6733.tar.gz zig-a9e3088d9ce9edd61765e610e5d1a5ea8a5f6733.zip | |
macho: extract testing logic for TLS into a helper
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO/ZigObject.zig | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index fdeec186e5..e75e8c9d19 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -958,14 +958,11 @@ pub fn updateDecl( return; }, }; - const sect_index = try self.getDeclOutputSection(macho_file, decl, code); - const is_threadlocal = switch (macho_file.sections.items(.header)[sect_index].type()) { - macho.S_THREAD_LOCAL_ZEROFILL, macho.S_THREAD_LOCAL_REGULAR => true, - else => false, - }; - if (is_threadlocal) { + if (isThreadlocal(macho_file, decl_index)) { + const sect_index = try self.getDeclOutputSection(macho_file, decl, code); try self.updateTlv(macho_file, pt, decl_index, sym_index, sect_index, code); } else { + const sect_index = try self.getDeclOutputSection(macho_file, decl, code); try self.updateDeclCode(macho_file, pt, decl_index, sym_index, sect_index, code); } @@ -1590,17 +1587,11 @@ pub fn getOrCreateMetadataForDecl( const gpa = macho_file.base.comp.gpa; const gop = try self.decls.getOrPut(gpa, decl_index); if (!gop.found_existing) { - const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; const sym_index = try self.newSymbolWithAtom(gpa, 0, macho_file); const sym = &self.symbols.items[sym_index]; - const mod = macho_file.base.comp.module.?; - const decl = mod.declPtr(decl_index); - if (decl.getOwnedVariable(mod)) |variable| { - if (variable.is_threadlocal and any_non_single_threaded) { - sym.flags.tlv = true; - } - } - if (!sym.flags.tlv) { + if (isThreadlocal(macho_file, decl_index)) { + sym.flags.tlv = true; + } else { sym.flags.needs_zig_got = true; } gop.value_ptr.* = .{ .symbol_index = sym_index }; @@ -1649,6 +1640,14 @@ pub fn getOrCreateMetadataForLazySymbol( return symbol_index; } +fn isThreadlocal(macho_file: *MachO, decl_index: InternPool.DeclIndex) bool { + const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; + const zcu = macho_file.base.comp.module.?; + const decl = zcu.declPtr(decl_index); + const variable = decl.getOwnedVariable(zcu) orelse return false; + return variable.is_threadlocal and any_non_single_threaded; +} + fn addAtom(self: *ZigObject, allocator: Allocator) !Atom.Index { try self.atoms.ensureUnusedCapacity(allocator, 1); try self.atoms_extra.ensureUnusedCapacity(allocator, 1); |
