authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-20 18:08:11+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:42+01:00
log55f57ceb2e8f900ba281c5cf5524718cf7eb332f
tree6325fb5bf745868ba77504a54bb0a5559208e518
parent5c30c23fc4d9f996244c11ff95104d86be88b4e4

macho: prep for lowering TLS variables


2 files changed, 23 insertions(+), 27 deletions(-)

src/codegen.zig+3-4
......@@ -996,10 +996,9 @@ fn genDeclRef(
996996 }
997997 const sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index);
998998 const sym = macho_file.getSymbol(sym_index);
999 // TODO: tlv
1000 // if (is_threadlocal) {
1001 // return GenResult.mcv(.{ .load_tlv = sym.nlist_idx });
1002 // }
999 if (is_threadlocal) {
1000 return GenResult.mcv(.{ .load_tlv = sym.nlist_idx });
1001 }
10031002 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });
10041003 } else if (lf.cast(link.File.Coff)) |coff_file| {
10051004 if (is_extern) {
src/link/MachO/ZigObject.zig+20-23
......@@ -724,26 +724,25 @@ fn getDeclOutputSection(
724724 _ = self;
725725 const mod = macho_file.base.comp.module.?;
726726 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
727 _ = any_non_single_threaded;
728727 const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) {
729728 .Fn => macho_file.zig_text_sect_index.?,
730729 else => blk: {
731730 if (decl.getOwnedVariable(mod)) |variable| {
732 // if (variable.is_threadlocal and any_non_single_threaded) {
733 // const is_all_zeroes = for (code) |byte| {
734 // if (byte != 0) break false;
735 // } else true;
736 // if (is_all_zeroes) break :blk macho_file.getSectionByName("__DATA", "__thread_bss") orelse try macho_file.addSection(
737 // "__DATA",
738 // "__thread_bss",
739 // .{ .flags = macho.S_THREAD_LOCAL_ZEROFILL },
740 // );
741 // break :blk macho_file.getSectionByName("__DATA", "__thread_data") orelse try macho_file.addSection(
742 // "__DATA",
743 // "__thread_data",
744 // .{ .flags = macho.S_THREAD_LOCAL_REGULAR },
745 // );
746 // }
731 if (variable.is_threadlocal and any_non_single_threaded) {
732 const is_all_zeroes = for (code) |byte| {
733 if (byte != 0) break false;
734 } else true;
735 if (is_all_zeroes) break :blk macho_file.getSectionByName("__DATA", "__thread_bss") orelse try macho_file.addSection(
736 "__DATA",
737 "__thread_bss",
738 .{ .flags = macho.S_THREAD_LOCAL_ZEROFILL },
739 );
740 break :blk macho_file.getSectionByName("__DATA", "__thread_data") orelse try macho_file.addSection(
741 "__DATA",
742 "__thread_data",
743 .{ .flags = macho.S_THREAD_LOCAL_REGULAR },
744 );
745 }
747746
748747 if (variable.is_const) break :blk macho_file.zig_const_sect_index.?;
749748 if (Value.fromInterned(variable.init).isUndefDeep(mod)) {
......@@ -1112,17 +1111,15 @@ pub fn getOrCreateMetadataForDecl(
11121111 const gop = try self.decls.getOrPut(gpa, decl_index);
11131112 if (!gop.found_existing) {
11141113 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
1115 _ = any_non_single_threaded;
11161114 const sym_index = try self.addAtom(macho_file);
11171115 const mod = macho_file.base.comp.module.?;
11181116 const decl = mod.declPtr(decl_index);
1119 _ = decl;
11201117 const sym = macho_file.getSymbol(sym_index);
1121 // if (decl.getOwnedVariable(mod)) |variable| {
1122 // if (variable.is_threadlocal and any_non_single_threaded) {
1123 // sym.flags.tlv = true;
1124 // }
1125 // }
1118 if (decl.getOwnedVariable(mod)) |variable| {
1119 if (variable.is_threadlocal and any_non_single_threaded) {
1120 sym.flags.tlv = true;
1121 }
1122 }
11261123 if (!sym.flags.tlv) {
11271124 sym.flags.needs_zig_got = true;
11281125 }