Commit 0444d9b3 authored by Jörn Engel's avatar Jörn Engel Committed by Linus Torvalds

[PATCH] Improve `make checkstack'

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: default avatarJörn Engel <joern@wohnheim.fh-wedel.de>
parent 20e743bb
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
$re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
} elsif ($arch =~ /^i[3456]86$/) { } elsif ($arch =~ /^i[3456]86$/) {
#c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp #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$/) { } elsif ($arch =~ /^ia64$/) {
#e0000000044011fc: 01 0f fc 8c adds r12=-384,r12 #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
$re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o; $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
...@@ -48,10 +48,10 @@ ...@@ -48,10 +48,10 @@
$re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
} elsif ($arch =~ /^ppc$/) { } elsif ($arch =~ /^ppc$/) {
#c00029f4: 94 21 ff 30 stwu r1,-208(r1) #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$/) { } elsif ($arch =~ /^ppc64$/) {
#XXX #XXX
$re = qr/.*stdu.*r1,-($x{3,5})\(r1\)/o; $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o;
} elsif ($arch =~ /^s390x?$/) { } elsif ($arch =~ /^s390x?$/) {
# 11160: a7 fb ff 60 aghi %r15,-160 # 11160: a7 fb ff 60 aghi %r15,-160
$re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o; $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o;
...@@ -79,6 +79,12 @@ while ($line = <STDIN>) { ...@@ -79,6 +79,12 @@ while ($line = <STDIN>) {
my $size = $1; my $size = $1;
$size = hex($size) if ($size =~ /^0x/); $size = hex($size) if ($size =~ /^0x/);
if ($size > 0x80000000) {
$size = - $size;
$size += 0x80000000;
$size += 0x80000000;
}
$line =~ m/^($xs*).*/; $line =~ m/^($xs*).*/;
my $addr = $1; my $addr = $1;
$addr =~ s/ /0/g; $addr =~ s/ /0/g;
...@@ -90,6 +96,7 @@ while ($line = <STDIN>) { ...@@ -90,6 +96,7 @@ while ($line = <STDIN>) {
$intro .= ' '; $intro .= ' ';
$padlen -= 8; $padlen -= 8;
} }
next if ($size < 100);
$stack[@stack] = "$intro$size\n"; $stack[@stack] = "$intro$size\n";
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment