From 9f0e1ab467a2214efb97d340c733fa1da4e708c7 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 14 Jan 2024 10:59:47 +0100 Subject: [PATCH] test/link/macho: test thunks on arm64 --- test/link/macho.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/link/macho.zig b/test/link/macho.zig index ff02bee33d..10cc38d374 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -11,6 +11,10 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { .cpu_arch = .x86_64, .os_tag = .macos, }); + const aarch64_target = b.resolveTargetQuery(.{ + .cpu_arch = .aarch64, + .os_tag = .macos, + }); macho_step.dependOn(testDeadStrip(b, .{ .target = default_target })); macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); @@ -21,6 +25,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target })); macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); + macho_step.dependOn(testThunks(b, .{ .target = aarch64_target })); macho_step.dependOn(testTlsLargeTbss(b, .{ .target = default_target })); macho_step.dependOn(testUndefinedFlag(b, .{ .target = default_target })); macho_step.dependOn(testWeakBind(b, .{ .target = x86_64_target })); @@ -639,6 +644,35 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { return test_step; } +fn testThunks(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-thunks", opts); + + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = + \\#include + \\__attribute__((aligned(0x8000000))) int bar() { + \\ return 42; + \\} + \\int foobar(); + \\int foo() { + \\ return bar() - foobar(); + \\} + \\__attribute__((aligned(0x8000000))) int foobar() { + \\ return 42; + \\} + \\int main() { + \\ printf("bar=%d, foo=%d, foobar=%d", bar(), foo(), foobar()); + \\ return foo(); + \\} + }); + + const run = addRunArtifact(exe); + run.expectStdOutEqual("bar=42, foo=0, foobar=42"); + run.expectExitCode(0); + test_step.dependOn(&run.step); + + return test_step; +} + fn testTlsLargeTbss(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "macho-tls-large-tbss", opts);