summaryrefslogtreecommitdiff
path: root/anim/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/build.zig')
-rw-r--r--anim/build.zig43
1 files changed, 42 insertions, 1 deletions
diff --git a/anim/build.zig b/anim/build.zig
index 6351250..9c7d63e 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", "musl", "zoom", "heap", "gallery", "column", "column_sort" };
+const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "musl", "zoom", "heap", "gallery", "column", "column_sort", "intro_memory", "intro_stack", "intro_code", "asan" };
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
@@ -222,6 +222,47 @@ pub fn build(b: *std.Build) void {
source_modules.append(b.allocator, .{ .name = b.fmt("{s}-sources", .{r.name}), .module = sources }) catch @panic("OOM");
table.print(b.allocator, "pub const {s}: Program = .{{ .trace = @embedFile(\"{s}\"), .file = \"{s}\", .source = @embedFile(\"{s}\"), .sources = &@import(\"{s}-sources\").list }};\n", .{ r.name, file, r.source, r.source, r.name }) catch @panic("OOM");
}
+ // The pair (`asan`, design/motion.md "A scene: ASan against a plain
+ // build"): overflow.c built twice by the system's clang, plain and with
+ // AddressSanitizer, frame pointers kept and no canary (Arch's clang puts
+ // one in by default, and the plain run would die in `__stack_chk_fail`,
+ // not at `ret`). Each run as `./overflow` in a directory of its own, with
+ // no environment but ASan's leak check off (it fails under a tracer):
+ // plain by instruction from main to its fault at `ret` (the recorder
+ // says `exit 139`, SIGSEGV); ASan by instruction from main to the first
+ // instruction of `__asan_report_store1` (582 stops: the report itself is
+ // a million more), and the same run again by syscall alone, for the
+ // report's `write`s to fd 2 as written.
+ for ([_]struct { name: []const u8, asan: bool, args: []const []const u8, exit: []const u8 }{
+ .{ .name = "overflow", .asan = false, .args = &.{ "--by", "insn", "--stack", "1024", "--around", "256", "--disasm", "69", "-s", "64", "--from", "main" }, .exit = "exit 139" },
+ .{ .name = "overflow_asan", .asan = true, .args = &.{ "--asan", "--by", "insn", "--stack", "1024", "--around", "256", "--disasm", "69", "-s", "64", "--from", "main", "--steps", "582" }, .exit = "exit 0" },
+ .{ .name = "overflow_report", .asan = true, .args = &.{ "--by", "syscall", "--stack", "0", "--telescope", "0", "-s", "4096" }, .exit = "exit 1" },
+ }) |r| {
+ const cc = b.addSystemCommand(&.{ "clang", "-O0", "-g", "-fno-omit-frame-pointer", "-no-pie", "-fno-stack-protector" });
+ if (r.asan) cc.addArg("-fsanitize=address");
+ cc.addFileArg(b.path("tools/overflow.c"));
+ cc.addArg("-o");
+ const program = cc.addOutputFileArg("overflow");
+ const where = b.addWriteFiles();
+ _ = where.addCopyFile(program, "overflow");
+ const link = "ln -sfn \"" ++ debuginfod_cache ++ "\" debuginfod && exec env -i DEBUGINFOD_CACHE_PATH=debuginfod ";
+ const run = b.addSystemCommand(&.{ "sh", "-c", if (r.asan) link ++ "ASAN_OPTIONS=detect_leaks=0 setarch -R \"$0\" \"$@\"" else link ++ "setarch -R \"$0\" \"$@\"" });
+ run.addArtifactArg(ztrace);
+ run.addArg("record");
+ run.addArgs(r.args);
+ run.addArg("-o");
+ const trace = run.addOutputFileArg(b.fmt("{s}.ztrace", .{r.name}));
+ run.addArgs(&.{ "--", "./overflow" });
+ run.setCwd(where.getDirectory());
+ run.expectExitCode(0);
+ run.expectStdErrMatch(r.exit);
+ const file = b.fmt("{s}.ztrace", .{r.name});
+ record_step.dependOn(&b.addInstallFile(trace, b.fmt("recordings/{s}", .{file})).step);
+ _ = embedded.addCopyFile(trace, file);
+ table.print(b.allocator, "pub const {s}: Program = .{{ .trace = @embedFile(\"{s}\"), .file = \"overflow.c\", .source = @embedFile(\"overflow.c\") }};\n", .{ r.name, file }) catch @panic("OOM");
+ }
+ _ = embedded.addCopyFile(b.path("tools/overflow.c"), "overflow.c");
+
// SQLite, the next rung: its amalgamation is not ours to copy, so the
// scene is made only where it is. Built as the bench builds it (-O2,
// frame pointers kept), and as the instrumented ones are (no PIE, bound