authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-12 21:17:53+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:39+01:00
logee68f35bfe742220f3fdebe97548425bb5440da1
tree60b115b6102cadb1e78952cb46e359cfe6ae45f7
parentee7a027059d87c10533744920793bca0bdec9687

macho: fix section boundary symbols test


1 files changed, 16 insertions(+), 11 deletions(-)

test/link/macho.zig+16-11
...@@ -4,15 +4,15 @@...@@ -4,15 +4,15 @@
4pub fn testAll(b: *std.Build) *Step {4pub fn testAll(b: *std.Build) *Step {
5 const macho_step = b.step("test-macho", "Run MachO tests");5 const macho_step = b.step("test-macho", "Run MachO tests");
66
7 macho_step.dependOn(testResolvingBoundarySymbols(b, .{7 macho_step.dependOn(testSectionBoundarySymbols(b, .{
8 .target = b.resolveTargetQuery(.{ .os_tag = .macos }),8 .target = b.resolveTargetQuery(.{ .os_tag = .macos }),
9 }));9 }));
1010
11 return macho_step;11 return macho_step;
12}12}
1313
14fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {14fn testSectionBoundarySymbols(b: *std.Build, opts: Options) *Step {
15 const test_step = addTestStep(b, "macho-resolving-boundary-symbols", opts);15 const test_step = addTestStep(b, "macho-section-boundary-symbols", opts);
1616
17 const obj1 = addObject(b, opts, .{17 const obj1 = addObject(b, opts, .{
18 .name = "obj1",18 .name = "obj1",
...@@ -25,10 +25,10 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {...@@ -25,10 +25,10 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {
25 .name = "main",25 .name = "main",
26 .zig_source_bytes =26 .zig_source_bytes =
27 \\const std = @import("std");27 \\const std = @import("std");
28 \\extern fn interop() [*:0]const u8;28 \\extern fn interop() ?[*:0]const u8;
29 \\pub fn main() !void {29 \\pub fn main() !void {
30 \\ std.debug.print("All your {s} are belong to us.\n", .{30 \\ std.debug.print("All your {s} are belong to us.\n", .{
31 \\ std.mem.span(interop()),31 \\ if (interop()) |ptr| std.mem.span(ptr) else "(null)",
32 \\ });32 \\ });
33 \\}33 \\}
34 ,34 ,
...@@ -57,7 +57,7 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {...@@ -57,7 +57,7 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {
5757
58 const check = exe.checkObject();58 const check = exe.checkObject();
59 check.checkInSymtab();59 check.checkInSymtab();
60 check.checkNotPresent("section$start$__DATA_CONST$__message_ptr");60 check.checkNotPresent("external section$start$__DATA_CONST$__message_ptr");
61 test_step.dependOn(&check.step);61 test_step.dependOn(&check.step);
62 }62 }
6363
...@@ -65,7 +65,7 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {...@@ -65,7 +65,7 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {
65 const obj3 = addObject(b, opts, .{65 const obj3 = addObject(b, opts, .{
66 .name = "obj3",66 .name = "obj3",
67 .cpp_source_bytes =67 .cpp_source_bytes =
68 \\extern const char* message_pointer __asm("section$start$__DATA$__message_ptr");68 \\extern const char* message_pointer __asm("section$start$__DATA_CONST$__not_present");
69 \\extern "C" const char* interop() {69 \\extern "C" const char* interop() {
70 \\ return message_pointer;70 \\ return message_pointer;
71 \\}71 \\}
...@@ -77,10 +77,15 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {...@@ -77,10 +77,15 @@ fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step {
77 exe.addObject(obj3);77 exe.addObject(obj3);
78 exe.addObject(main_o);78 exe.addObject(main_o);
7979
80 expectLinkErrors(exe, test_step, .{ .exact = &.{80 const run = b.addRunArtifact(exe);
81 "section not found: __DATA,__message_ptr",81 run.skip_foreign_checks = true;
82 "note: while resolving section$start$__DATA$__message_ptr",82 run.expectStdErrEqual("All your (null) are belong to us.\n");
83 } });83 test_step.dependOn(&run.step);
84
85 const check = exe.checkObject();
86 check.checkInSymtab();
87 check.checkNotPresent("external section$start$__DATA_CONST$__not_present");
88 test_step.dependOn(&check.step);
84 }89 }
8590
86 return test_step;91 return test_step;