macho: fix section boundary symbols test

This commit is contained in:
Jakub Konka 2024-01-12 21:17:53 +01:00
parent ee7a027059
commit ee68f35bfe

View File

@ -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;