aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 4156dd853b..e00141db97 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -912,11 +912,13 @@ fn lowerDeclRef(
/// * got - the value is referenced indirectly via GOT entry index (the linker emits a got-type reloc)
/// * direct - the value is referenced directly via symbol index index (the linker emits a displacement reloc)
/// * import - the value is referenced indirectly via import entry index (the linker emits an import-type reloc)
+/// * tlv - the value is a threadlocal variable referenced indirectly via GOT (the linker emits a got-type reloc)
pub const LinkerLoad = struct {
type: enum {
got,
direct,
import,
+ tlv,
},
sym_index: u32,
};
@@ -991,6 +993,8 @@ fn genDeclRef(
module.markDeclAlive(decl);
+ const is_threadlocal = tv.val.isPtrToThreadLocal(module) and !bin_file.options.single_threaded;
+
if (bin_file.cast(link.File.Elf)) |elf_file| {
const atom_index = try elf_file.getOrCreateAtomForDecl(decl_index);
const atom = elf_file.getAtom(atom_index);
@@ -999,7 +1003,7 @@ fn genDeclRef(
const atom_index = try macho_file.getOrCreateAtomForDecl(decl_index);
const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;
return GenResult.mcv(.{ .linker_load = .{
- .type = .got,
+ .type = if (is_threadlocal) .tlv else .got,
.sym_index = sym_index,
} });
} else if (bin_file.cast(link.File.Coff)) |coff_file| {