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:
18 # Counter for assigning unique ids to labels:
22 my $qsize = $size / 8;
23 my $offset = - $size - 8;
26 # This is a crude hack to disable the stack cleaning on the main
27 # stack. It relies on the fact that the main stack is high in
28 # the address space and the other stacks are in the heap (lower).
29 print("\tmovq \$0x7fff00000000, %r11\n");
30 print("\tcmpq %r11, %rsp\n");
31 print("\tjae .Lstack_cleaner_done$id\n");
33 # Loop over the stack frame quadwords and zero it:
34 print("\tmovabsq \$$qsize, %r11\n");
35 print(".Lstack_cleaner_loop$id:\n");
36 print("\tmovq \$0, $offset(%rsp,%r11,8)\n");
37 print("\tsubq \$1, %r11\n");
38 print("\tjne .Lstack_cleaner_loop$id\n");
39 print(".Lstack_cleaner_done$id:\n");
53 if (m/^[ \t]*.cfi_endproc$/) {
55 } elsif (m/^[ \t]*pushq/) {
57 } elsif (m/^[ \t]*subq[\t *]\$([0-9]*),[ \t]*%rsp$/) {
59 $val = oct($val) if $val =~ /^0/;
63 } elsif (m/^[ \t]*.cfi_startproc$/) {