authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-21 23:05:28+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-21 23:05:28+02:00
logca417e1e32571b87b4a198a3f6faf1e63e7833b2
tree6fec0e3ebc4cd43cfddd69e9de8411e56c4c9457
parent8fc15f188c0deb1b0e2847297e535823eca1d2e8

link/elf: simplify how we test thunks


1 files changed, 20 insertions(+), 37 deletions(-)

test/link/elf.zig+20-37
......@@ -2973,44 +2973,27 @@ fn testStrip(b: *Build, opts: Options) *Step {
29732973fn testThunks(b: *Build, opts: Options) *Step {
29742974 const test_step = addTestStep(b, "thunks", opts);
29752975
2976 const src =
2977 \\#include <stdio.h>
2978 \\__attribute__((aligned(0x8000000))) int bar() {
2979 \\ return 42;
2980 \\}
2981 \\int foobar();
2982 \\int foo() {
2983 \\ return bar() - foobar();
2984 \\}
2985 \\__attribute__((aligned(0x8000000))) int foobar() {
2986 \\ return 42;
2987 \\}
2988 \\int main() {
2989 \\ printf("bar=%d, foo=%d, foobar=%d", bar(), foo(), foobar());
2990 \\ return foo();
2991 \\}
2992 ;
2993
2994 {
2995 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = src });
2996 exe.link_function_sections = true;
2997 exe.linkLibC();
2998
2999 const run = addRunArtifact(exe);
3000 run.expectStdOutEqual("bar=42, foo=0, foobar=42");
3001 run.expectExitCode(0);
3002 test_step.dependOn(&run.step);
3003 }
3004
3005 {
3006 const exe = addExecutable(b, opts, .{ .name = "main2", .c_source_bytes = src });
3007 exe.linkLibC();
2976 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2977 \\void foo();
2978 \\__attribute__((section(".bar"))) void bar() {
2979 \\ return foo();
2980 \\}
2981 \\__attribute__((section(".foo"))) void foo() {
2982 \\ return bar();
2983 \\}
2984 \\int main() {
2985 \\ foo();
2986 \\ bar();
2987 \\ return 0;
2988 \\}
2989 });
30082990
3009 const run = addRunArtifact(exe);
3010 run.expectStdOutEqual("bar=42, foo=0, foobar=42");
3011 run.expectExitCode(0);
3012 test_step.dependOn(&run.step);
3013 }
2991 const check = exe.checkObject();
2992 check.checkInSymtab();
2993 check.checkContains("foo$thunk");
2994 check.checkInSymtab();
2995 check.checkContains("bar$thunk");
2996 test_step.dependOn(&check.step);
30142997
30152998 return test_step;
30162999}