diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-01-20 22:31:50 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-01-24 12:34:42 +0100 |
| commit | 5c4db4e5787eb534c8a83a6f7fc8f0fcfb1d01ef (patch) | |
| tree | cf4fe1055583f61d85d2b750d9d6c03a16b2e536 /src/link | |
| parent | 080ad94249101ed167c06761eebbaf1f5d47cfa9 (diff) | |
| download | zig-5c4db4e5787eb534c8a83a6f7fc8f0fcfb1d01ef.tar.gz zig-5c4db4e5787eb534c8a83a6f7fc8f0fcfb1d01ef.zip | |
x86_64: emit MachO TLV sequence
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/MachO/ZigObject.zig | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 976a3236ae..fc9ce86762 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -141,13 +141,23 @@ pub fn getAtomDataAlloc(self: ZigObject, macho_file: *MachO, atom: Atom) ![]u8 { const gpa = macho_file.base.comp.gpa; assert(atom.file == self.index); const sect = macho_file.sections.items(.header)[atom.out_n_sect]; - const file_offset = sect.offset + atom.value - sect.addr; - const size = std.math.cast(usize, atom.size) orelse return error.Overflow; - const code = try gpa.alloc(u8, size); - errdefer gpa.free(code); - const amt = try macho_file.base.file.?.preadAll(code, file_offset); - if (amt != code.len) return error.InputOutput; - return code; + + switch (sect.type()) { + macho.S_THREAD_LOCAL_REGULAR => { + const tlv = self.tls_variables.get(atom.atom_index).?; + const code = try gpa.dupe(u8, tlv.code); + return code; + }, + else => { + const file_offset = sect.offset + atom.value - sect.addr; + const size = std.math.cast(usize, atom.size) orelse return error.Overflow; + const code = try gpa.alloc(u8, size); + errdefer gpa.free(code); + const amt = try macho_file.base.file.?.preadAll(code, file_offset); + if (amt != code.len) return error.InputOutput; + return code; + }, + } } pub fn getAtomRelocs(self: *ZigObject, atom: Atom) []const Relocation { |
