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 ;)
32 $x = "[0-9a-f]"; # hex character
33 $xs = "[0-9a-f ]"; # hex character or space
34 if ($arch =~ /^arm$/) {
35 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
36 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
37 } elsif ($arch =~ /^i[3456]86$/) {
38 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
39 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
40 } elsif ($arch =~ /^ia64$/) {
41 #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
42 $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
43 } elsif ($arch =~ /^mips64$/) {
44 #8800402c: 67bdfff0 daddiu sp,sp,-16
45 $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
46 } elsif ($arch =~ /^mips$/) {
47 #88003254: 27bdffe0 addiu sp,sp,-32
48 $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
49 } elsif ($arch =~ /^ppc$/) {
50 #c00029f4: 94 21 ff 30 stwu r1,-208(r1)
51 $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o;
52 } elsif ($arch =~ /^ppc64$/) {
54 $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o;
55 } elsif ($arch =~ /^s390x?$/) {
56 # 11160: a7 fb ff 60 aghi %r15,-160
57 $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o;
59 print("wrong or unknown architecture\n");
65 ($asize = $a) =~ s/.* +(.*)$/$1/;
66 ($bsize = $b) =~ s/.* +(.*)$/$1/;
73 $funcre = qr/^$x* \<(.*)\>:$/;
74 while ($line = <STDIN>) {
75 if ($line =~ m/$funcre/) {
78 if ($line =~ m/$re/) {
80 $size = hex($size) if ($size =~ /^0x/);
82 if ($size > 0x80000000) {
88 $line =~ m/^($xs*).*/;
93 my $intro = "$addr $func:";
94 my $padlen = 56 - length($intro);
99 next if ($size < 100);
100 $stack[@stack] = "$intro$size\n";
104 @sortedstack = sort bysize @stack;
106 foreach $i (@sortedstack) {