summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/debugger.zig15
1 files changed, 14 insertions, 1 deletions
diff --git a/build/debugger.zig b/build/debugger.zig
index 47547e8..e50c82c 100644
--- a/build/debugger.zig
+++ b/build/debugger.zig
@@ -29,6 +29,10 @@ pub fn add(ctx: Ctx) void {
const overflow_mod = b.createModule(.{ .target = ctx.target, .optimize = .Debug, .link_libc = true, .omit_frame_pointer = false, .stack_protector = false });
overflow_mod.addCSourceFiles(.{ .root = b.path("targets"), .files = &.{"overflow.c"}, .flags = &.{ "-O0", "-g" } });
const overflow = b.addExecutable(.{ .name = "overflow", .root_module = overflow_mod });
+ // The stack's own instructions and the string ones; -O0 with a canary.
+ const stack_mod = b.createModule(.{ .target = ctx.target, .optimize = .Debug, .link_libc = true, .omit_frame_pointer = false, .stack_protector = true });
+ stack_mod.addCSourceFiles(.{ .root = b.path("targets"), .files = &.{"stack.c"}, .flags = &.{ "-O0", "-g" } });
+ const stack = b.addExecutable(.{ .name = "stack", .root_module = stack_mod });
// Zig, no libc: always a debug build, so its lines are the source's.
const graph = b.addExecutable(.{ .name = "graph", .root_module = b.createModule(.{
.root_source_file = b.path("targets/graph.zig"),
@@ -36,7 +40,7 @@ pub fn add(ctx: Ctx) void {
.optimize = .Debug,
}) });
- const targets = [_]*std.Build.Step.Compile{ fib, list, list_o0, hello, clock, overflow, threads, libc_glibc, libc_musl, graph };
+ const targets = [_]*std.Build.Step.Compile{ fib, list, list_o0, hello, clock, overflow, stack, threads, libc_glibc, libc_musl, graph };
for (targets) |t| b.getInstallStep().dependOn(&b.addInstallArtifact(t, .{ .dest_dir = .{ .override = .{ .custom = "targets" } } }).step);
// The compiler's own checks (UBSan, on by default in a debug build) are
@@ -105,6 +109,7 @@ pub fn add(ctx: Ctx) void {
paths.addOptionPath("fib_recording", recording);
// The overflow built with ASan by the system's compilers and recorded by the command, in the tests.
paths.addOptionPath("overflow_source", b.path("targets/overflow.c"));
+ paths.addOptionPath("stack_source", b.path("targets/stack.c"));
paths.addOptionPath("ztrace", ctx.exe.getEmittedBin());
// A call followed down by instruction: through the PLT, the loader's
@@ -125,6 +130,14 @@ pub fn add(ctx: Ctx) void {
loops.addArg("3");
loops.expectStdErrMatch("exit 0");
+ // The stack's own instructions, the string ones, a canary, by instruction from main to the end.
+ const stack_run = b.addRunArtifact(ctx.exe);
+ stack_run.addArgs(&.{ "record", "--by", "insn", "--from", "main", "-o" });
+ paths.addOptionPath("stack_recording", stack_run.addOutputFileArg("stack.ztrace"));
+ stack_run.addArg("--");
+ stack_run.addArtifactArg(stack);
+ stack_run.expectStdErrMatch("exit 0");
+
// Into libc by its PLT stub, syscalls not followed: the libraries'
// mappings are read when a name is wanted in them, and the callee's
// first instruction is named in the recording, its caller under it.