| author | |
| committer | |
| log | b8490c05c10193363107a1fb2e7c4ffab287f5ad |
| tree | 00b05680a984e2dfad2f4f1bec815574763bd90f |
| parent | a2ad8517eea597eb9d7215aef831a86ffd16d1b3 |
4 files changed, 33 insertions(+), 1 deletions(-)
src/link/MachO/Dylib.zig+2-1| ... | ... | @@ -520,7 +520,6 @@ pub fn resolveSymbols(self: *Dylib, macho_file: *MachO) void { |
| 520 | 520 | global.nlist_idx = 0; |
| 521 | 521 | global.file = self.index; |
| 522 | 522 | global.flags.weak = flags.weak; |
| 523 | global.flags.weak_ref = false; | |
| 524 | 523 | global.flags.tlv = flags.tlv; |
| 525 | 524 | global.flags.dyn_ref = false; |
| 526 | 525 | global.flags.tentative = false; |
| ... | ... | @@ -534,9 +533,11 @@ pub fn resetGlobals(self: *Dylib, macho_file: *MachO) void { |
| 534 | 533 | const sym = macho_file.getSymbol(sym_index); |
| 535 | 534 | const name = sym.name; |
| 536 | 535 | const global = sym.flags.global; |
| 536 | const weak_ref = sym.flags.weak_ref; | |
| 537 | 537 | sym.* = .{}; |
| 538 | 538 | sym.name = name; |
| 539 | 539 | sym.flags.global = global; |
| 540 | sym.flags.weak_ref = weak_ref; | |
| 540 | 541 | } |
| 541 | 542 | } |
| 542 | 543 |
src/link/MachO/Object.zig+5| ... | ... | @@ -525,6 +525,9 @@ fn initSymbols(self: *Object, macho_file: *MachO) !void { |
| 525 | 525 | const off = try macho_file.strings.insert(gpa, name); |
| 526 | 526 | const gop = try macho_file.getOrCreateGlobal(off); |
| 527 | 527 | self.symbols.addOneAssumeCapacity().* = gop.index; |
| 528 | if (nlist.undf() and nlist.weakRef()) { | |
| 529 | macho_file.getSymbol(gop.index).flags.weak_ref = true; | |
| 530 | } | |
| 528 | 531 | continue; |
| 529 | 532 | } |
| 530 | 533 | |
| ... | ... | @@ -1099,9 +1102,11 @@ pub fn resetGlobals(self: *Object, macho_file: *MachO) void { |
| 1099 | 1102 | const sym = macho_file.getSymbol(sym_index); |
| 1100 | 1103 | const name = sym.name; |
| 1101 | 1104 | const global = sym.flags.global; |
| 1105 | const weak_ref = sym.flags.weak_ref; | |
| 1102 | 1106 | sym.* = .{}; |
| 1103 | 1107 | sym.name = name; |
| 1104 | 1108 | sym.flags.global = global; |
| 1109 | sym.flags.weak_ref = weak_ref; | |
| 1105 | 1110 | } |
| 1106 | 1111 | } |
| 1107 | 1112 |
src/link/MachO/ZigObject.zig+2| ... | ... | @@ -233,9 +233,11 @@ pub fn resetGlobals(self: *ZigObject, macho_file: *MachO) void { |
| 233 | 233 | const sym = macho_file.getSymbol(sym_index); |
| 234 | 234 | const name = sym.name; |
| 235 | 235 | const global = sym.flags.global; |
| 236 | const weak_ref = sym.flags.weak_ref; | |
| 236 | 237 | sym.* = .{}; |
| 237 | 238 | sym.name = name; |
| 238 | 239 | sym.flags.global = global; |
| 240 | sym.flags.weak_ref = weak_ref; | |
| 239 | 241 | } |
| 240 | 242 | } |
| 241 | 243 |
test/link/macho.zig+24| ... | ... | @@ -43,6 +43,11 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 43 | 43 | macho_step.dependOn(testUnwindInfoNoSubsectionsX64(b, .{ .target = x86_64_target })); |
| 44 | 44 | macho_step.dependOn(testUnwindInfoNoSubsectionsArm64(b, .{ .target = aarch64_target })); |
| 45 | 45 | macho_step.dependOn(testWeakBind(b, .{ .target = x86_64_target })); |
| 46 | macho_step.dependOn(testWeakRef(b, .{ .target = b.resolveTargetQuery(.{ | |
| 47 | .cpu_arch = .x86_64, | |
| 48 | .os_tag = .macos, | |
| 49 | .os_version_min = .{ .semver = .{ .major = 10, .minor = 13, .patch = 0 } }, | |
| 50 | }) })); | |
| 46 | 51 | |
| 47 | 52 | // Tests requiring symlinks when tested on Windows |
| 48 | 53 | if (build_opts.has_symlinks_windows) { |
| ... | ... | @@ -2223,6 +2228,25 @@ fn testWeakLibrary(b: *Build, opts: Options) *Step { |
| 2223 | 2228 | return test_step; |
| 2224 | 2229 | } |
| 2225 | 2230 | |
| 2231 | fn testWeakRef(b: *Build, opts: Options) *Step { | |
| 2232 | const test_step = addTestStep(b, "macho-weak-ref", opts); | |
| 2233 | ||
| 2234 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | |
| 2235 | \\#include <stdio.h> | |
| 2236 | \\#include <sys/_types/_fd_def.h> | |
| 2237 | \\int main(int argc, char** argv) { | |
| 2238 | \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow); | |
| 2239 | \\} | |
| 2240 | }); | |
| 2241 | ||
| 2242 | const check = exe.checkObject(); | |
| 2243 | check.checkInSymtab(); | |
| 2244 | check.checkExact("(undefined) weakref external ___darwin_check_fd_set_overflow (from libSystem.B)"); | |
| 2245 | test_step.dependOn(&check.step); | |
| 2246 | ||
| 2247 | return test_step; | |
| 2248 | } | |
| 2249 | ||
| 2226 | 2250 | fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { |
| 2227 | 2251 | return link.addTestStep(b, "macho-" ++ prefix, opts); |
| 2228 | 2252 | } |