diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-01-20 18:08:11 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-01-24 12:34:42 +0100 |
| commit | 55f57ceb2e8f900ba281c5cf5524718cf7eb332f (patch) | |
| tree | 6325fb5bf745868ba77504a54bb0a5559208e518 | |
| parent | 5c30c23fc4d9f996244c11ff95104d86be88b4e4 (diff) | |
| download | zig-55f57ceb2e8f900ba281c5cf5524718cf7eb332f.tar.gz zig-55f57ceb2e8f900ba281c5cf5524718cf7eb332f.zip | |
macho: prep for lowering TLS variables
| -rw-r--r-- | src/codegen.zig | 7 | ||||
| -rw-r--r-- | src/link/MachO/ZigObject.zig | 43 |
2 files changed, 23 insertions, 27 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 49f7feda8f..e9509c4efd 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -996,10 +996,9 @@ fn genDeclRef( } const sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index); const sym = macho_file.getSymbol(sym_index); - // TODO: tlv - // if (is_threadlocal) { - // return GenResult.mcv(.{ .load_tlv = sym.nlist_idx }); - // } + if (is_threadlocal) { + return GenResult.mcv(.{ .load_tlv = sym.nlist_idx }); + } return GenResult.mcv(.{ .load_symbol = sym.nlist_idx }); } else if (lf.cast(link.File.Coff)) |coff_file| { if (is_extern) { diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 23673f2438..930d500e29 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -724,26 +724,25 @@ fn getDeclOutputSection( _ = self; const mod = macho_file.base.comp.module.?; const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; - _ = any_non_single_threaded; const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) { .Fn => macho_file.zig_text_sect_index.?, else => blk: { if (decl.getOwnedVariable(mod)) |variable| { - // if (variable.is_threadlocal and any_non_single_threaded) { - // const is_all_zeroes = for (code) |byte| { - // if (byte != 0) break false; - // } else true; - // if (is_all_zeroes) break :blk macho_file.getSectionByName("__DATA", "__thread_bss") orelse try macho_file.addSection( - // "__DATA", - // "__thread_bss", - // .{ .flags = macho.S_THREAD_LOCAL_ZEROFILL }, - // ); - // break :blk macho_file.getSectionByName("__DATA", "__thread_data") orelse try macho_file.addSection( - // "__DATA", - // "__thread_data", - // .{ .flags = macho.S_THREAD_LOCAL_REGULAR }, - // ); - // } + if (variable.is_threadlocal and any_non_single_threaded) { + const is_all_zeroes = for (code) |byte| { + if (byte != 0) break false; + } else true; + if (is_all_zeroes) break :blk macho_file.getSectionByName("__DATA", "__thread_bss") orelse try macho_file.addSection( + "__DATA", + "__thread_bss", + .{ .flags = macho.S_THREAD_LOCAL_ZEROFILL }, + ); + break :blk macho_file.getSectionByName("__DATA", "__thread_data") orelse try macho_file.addSection( + "__DATA", + "__thread_data", + .{ .flags = macho.S_THREAD_LOCAL_REGULAR }, + ); + } if (variable.is_const) break :blk macho_file.zig_const_sect_index.?; if (Value.fromInterned(variable.init).isUndefDeep(mod)) { @@ -1112,17 +1111,15 @@ pub fn getOrCreateMetadataForDecl( 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; - _ = any_non_single_threaded; const sym_index = try self.addAtom(macho_file); const mod = macho_file.base.comp.module.?; const decl = mod.declPtr(decl_index); - _ = decl; const sym = macho_file.getSymbol(sym_index); - // if (decl.getOwnedVariable(mod)) |variable| { - // if (variable.is_threadlocal and any_non_single_threaded) { - // sym.flags.tlv = true; - // } - // } + if (decl.getOwnedVariable(mod)) |variable| { + if (variable.is_threadlocal and any_non_single_threaded) { + sym.flags.tlv = true; + } + } if (!sym.flags.tlv) { sym.flags.needs_zig_got = true; } |
