diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 20:08:00 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 20:08:07 -0300 |
| commit | 0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594 (patch) | |
| tree | bb820b7e39994177b6abc503ab5b980603d34513 /build | |
| parent | cc2059e39047cafe1886dc17084855ddd0c52b01 (diff) | |
| download | computeranim-0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594.tar.gz computeranim-0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594.zip | |
trace: what push, call and ret touch; names for data; the stack's roles, sharper
For a disassembly that points at the stack word it touched. The stack's
own instructions have touches (push, call and enter write at rsp-8; pop
and ret read at rsp; leave at rbp), and a rep string instruction its
whole range. An address a global or static object holds is named
(head+0, libc.so.6!main_arena+96). The saved rbp has its role at the
push that makes it; every local in a shared word is given; the stack
protector's copy is found by seeing its store; ztrace show labels each
stack word. Six bytes a moment and 3% slower on the list by instruction.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'build')
| -rw-r--r-- | build/debugger.zig | 15 |
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. |
