summaryrefslogtreecommitdiff
path: root/anim/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/build.zig')
-rw-r--r--anim/build.zig37
1 files changed, 28 insertions, 9 deletions
diff --git a/anim/build.zig b/anim/build.zig
index 21abbce..d12912d 100644
--- a/anim/build.zig
+++ b/anim/build.zig
@@ -16,7 +16,7 @@
const std = @import("std");
const sketchbook = @import("sketchbook");
-const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "zoom", "gallery" };
+const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "zoom", "heap", "gallery" };
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
@@ -74,23 +74,34 @@ pub fn build(b: *std.Build) void {
alloc: bool = false,
/// A file of tools/ it reads, by its bare name.
reads: ?[]const u8 = null,
- /// Bytes of stack above rsp each stop records. An instrumented
- /// program's runtime reads the clock through the vDSO, whose retry
- /// loop is stepped: with 512 or more the loop seldom gets through
- /// (`list` took 27 000 to 42 000 moments at 512, and 0.3 to 1.6
- /// million at 1024, against 3 900 at 256), so those take 256.
+ /// Bytes of stack above rsp each stop records. (A call into the
+ /// vDSO, the runtime's clock, is one moment: its retry loop is not stepped.)
stack: []const u8 = "1024",
+ /// Built by the system's clang against its glibc and linked
+ /// dynamically, as a C programmer's program is (a PLT, libc's own
+ /// code to follow down): `-no-pie` for short addresses, bound at
+ /// load (`-z now`: no resolver), with the canary the compiler puts in.
+ glibc: bool = false,
+ /// Stops after `from` before the recording ends: main's return, not the exit's.
+ steps: ?[]const u8 = null,
+ /// Also glibc's heap at every stop (`--heap`), and memory watched (`-w`).
+ heap: bool = false,
+ watch: []const []const u8 = &.{},
};
for ([_]Recording{
.{ .name = "steps", .source = "fib.c", .by = "insn" },
- .{ .name = "hello", .source = "hello.c", .by = "line", .reads = "note" },
+ // By instruction from main, through the PLT and libc's wrappers to
+ // the kernel and back: the descent; to main's return.
+ .{ .name = "hello", .source = "hello.c", .by = "insn", .from = "main", .steps = "132", .glibc = true, .reads = "note" },
+ // A line a stop, malloc and free run through; glibc's heap at each.
+ .{ .name = "heap", .source = "heap.c", .by = "line", .from = "main", .glibc = true, .heap = true, .watch = &.{ "0x405000,1024", "head" } },
// By instruction, as `steps` is: the registers are the program's
// own, so they strike and link. Only the variables the scenes name
// are told by the instrumentation (each a call into its runtime,
// stepped like any other); `list` starts at `reverse`, its pushes
// (the agent's and the runtime's first calls) run through.
- .{ .name = "sort", .source = "sort.c", .by = "insn", .instr = "vars", .only = "sort,a", .from = "main", .stack = "256" },
- .{ .name = "list", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "reverse", .alloc = true, .stack = "256" },
+ .{ .name = "sort", .source = "sort.c", .by = "insn", .instr = "vars", .only = "sort,a", .from = "main" },
+ .{ .name = "list", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "reverse", .alloc = true },
}) |r| {
const source = b.path(b.fmt("tools/{s}", .{r.source}));
var program: std.Build.LazyPath = undefined;
@@ -108,6 +119,11 @@ pub fn build(b: *std.Build) void {
cc.addFileArg(source);
cc.addArg("-o");
program = cc.addOutputFileArg(r.name);
+ } else if (r.glibc) {
+ const cc = b.addSystemCommand(&.{ "clang", "-O0", "-g", "-no-pie", "-fstack-protector-strong", "-Wl,-z,now" });
+ cc.addFileArg(source);
+ cc.addArg("-o");
+ program = cc.addOutputFileArg(r.name);
} else {
const mod = b.createModule(.{ .target = musl, .optimize = .Debug, .link_libc = true, .omit_frame_pointer = false, .sanitize_c = .off, .stack_protector = false });
mod.addCSourceFile(.{ .file = source, .flags = &.{ "-O0", "-g" } });
@@ -127,6 +143,9 @@ pub fn build(b: *std.Build) void {
// instructions round the pc.
run.addArgs(&.{ "record", "--by", r.by, "--stack", r.stack, "--around", "256", "--disasm", "69", "-s", "64" });
if (r.from) |place| run.addArgs(&.{ "--from", place });
+ if (r.steps) |n| run.addArgs(&.{ "--steps", n });
+ if (r.heap) run.addArg("--heap");
+ for (r.watch) |what| run.addArgs(&.{ "-w", what });
// What an instrumented program tells of itself comes through a ring.
if (r.instr != null) run.addArg("--ring");
if (r.alloc) {