Skip to content

Commit

Permalink
elf: test exec stack flags for PT_GNU_STACK
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jul 20, 2023
1 parent 284d269 commit 2278687
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn addElfTests(b: *Build, opts: Options) *Step {
elf_step.dependOn(testDsoUndef(b, opts));
elf_step.dependOn(testEmptyObject(b, opts));
elf_step.dependOn(testEntryPoint(b, opts));
elf_step.dependOn(testExecStack(b, opts));
elf_step.dependOn(testIfuncAlias(b, opts));
elf_step.dependOn(testIfuncDynamic(b, opts));
elf_step.dependOn(testIfuncFuncPtr(b, opts));
Expand Down Expand Up @@ -469,6 +470,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step {

const check = exe.check();
check.checkStart();
check.checkExact("section headers");
check.checkExact("name .copyrel");
check.checkExact("addralign 20");
test_step.dependOn(&check.step);
Expand All @@ -487,6 +489,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step {

const check = exe.check();
check.checkStart();
check.checkExact("section headers");
check.checkExact("name .copyrel");
check.checkExact("addralign 8");
test_step.dependOn(&check.step);
Expand All @@ -505,6 +508,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step {

const check = exe.check();
check.checkStart();
check.checkExact("section headers");
check.checkExact("name .copyrel");
check.checkExact("addralign 100");
test_step.dependOn(&check.step);
Expand Down Expand Up @@ -695,6 +699,55 @@ fn testEntryPoint(b: *Build, opts: Options) *Step {
return test_step;
}

fn testExecStack(b: *Build, opts: Options) *Step {
const test_step = b.step("test-elf-exec-stack", "");

const obj = cc(b, opts);
obj.addEmptyMain();
obj.addArg("-c");
const obj_out = obj.saveOutputAs("a.o");

{
const exe = cc(b, opts);
exe.addFileSource(obj_out.file);
exe.addArg("-Wl,-z,execstack");

const check = exe.check();
check.checkStart();
check.checkExact("program headers");
check.checkExact("type GNU_STACK");
check.checkExact("flags RWE");
test_step.dependOn(&check.step);
}

{
const exe = cc(b, opts);
exe.addFileSource(obj_out.file);
exe.addArgs(&.{ "-Wl,-z,execstack", "-Wl,-z,noexecstack" });

const check = exe.check();
check.checkStart();
check.checkExact("program headers");
check.checkExact("type GNU_STACK");
check.checkExact("flags RW");
test_step.dependOn(&check.step);
}

{
const exe = cc(b, opts);
exe.addFileSource(obj_out.file);

const check = exe.check();
check.checkStart();
check.checkExact("program headers");
check.checkExact("type GNU_STACK");
check.checkExact("flags RW");
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 Expand Up @@ -887,8 +940,10 @@ fn testIfuncStaticPie(b: *Build, opts: Options) *Step {
check.checkExact("header");
check.checkExact("type DYN");
check.checkStart();
check.checkExact("section headers");
check.checkExact("name .dynamic");
check.checkStart();
check.checkExact("section headers");
check.checkNotPresent("name .interp");
test_step.dependOn(&check.step);

Expand Down Expand Up @@ -916,6 +971,7 @@ fn testHelloStatic(b: *Build, opts: Options) *Step {
check.checkExact("header");
check.checkExact("type EXEC");
check.checkStart();
check.checkExact("section headers");
check.checkNotPresent("name .dynamic");
test_step.dependOn(&check.step);

Expand All @@ -938,6 +994,7 @@ fn testHelloDynamic(b: *Build, opts: Options) *Step {
check.checkExact("header");
check.checkExact("type EXEC");
check.checkStart();
check.checkExact("section headers");
check.checkExact("name .dynamic");
test_step.dependOn(&check.step);

Expand All @@ -960,6 +1017,7 @@ fn testHelloPie(b: *Build, opts: Options) *Step {
check.checkExact("header");
check.checkExact("type DYN");
check.checkStart();
check.checkExact("section headers");
check.checkExact("name .dynamic");
test_step.dependOn(&check.step);

Expand Down

0 comments on commit 2278687

Please sign in to comment.