From b426a8a99bcad81ecbb41d1f2a2e83738c29d8e1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:32:21 -0300 Subject: llvm: a pass that instruments for animation, its runtime, ztrace cc llvm/pass.cpp is an LLVM pass plugin: lines, stores, loads, calls and variables, each call into the runtime carrying names and type descriptions, selected by globs (-ztrace-only, -ztrace-mem), before the optimizer by default. src/instr/rt.zig is the runtime (libztrace-rt.a), which also answers clang's own coverage and -finstrument-functions hooks; src/instr/types.zig the grammar of the type descriptions and its parser. ztrace cc adds all of it to a compiler command. test-llvm compiles fib, two sorts, a linked list and a BFS through ztrace cc and asserts on their recordings; bench-llvm measures what each selection costs. Co-Authored-By: Claude Fable 5.2 --- targets/instr_own.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 targets/instr_own.c (limited to 'targets/instr_own.c') diff --git a/targets/instr_own.c b/targets/instr_own.c new file mode 100644 index 0000000..5c30141 --- /dev/null +++ b/targets/instr_own.c @@ -0,0 +1,27 @@ +// A program with its own memcpy and strlen, as one linked with a libc +// compiled by the pass has: the runtime calls them too, and must not trace +// itself. Exits with the length of the string it copied. +#include + +void *memcpy(void *to, const void *from, size_t n) { + char *d = to; + const char *s = from; + for (size_t i = 0; i < n; i++) d[i] = s[i]; + return to; +} + +size_t strlen(const char *s) { + size_t n = 0; + while (s[n]) n++; + return n; +} + +// Through pointers: the compiler would do a known memcpy inline. +void *(*volatile copy)(void *, const void *, size_t) = memcpy; +size_t (*volatile length)(const char *) = strlen; + +int main(void) { + char to[8], from[8] = "abcdefg"; + copy(to, from, sizeof from); + return (int)length(to); +} -- cgit v1.3