| author | |
| committer | |
| log | 5c951cd21175c935215979f7599e8e340d86845b |
| tree | 42b70e111de0f1ec26603d6ea5d9f1ef4b8a7bd1 |
| parent | a8629fb8501275d826912085ccd120eb48a53199 |
5 files changed, 17 insertions(+), 10 deletions(-)
src/arch/x86_64/Emit.zig+3-2| ... | @@ -51,10 +51,11 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -51,10 +51,11 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 51 | } else if (emit.lower.bin_file.cast(link.File.MachO)) |macho_file| { | 51 | } else if (emit.lower.bin_file.cast(link.File.MachO)) |macho_file| { |
| 52 | // Add relocation to the decl. | 52 | // Add relocation to the decl. |
| 53 | const atom = macho_file.getSymbol(symbol.atom_index).getAtom(macho_file).?; | 53 | const atom = macho_file.getSymbol(symbol.atom_index).getAtom(macho_file).?; |
| 54 | const sym_index = macho_file.getZigObject().?.symbols.items[symbol.sym_index]; | ||
| 54 | try atom.addReloc(macho_file, .{ | 55 | try atom.addReloc(macho_file, .{ |
| 55 | .tag = .@"extern", | 56 | .tag = .@"extern", |
| 56 | .offset = end_offset - 4, | 57 | .offset = end_offset - 4, |
| 57 | .target = symbol.sym_index, | 58 | .target = sym_index, |
| 58 | .addend = 0, | 59 | .addend = 0, |
| 59 | .type = .branch, | 60 | .type = .branch, |
| 60 | .meta = .{ | 61 | .meta = .{ |
| ... | @@ -170,7 +171,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -170,7 +171,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 170 | try atom.addReloc(macho_file, .{ | 171 | try atom.addReloc(macho_file, .{ |
| 171 | .tag = .@"extern", | 172 | .tag = .@"extern", |
| 172 | .offset = @intCast(end_offset - 4), | 173 | .offset = @intCast(end_offset - 4), |
| 173 | .target = data.sym_index, | 174 | .target = sym_index, |
| 174 | .addend = 0, | 175 | .addend = 0, |
| 175 | .type = @"type", | 176 | .type = @"type", |
| 176 | .meta = .{ | 177 | .meta = .{ |
src/arch/x86_64/Lower.zig+2-1| ... | @@ -424,7 +424,8 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) | ... | @@ -424,7 +424,8 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) |
| 424 | else => unreachable, | 424 | else => unreachable, |
| 425 | }; | 425 | }; |
| 426 | } else if (lower.bin_file.cast(link.File.MachO)) |macho_file| { | 426 | } else if (lower.bin_file.cast(link.File.MachO)) |macho_file| { |
| 427 | const macho_sym = macho_file.getSymbol(sym.sym_index); | 427 | const sym_index = macho_file.getZigObject().?.symbols.items[sym.sym_index]; |
| 428 | const macho_sym = macho_file.getSymbol(sym_index); | ||
| 428 | 429 | ||
| 429 | if (macho_sym.flags.tlv) { | 430 | if (macho_sym.flags.tlv) { |
| 430 | @panic("TODO lower TLS access on macOS"); | 431 | @panic("TODO lower TLS access on macOS"); |
src/link/MachO.zig+2| ... | @@ -1617,6 +1617,8 @@ fn scanRelocs(self: *MachO) !void { | ... | @@ -1617,6 +1617,8 @@ fn scanRelocs(self: *MachO) !void { |
| 1617 | const tracy = trace(@src()); | 1617 | const tracy = trace(@src()); |
| 1618 | defer tracy.end(); | 1618 | defer tracy.end(); |
| 1619 | 1619 | ||
| 1620 | if (self.getZigObject()) |zo| try zo.scanRelocs(self); | ||
| 1621 | |||
| 1620 | for (self.objects.items) |index| { | 1622 | for (self.objects.items) |index| { |
| 1621 | try self.getFile(index).?.object.scanRelocs(self); | 1623 | try self.getFile(index).?.object.scanRelocs(self); |
| 1622 | } | 1624 | } |
src/link/MachO/ZigObject.zig+9-7| ... | @@ -346,7 +346,7 @@ pub fn getDeclVAddr( | ... | @@ -346,7 +346,7 @@ pub fn getDeclVAddr( |
| 346 | try parent_atom.addReloc(macho_file, .{ | 346 | try parent_atom.addReloc(macho_file, .{ |
| 347 | .tag = .@"extern", | 347 | .tag = .@"extern", |
| 348 | .offset = @intCast(reloc_info.offset), | 348 | .offset = @intCast(reloc_info.offset), |
| 349 | .target = sym.nlist_idx, | 349 | .target = sym_index, |
| 350 | .addend = reloc_info.addend, | 350 | .addend = reloc_info.addend, |
| 351 | .type = .unsigned, | 351 | .type = .unsigned, |
| 352 | .meta = .{ | 352 | .meta = .{ |
| ... | @@ -372,7 +372,7 @@ pub fn getAnonDeclVAddr( | ... | @@ -372,7 +372,7 @@ pub fn getAnonDeclVAddr( |
| 372 | try parent_atom.addReloc(macho_file, .{ | 372 | try parent_atom.addReloc(macho_file, .{ |
| 373 | .tag = .@"extern", | 373 | .tag = .@"extern", |
| 374 | .offset = @intCast(reloc_info.offset), | 374 | .offset = @intCast(reloc_info.offset), |
| 375 | .target = sym.nlist_idx, | 375 | .target = sym_index, |
| 376 | .addend = reloc_info.addend, | 376 | .addend = reloc_info.addend, |
| 377 | .type = .unsigned, | 377 | .type = .unsigned, |
| 378 | .meta = .{ | 378 | .meta = .{ |
| ... | @@ -1102,15 +1102,17 @@ pub fn getOrCreateMetadataForDecl( | ... | @@ -1102,15 +1102,17 @@ pub fn getOrCreateMetadataForDecl( |
| 1102 | const gop = try self.decls.getOrPut(gpa, decl_index); | 1102 | const gop = try self.decls.getOrPut(gpa, decl_index); |
| 1103 | if (!gop.found_existing) { | 1103 | if (!gop.found_existing) { |
| 1104 | const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; | 1104 | const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; |
| 1105 | _ = any_non_single_threaded; | ||
| 1105 | const sym_index = try self.addAtom(macho_file); | 1106 | const sym_index = try self.addAtom(macho_file); |
| 1106 | const mod = macho_file.base.comp.module.?; | 1107 | const mod = macho_file.base.comp.module.?; |
| 1107 | const decl = mod.declPtr(decl_index); | 1108 | const decl = mod.declPtr(decl_index); |
| 1109 | _ = decl; | ||
| 1108 | const sym = macho_file.getSymbol(sym_index); | 1110 | const sym = macho_file.getSymbol(sym_index); |
| 1109 | if (decl.getOwnedVariable(mod)) |variable| { | 1111 | // if (decl.getOwnedVariable(mod)) |variable| { |
| 1110 | if (variable.is_threadlocal and any_non_single_threaded) { | 1112 | // if (variable.is_threadlocal and any_non_single_threaded) { |
| 1111 | sym.flags.tlv = true; | 1113 | // sym.flags.tlv = true; |
| 1112 | } | 1114 | // } |
| 1113 | } | 1115 | // } |
| 1114 | if (!sym.flags.tlv) { | 1116 | if (!sym.flags.tlv) { |
| 1115 | sym.flags.needs_zig_got = true; | 1117 | sym.flags.needs_zig_got = true; |
| 1116 | } | 1118 | } |
src/link/MachO/synthetic.zig+1| ... | @@ -24,6 +24,7 @@ pub const ZigGotSection = struct { | ... | @@ -24,6 +24,7 @@ pub const ZigGotSection = struct { |
| 24 | const entry = &zig_got.entries.items[index]; | 24 | const entry = &zig_got.entries.items[index]; |
| 25 | entry.* = sym_index; | 25 | entry.* = sym_index; |
| 26 | const symbol = macho_file.getSymbol(sym_index); | 26 | const symbol = macho_file.getSymbol(sym_index); |
| 27 | assert(symbol.flags.needs_zig_got); | ||
| 27 | symbol.flags.has_zig_got = true; | 28 | symbol.flags.has_zig_got = true; |
| 28 | try symbol.addExtra(.{ .zig_got = index }, macho_file); | 29 | try symbol.addExtra(.{ .zig_got = index }, macho_file); |
| 29 | return index; | 30 | return index; |