From: Jorn Engel On i386, stack usually grows with "sub $0x8,%esp" and shrinks with "add $0x8,%esp" respectively. In some cases, though, stack grows with "add $0xffffff80,%esp" and shrinks with "sub $0xffffff80,%esp". Obviously, we don't want to miss those cases. Since in either case add and sub seem to be balanced and contain the same parameter, we don't need a second regex. We simply accept hex numbers of up to 8 digits and treat them as negative numbers when the sub appears to be a little too high. ...or so I thought. But another day of testing proved me wrong again. Some functions do stuff like "sub $0x10,%esp", ..., "add $0x20,%esp". In other words, add and sub are *NOT* balanced. Manual inspection showed that 0x20 is a more realistic number, so I accept either variant, just in case. We pay for this with a bunch of duplicates in our output, but that beats missing some stack hogs. In the long run, this script has to be replaced by gcc options, really. Looking at the result and guessing back is such a stupid idea. Signed-off-by: Jörn Engel Signed-off-by: Andrew Morton --- 25-akpm/scripts/checkstack.pl | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff -puN scripts/checkstack.pl~checkstack-fixes scripts/checkstack.pl --- 25/scripts/checkstack.pl~checkstack-fixes 2004-05-31 23:14:51.312558400 -0700 +++ 25-akpm/scripts/checkstack.pl 2004-05-31 23:14:51.316557792 -0700 @@ -36,7 +36,7 @@ $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; } elsif ($arch =~ /^i[3456]86$/) { #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp - $re = qr/^.*sub \$(0x$x{3,5}),\%esp$/o; + $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o; } elsif ($arch =~ /^ia64$/) { #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12 $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o; @@ -48,10 +48,10 @@ $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; } elsif ($arch =~ /^ppc$/) { #c00029f4: 94 21 ff 30 stwu r1,-208(r1) - $re = qr/.*stwu.*r1,-($x{3,5})\(r1\)/o; + $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o; } elsif ($arch =~ /^ppc64$/) { #XXX - $re = qr/.*stdu.*r1,-($x{3,5})\(r1\)/o; + $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o; } elsif ($arch =~ /^s390x?$/) { # 11160: a7 fb ff 60 aghi %r15,-160 $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o; @@ -79,6 +79,12 @@ while ($line = ) { my $size = $1; $size = hex($size) if ($size =~ /^0x/); + if ($size > 0x80000000) { + $size = - $size; + $size += 0x80000000; + $size += 0x80000000; + } + $line =~ m/^($xs*).*/; my $addr = $1; $addr =~ s/ /0/g; @@ -90,6 +96,7 @@ while ($line = ) { $intro .= ' '; $padlen -= 8; } + next if ($size < 100); $stack[@stack] = "$intro$size\n"; } } _