From 0444d9b3e8570d374a83198229880bf246bb91a1 Mon Sep 17 00:00:00 2001 From: Jörn Engel Date: Mon, 31 May 2004 08:36:02 -0700 Subject: [PATCH] Improve `make checkstack' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/checkstack.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'scripts/checkstack.pl') diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl index e16d5d0fb0ea..df85c66caa0a 100644 --- a/scripts/checkstack.pl +++ b/scripts/checkstack.pl @@ -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"; } } -- cgit v1.2.3