authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-15 14:51:17+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
loge117e05768be08078a8484eaf982cfa5347a674e
tree5abf76c2a2bda4e964057f7f318a1117c7cbae82
parent91de8dc8abd9db03ba4ac4c4a5fcbe86e8bc7ee4

macho: ensure we always name decls like LLVM to avoid confusion


3 files changed, 20 insertions(+), 8 deletions(-)

src/link/MachO/ZigObject.zig+3-1
......@@ -979,7 +979,9 @@ fn updateDeclCode(
979979 sym.out_n_sect = sect_index;
980980 atom.out_n_sect = sect_index;
981981
982 sym.name = try self.strtab.insert(gpa, decl.fqn.toSlice(ip));
982 const sym_name = try std.fmt.allocPrintZ(gpa, "_{s}", .{decl.fqn.toSlice(ip)});
983 defer gpa.free(sym_name);
984 sym.name = try self.strtab.insert(gpa, sym_name);
983985 atom.flags.alive = true;
984986 atom.name = sym.name;
985987 nlist.n_strx = sym.name;
test/link/link.zig+2-1
......@@ -74,8 +74,9 @@ fn addCompileStep(
7474 .target = base.target,
7575 .optimize = base.optimize,
7676 .root_source_file = rsf: {
77 const name = b.fmt("{s}.zig", .{overlay.name});
7778 const bytes = overlay.zig_source_bytes orelse break :rsf null;
78 break :rsf b.addWriteFiles().add("a.zig", bytes);
79 break :rsf b.addWriteFiles().add(name, bytes);
7980 },
8081 .pic = overlay.pic,
8182 .strip = if (base.strip) |s| s else overlay.strip,
test/link/macho.zig+15-6
......@@ -916,7 +916,7 @@ fn testLinksection(b: *Build, opts: Options) *Step {
916916
917917 if (opts.optimize == .Debug) {
918918 check.checkInSymtab();
919 check.checkContains("(__TEXT,__TestGenFnA) _a.testGenericFn__anon_");
919 check.checkContains("(__TEXT,__TestGenFnA) _main.testGenericFn__anon_");
920920 }
921921
922922 test_step.dependOn(&check.step);
......@@ -2519,11 +2519,20 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step {
25192519 });
25202520 exe.addObject(obj);
25212521
2522 expectLinkErrors(exe, test_step, .{ .exact = &.{
2523 "error: undefined symbol: _foo",
2524 "note: referenced by /?/a.o:_bar",
2525 "note: referenced by /?/main.o:_a.main",
2526 } });
2522 // TODO order should match across backends if possible
2523 if (opts.use_llvm) {
2524 expectLinkErrors(exe, test_step, .{ .exact = &.{
2525 "error: undefined symbol: _foo",
2526 "note: referenced by /?/a.o:_bar",
2527 "note: referenced by /?/main.o:_main.main",
2528 } });
2529 } else {
2530 expectLinkErrors(exe, test_step, .{ .exact = &.{
2531 "error: undefined symbol: _foo",
2532 "note: referenced by /?/main.o:_main.main",
2533 "note: referenced by /?/a.o:__TEXT$__text_zig",
2534 } });
2535 }
25272536
25282537 return test_step;
25292538}