From ee68f35bfe742220f3fdebe97548425bb5440da1 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 12 Jan 2024 21:17:53 +0100 Subject: [PATCH] macho: fix section boundary symbols test --- test/link/macho.zig | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/test/link/macho.zig b/test/link/macho.zig index 8a5016f9b7..fc40ebec33 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -4,15 +4,15 @@ pub fn testAll(b: *std.Build) *Step { const macho_step = b.step("test-macho", "Run MachO tests"); - macho_step.dependOn(testResolvingBoundarySymbols(b, .{ + macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = b.resolveTargetQuery(.{ .os_tag = .macos }), })); return macho_step; } -fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { - const test_step = addTestStep(b, "macho-resolving-boundary-symbols", opts); +fn testSectionBoundarySymbols(b: *std.Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-section-boundary-symbols", opts); const obj1 = addObject(b, opts, .{ .name = "obj1", @@ -25,10 +25,10 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { .name = "main", .zig_source_bytes = \\const std = @import("std"); - \\extern fn interop() [*:0]const u8; + \\extern fn interop() ?[*:0]const u8; \\pub fn main() !void { \\ std.debug.print("All your {s} are belong to us.\n", .{ - \\ std.mem.span(interop()), + \\ if (interop()) |ptr| std.mem.span(ptr) else "(null)", \\ }); \\} , @@ -57,7 +57,7 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { const check = exe.checkObject(); check.checkInSymtab(); - check.checkNotPresent("section$start$__DATA_CONST$__message_ptr"); + check.checkNotPresent("external section$start$__DATA_CONST$__message_ptr"); test_step.dependOn(&check.step); } @@ -65,7 +65,7 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { const obj3 = addObject(b, opts, .{ .name = "obj3", .cpp_source_bytes = - \\extern const char* message_pointer __asm("section$start$__DATA$__message_ptr"); + \\extern const char* message_pointer __asm("section$start$__DATA_CONST$__not_present"); \\extern "C" const char* interop() { \\ return message_pointer; \\} @@ -77,10 +77,15 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { exe.addObject(obj3); exe.addObject(main_o); - expectLinkErrors(exe, test_step, .{ .exact = &.{ - "section not found: __DATA,__message_ptr", - "note: while resolving section$start$__DATA$__message_ptr", - } }); + const run = b.addRunArtifact(exe); + run.skip_foreign_checks = true; + run.expectStdErrEqual("All your (null) are belong to us.\n"); + test_step.dependOn(&run.step); + + const check = exe.checkObject(); + check.checkInSymtab(); + check.checkNotPresent("external section$start$__DATA_CONST$__not_present"); + test_step.dependOn(&check.step); } return test_step;