3 # Check the stack usage of functions
5 # Copyright Joern Engel <joern@wh.fh-wedel.de>
6 # Inspired by Linus Torvalds
7 # Original idea maybe from Keith Owens
8 # s390 port and big speedup by Arnd Bergmann <arnd@bergmann-dalldorf.de>
9 # Mips port by Juan Quintela <quintela@mandrakesoft.com>
10 # IA64 port via Andreas Dilger
11 # Arm port by Holger Schurig
12 # Random bits by Matt Mackall <mpm@selenic.com>
15 # objdump -d vmlinux | stackcheck_ppc.pl [arch]
17 # TODO : Port to all architectures (one regex per arch)
21 # $re is used for two matches:
22 # $& (whole re) matches the complete objdump line with the stack growth
23 # $1 (first bracket) matches the size of the stack growth
25 # use anything else and feel the pain ;)
26 my (@stack, $re, $x, $xs);
33 $x = "[0-9a-f]"; # hex character
34 $xs = "[0-9a-f ]"; # hex character or space
36 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
37 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
38 } elsif ($arch =~ /^i[3456]86$/) {
39 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
40 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
41 } elsif ($arch eq 'ia64') {
42 #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
43 $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
44 } elsif ($arch eq 'mips64') {
45 #8800402c: 67bdfff0 daddiu sp,sp,-16
46 $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
47 } elsif ($arch eq 'mips') {
48 #88003254: 27bdffe0 addiu sp,sp,-32
49 $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
50 } elsif ($arch eq 'ppc') {
51 #c00029f4: 94 21 ff 30 stwu r1,-208(r1)
52 $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o;
53 } elsif ($arch eq 'ppc64') {
55 $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o;
56 } elsif ($arch =~ /^s390x?$/) {
57 # 11160: a7 fb ff 60 aghi %r15,-160
58 $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o;
60 print("wrong or unknown architecture\n");
67 ($asize = $a) =~ s/.* +(.*)$/$1/;
68 ($bsize = $b) =~ s/.* +(.*)$/$1/;
75 my $funcre = qr/^$x* <(.*)>:$/;
77 while (my $line = <STDIN>) {
78 if ($line =~ m/$funcre/) {
81 if ($line =~ m/$re/) {
83 $size = hex($size) if ($size =~ /^0x/);
85 if ($size > 0x80000000) {
91 next if $line !~ m/^($xs*)/;
96 my $intro = "$addr $func:";
97 my $padlen = 56 - length($intro);
102 next if ($size < 100);
103 push @stack, "$intro$size\n";
107 print sort bysize @stack;