diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 680f19a245..b363ab91ed 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -979,7 +979,9 @@ fn updateDeclCode( sym.out_n_sect = sect_index; atom.out_n_sect = sect_index; - sym.name = try self.strtab.insert(gpa, decl.fqn.toSlice(ip)); + const sym_name = try std.fmt.allocPrintZ(gpa, "_{s}", .{decl.fqn.toSlice(ip)}); + defer gpa.free(sym_name); + sym.name = try self.strtab.insert(gpa, sym_name); atom.flags.alive = true; atom.name = sym.name; nlist.n_strx = sym.name; diff --git a/test/link/link.zig b/test/link/link.zig index a098da757d..aee3bbe01b 100644 --- a/test/link/link.zig +++ b/test/link/link.zig @@ -74,8 +74,9 @@ fn addCompileStep( .target = base.target, .optimize = base.optimize, .root_source_file = rsf: { + const name = b.fmt("{s}.zig", .{overlay.name}); const bytes = overlay.zig_source_bytes orelse break :rsf null; - break :rsf b.addWriteFiles().add("a.zig", bytes); + break :rsf b.addWriteFiles().add(name, bytes); }, .pic = overlay.pic, .strip = if (base.strip) |s| s else overlay.strip, diff --git a/test/link/macho.zig b/test/link/macho.zig index 7dd27c0467..6c047ee322 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -916,7 +916,7 @@ fn testLinksection(b: *Build, opts: Options) *Step { if (opts.optimize == .Debug) { check.checkInSymtab(); - check.checkContains("(__TEXT,__TestGenFnA) _a.testGenericFn__anon_"); + check.checkContains("(__TEXT,__TestGenFnA) _main.testGenericFn__anon_"); } test_step.dependOn(&check.step); @@ -2519,11 +2519,20 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { }); exe.addObject(obj); - expectLinkErrors(exe, test_step, .{ .exact = &.{ - "error: undefined symbol: _foo", - "note: referenced by /?/a.o:_bar", - "note: referenced by /?/main.o:_a.main", - } }); + // TODO order should match across backends if possible + if (opts.use_llvm) { + expectLinkErrors(exe, test_step, .{ .exact = &.{ + "error: undefined symbol: _foo", + "note: referenced by /?/a.o:_bar", + "note: referenced by /?/main.o:_main.main", + } }); + } else { + expectLinkErrors(exe, test_step, .{ .exact = &.{ + "error: undefined symbol: _foo", + "note: referenced by /?/main.o:_main.main", + "note: referenced by /?/a.o:__TEXT$__text_zig", + } }); + } return test_step; }