Skip to content

Commit

Permalink
elf: test exports from executables
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jul 20, 2023
1 parent 7c64977 commit c3306c2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn addElfTests(b: *Build, opts: Options) *Step {
elf_step.dependOn(testEntryPoint(b, opts));
elf_step.dependOn(testExecStack(b, opts));
elf_step.dependOn(testExportDynamic(b, opts));
elf_step.dependOn(testExportSymbolsFromExe(b, opts));
elf_step.dependOn(testIfuncAlias(b, opts));
elf_step.dependOn(testIfuncDynamic(b, opts));
elf_step.dependOn(testIfuncFuncPtr(b, opts));
Expand Down Expand Up @@ -790,6 +791,46 @@ fn testExportDynamic(b: *Build, opts: Options) *Step {
return test_step;
}

fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step {
const test_step = b.step("test-elf-export-symbols-from-exe", "");

const dso = cc(b, opts);
dso.addCSource(
\\void expfn1();
\\void expfn2() {}
\\
\\void foo() {
\\ expfn1();
\\}
);
dso.addArgs(&.{ "-fPIC", "-shared" });
const dso_out = dso.saveOutputAs("a.so");

const exe = cc(b, opts);
exe.addCSource(
\\void expfn1() {}
\\void expfn2() {}
\\void foo();
\\
\\int main() {
\\ expfn1();
\\ expfn2();
\\ foo();
\\}
);
exe.addFileSource(dso_out.file);
exe.addPrefixedDirectorySource("-Wl,-rpath,", dso_out.dir);

const check = exe.check();
check.checkInDynamicSymtab();
check.checkContains("expfn2");
check.checkInDynamicSymtab();
check.checkContains("expfn1");
test_step.dependOn(&check.step);

return test_step;
}

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

Expand Down

0 comments on commit c3306c2

Please sign in to comment.