2 # Transform assembly in order to clean each stack frame for X86_64.
7 $SIG{__WARN__} = sub { die @_ };
9 # Whether we are still scanning the content of a function:
12 # Save lines of the function:
15 # Size of the stack for this function:
19 # Counter for assigning unique ids to labels:
23 my $qsize = $size / 8;
24 my $offset = - $size - 8;
27 # This is a crude hack to disable the stack cleaning on the main
28 # stack. It relies on the fact that the main stack is high in
29 # the address space and the other stacks are in the heap (lower).
30 print("\tmovq \$0x7fff00000000, %r11\n");
31 print("\tcmpq %r11, %rsp\n");
32 print("\tjae .Lstack_cleaner_done$id\n");
34 # Loop over the stack frame quadwords and zero it:
35 print("\tmovabsq \$$qsize, %r11\n");
36 print(".Lstack_cleaner_loop$id:\n");
37 print("\tmovq \$0, $offset(%rsp,%r11,8)\n");
38 print("\tsubq \$1, %r11\n");
39 print("\tjne .Lstack_cleaner_loop$id\n");
40 print(".Lstack_cleaner_done$id:\n");
54 if (m/^[ \t]*.cfi_endproc$/) {
56 } elsif (m/^[ \t]*pushq/) {
58 } elsif (m/^[ \t]*subq[\t *]\$([0-9]*),[ \t]*%rsp$/) {
60 $val = oct($val) if $val =~ /^0/;
64 } elsif (m/^[ \t]*.cfi_startproc$/) {