From 0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 20:08:00 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- targets/stack.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 targets/stack.c (limited to 'targets') diff --git a/targets/stack.c b/targets/stack.c new file mode 100644 index 0000000..6ba2735 --- /dev/null +++ b/targets/stack.c @@ -0,0 +1,36 @@ +// What a stack's own instructions and the string instructions touch, by +// instruction: pushes and pops, calls and returns, enter and leave, the +// flags pushed; copies and fills, repeated, both ways. Built at -O0 with +// the stack protector: `fill` keeps a canary, and its i and n share a word. +#include + +char dst[64], src[64] = "abcdefghijklmnopqrstuvwxyz"; +// Past the file's last page: zeroes in a mapping of their own. +char big[1 << 16]; + +__attribute__((noinline)) static void strings(void) { + void *d = dst, *s = src; + uint64_t n = 3; + __asm__ volatile("rep movsq" : "+D"(d), "+S"(s), "+c"(n) : : "memory"); + d = dst + 40; + n = 5; + __asm__ volatile("rep stosb" : "+D"(d), "+c"(n) : "a"(0x41) : "memory"); + // Down from the last byte, the direction flag set. + d = dst + 63; + s = src + 25; + n = 4; + __asm__ volatile("std; rep movsb; cld" : "+D"(d), "+S"(s), "+c"(n) : : "memory"); + __asm__ volatile("pushfq; popfq; push %%rbx; pop %%rbx; enter $16, $0; leave" : : : "memory"); +} + +__attribute__((noinline)) static int fill(int n) { + char buf[16]; + for (int i = 0; i < n; i++) buf[i] = 'A' + i; + return buf[n - 1]; +} + +int main(void) { + strings(); + big[4096] = 1; + return fill(16) + big[4096] + dst[0] - 'P' - 1 - 'a'; +} -- cgit v1.3