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(...@@ -996,10 +996,9 @@ fn genDeclRef(
996 }996 }
997 const sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index);997 const sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index);
998 const sym = macho_file.getSymbol(sym_index);998 const sym = macho_file.getSymbol(sym_index);
999 // TODO: tlv999 if (is_threadlocal) {
1000 // if (is_threadlocal) {1000 return GenResult.mcv(.{ .load_tlv = sym.nlist_idx });
1001 // return GenResult.mcv(.{ .load_tlv = sym.nlist_idx });1001 }
1002 // }
1003 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });1002 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });
1004 } else if (lf.cast(link.File.Coff)) |coff_file| {1003 } else if (lf.cast(link.File.Coff)) |coff_file| {
1005 if (is_extern) {1004 if (is_extern) {
src/link/MachO/ZigObject.zig+20-23
...@@ -724,26 +724,25 @@ fn getDeclOutputSection(...@@ -724,26 +724,25 @@ fn getDeclOutputSection(
724 _ = self;724 _ = self;
725 const mod = macho_file.base.comp.module.?;725 const mod = macho_file.base.comp.module.?;
726 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;726 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
727 _ = any_non_single_threaded;
728 const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) {727 const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) {
729 .Fn => macho_file.zig_text_sect_index.?,728 .Fn => macho_file.zig_text_sect_index.?,
730 else => blk: {729 else => blk: {
731 if (decl.getOwnedVariable(mod)) |variable| {730 if (decl.getOwnedVariable(mod)) |variable| {
732 // if (variable.is_threadlocal and any_non_single_threaded) {731 if (variable.is_threadlocal and any_non_single_threaded) {
733 // const is_all_zeroes = for (code) |byte| {732 const is_all_zeroes = for (code) |byte| {
734 // if (byte != 0) break false;733 if (byte != 0) break false;
735 // } else true;734 } else true;
736 // if (is_all_zeroes) break :blk macho_file.getSectionByName("__DATA", "__thread_bss") orelse try macho_file.addSection(735 if (is_all_zeroes) break :blk macho_file.getSectionByName("__DATA", "__thread_bss") orelse try macho_file.addSection(
737 // "__DATA",736 "__DATA",
738 // "__thread_bss",737 "__thread_bss",
739 // .{ .flags = macho.S_THREAD_LOCAL_ZEROFILL },738 .{ .flags = macho.S_THREAD_LOCAL_ZEROFILL },
740 // );739 );
741 // break :blk macho_file.getSectionByName("__DATA", "__thread_data") orelse try macho_file.addSection(740 break :blk macho_file.getSectionByName("__DATA", "__thread_data") orelse try macho_file.addSection(
742 // "__DATA",741 "__DATA",
743 // "__thread_data",742 "__thread_data",
744 // .{ .flags = macho.S_THREAD_LOCAL_REGULAR },743 .{ .flags = macho.S_THREAD_LOCAL_REGULAR },
745 // );744 );
746 // }745 }
747746
748 if (variable.is_const) break :blk macho_file.zig_const_sect_index.?;747 if (variable.is_const) break :blk macho_file.zig_const_sect_index.?;
749 if (Value.fromInterned(variable.init).isUndefDeep(mod)) {748 if (Value.fromInterned(variable.init).isUndefDeep(mod)) {
...@@ -1112,17 +1111,15 @@ pub fn getOrCreateMetadataForDecl(...@@ -1112,17 +1111,15 @@ pub fn getOrCreateMetadataForDecl(
1112 const gop = try self.decls.getOrPut(gpa, decl_index);1111 const gop = try self.decls.getOrPut(gpa, decl_index);
1113 if (!gop.found_existing) {1112 if (!gop.found_existing) {
1114 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;1113 const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
1115 _ = any_non_single_threaded;
1116 const sym_index = try self.addAtom(macho_file);1114 const sym_index = try self.addAtom(macho_file);
1117 const mod = macho_file.base.comp.module.?;1115 const mod = macho_file.base.comp.module.?;
1118 const decl = mod.declPtr(decl_index);1116 const decl = mod.declPtr(decl_index);
1119 _ = decl;
1120 const sym = macho_file.getSymbol(sym_index);1117 const sym = macho_file.getSymbol(sym_index);
1121 // if (decl.getOwnedVariable(mod)) |variable| {1118 if (decl.getOwnedVariable(mod)) |variable| {
1122 // if (variable.is_threadlocal and any_non_single_threaded) {1119 if (variable.is_threadlocal and any_non_single_threaded) {
1123 // sym.flags.tlv = true;1120 sym.flags.tlv = true;
1124 // }1121 }
1125 // }1122 }
1126 if (!sym.flags.tlv) {1123 if (!sym.flags.tlv) {
1127 sym.flags.needs_zig_got = true;1124 sym.flags.needs_zig_got = true;
1128 }1125 }