Skip to content

Commit

Permalink
elf: add ifunc func-ptr test
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jul 11, 2023
1 parent e3774d7 commit d461c91
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn addElfTests(b: *Build, opts: Options) *Step {
elf_step.dependOn(testDsoIfunc(b, opts));
elf_step.dependOn(testDsoPlt(b, opts));
elf_step.dependOn(testIfuncDynamic(b, opts));
elf_step.dependOn(testIfuncFuncPtr(b, opts));
elf_step.dependOn(testIfuncNoPlt(b, opts));
elf_step.dependOn(testIfuncStatic(b, opts));
elf_step.dependOn(testIfuncStaticPie(b, opts));
Expand Down Expand Up @@ -235,6 +236,41 @@ fn testIfuncDynamic(b: *Build, opts: Options) *Step {
return test_step;
}

fn testIfuncFuncPtr(b: *Build, opts: Options) *Step {
const test_step = b.step("test-elf-ifunc-func-ptr", "");

const exe = cc(b, null, opts);
exe.addSourceBytes(
\\typedef int Fn();
\\int foo() __attribute__((ifunc("resolve_foo")));
\\int real_foo() { return 3; }
\\Fn *resolve_foo(void) {
\\ return real_foo;
\\}
, "a.c");
exe.addSourceBytes(
\\typedef int Fn();
\\int foo();
\\Fn *get_foo() { return foo; }
, "b.c");
exe.addSourceBytes(
\\#include <stdio.h>
\\typedef int Fn();
\\Fn *get_foo();
\\int main() {
\\ Fn *f = get_foo();
\\ printf("%d\n", f());
\\}
, "c.c");
exe.addArg("-fPIC");

const run = exe.run();
run.expectStdOutEqual("3\n");
test_step.dependOn(run.step());

return test_step;
}

fn testIfuncNoPlt(b: *Build, opts: Options) *Step {
const test_step = b.step("test-elf-ifunc-noplt", "");

Expand Down

0 comments on commit d461c91

Please sign in to comment.