diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-08-22 06:59:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-22 06:59:45 +0200 |
| commit | 7cd1c882c9dda18d333649462193e3e44e54196e (patch) | |
| tree | 595e68221ef57cbfd4c09a368cee25e5d2f8d0b3 /test | |
| parent | 5bf9dc3850117c85fb124cc481d4a284e2c8504d (diff) | |
| parent | fa79f53f92cf41f30a84f4e8f5f059e15060ae2b (diff) | |
| download | zig-7cd1c882c9dda18d333649462193e3e44e54196e.tar.gz zig-7cd1c882c9dda18d333649462193e3e44e54196e.zip | |
Merge pull request #21160 from ziglang/link-thunks-test
Diffstat (limited to 'test')
| -rw-r--r-- | test/link/elf.zig | 57 | ||||
| -rw-r--r-- | test/link/macho.zig | 27 |
2 files changed, 35 insertions, 49 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig index 5539638ba7..98253811b2 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -2973,44 +2973,27 @@ fn testStrip(b: *Build, opts: Options) *Step { fn testThunks(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "thunks", opts); - const src = - \\#include <stdio.h> - \\__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 exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = src }); - exe.link_function_sections = true; - exe.linkLibC(); - - const run = addRunArtifact(exe); - run.expectStdOutEqual("bar=42, foo=0, foobar=42"); - run.expectExitCode(0); - test_step.dependOn(&run.step); - } - - { - const exe = addExecutable(b, opts, .{ .name = "main2", .c_source_bytes = src }); - exe.linkLibC(); + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = + \\void foo(); + \\__attribute__((section(".bar"))) void bar() { + \\ return foo(); + \\} + \\__attribute__((section(".foo"))) void foo() { + \\ return bar(); + \\} + \\int main() { + \\ foo(); + \\ bar(); + \\ return 0; + \\} + }); - const run = addRunArtifact(exe); - run.expectStdOutEqual("bar=42, foo=0, foobar=42"); - run.expectExitCode(0); - test_step.dependOn(&run.step); - } + const check = exe.checkObject(); + check.checkInSymtab(); + check.checkContains("foo$thunk"); + check.checkInSymtab(); + check.checkContains("bar$thunk"); + test_step.dependOn(&check.step); return test_step; } diff --git a/test/link/macho.zig b/test/link/macho.zig index 30982e6ba2..730edcf3a9 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -2204,25 +2204,28 @@ fn testThunks(b: *Build, opts: Options) *Step { const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = \\#include <stdio.h> - \\__attribute__((aligned(0x8000000))) int bar() { - \\ return 42; + \\void bar() { + \\ printf("bar"); \\} - \\int foobar(); - \\int foo() { - \\ return bar() - foobar(); - \\} - \\__attribute__((aligned(0x8000000))) int foobar() { - \\ return 42; + \\void foo() { + \\ fprintf(stdout, "foo"); \\} \\int main() { - \\ printf("bar=%d, foo=%d, foobar=%d", bar(), foo(), foobar()); - \\ return foo(); + \\ foo(); + \\ bar(); + \\ return 0; \\} }); + const check = exe.checkObject(); + check.checkInSymtab(); + check.checkContains("_printf__thunk"); + check.checkInSymtab(); + check.checkContains("_fprintf__thunk"); + test_step.dependOn(&check.step); + const run = addRunArtifact(exe); - run.expectStdOutEqual("bar=42, foo=0, foobar=42"); - run.expectExitCode(0); + run.expectStdOutEqual("foobar"); test_step.dependOn(&run.step); return test_step; |
