X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fdriver%2Fmangler%2Fghc-asm.lprl;h=92feae1dc47fd85cf254e589fb14e10f36e9e4b8;hb=a324b415d33bf851ba858db1295c1715fdbfc6da;hp=e976570c2b50932170ab2da654f3e6edbb49c836;hpb=2011da8dabbf5cbe57e4fc1e0ee3012634cd4d8f;p=ghc-hetmet.git diff --git a/ghc/driver/mangler/ghc-asm.lprl b/ghc/driver/mangler/ghc-asm.lprl index e976570..92feae1 100644 --- a/ghc/driver/mangler/ghc-asm.lprl +++ b/ghc/driver/mangler/ghc-asm.lprl @@ -96,8 +96,8 @@ sub init_TARGET_STUFF { $T_CONST_LBL = '^\$L?C(\d+):$'; # regexp for what such a lbl looks like $T_POST_LBL = ':'; - $T_MOVE_DIRVS = '^(\s*(\.align\s+\d+|\.(globl|ent)\s+\S+|\#.*|\.(file|loc)\s+\S+\s+\S+|\.text|\.r?data)\n)'; - $T_COPY_DIRVS = '^\s*(\#|\.(file|globl|ent|loc))'; + $T_MOVE_DIRVS = '^(\s*(\$.*\.\.ng:|\.align\s+\d+|\.(globl|ent)\s+\S+|\#.*|\.(file|loc)\s+\S+\s+\S+|\.text|\.r?data)\n)'; + $T_COPY_DIRVS = '^\s*(\$.*\.\.ng:|\#|\.(file|globl|ent|loc))'; $T_hsc_cc_PAT = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"'; $T_DOT_WORD = '\.(long|quad|byte|word)'; @@ -188,8 +188,8 @@ sub init_TARGET_STUFF { $T_X86_PRE_LLBL = '.L'; $T_X86_BADJMP = '^\tjmp\s+[^\.\*]'; - $T_MOVE_DIRVS = '^(\s*(\.(p2)?align\s+\d+(,\s*0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.Lfe.*\n\s*\.size\s+.*|\.size\s+.*|\.ident.*)\n)'; - $T_COPY_DIRVS = '\.(globl)'; + $T_MOVE_DIRVS = '^(\s*(\.(p2)?align\s+\d+(,\s*0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.size\s+\S+,\d+|\.ident.*)\n)'; + $T_COPY_DIRVS = '^\s*\.(globl|type|size)'; if ( $TargetPlatform =~ /freebsd|netbsd/ ) { $T_hsc_cc_PAT = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"'; @@ -613,7 +613,8 @@ sub mangle_asm { || ! /^L\$\d+$/ ) ) { local($thing); chop($thing = $_); - print STDERR "Funny global thing?: $_" + $thing =~ s/:$//; + print STDERR "Warning: retaining unknown function \`$thing' in output from C compiler\n" unless # $KNOWN_FUNNY_THING{$thing} /^${T_US}stg_.*${T_POST_LBL}$/o # RTS internals || /^${T_US}__stg_.*${T_POST_LBL}$/o # more RTS internals @@ -631,6 +632,11 @@ sub mangle_asm { $chk[++$i] = $_; $chkcat[$i] = 'dyld'; $chksymb[$i] = ''; + } elsif ( $TargetPlatform =~ /^powerpc-apple-.*/ && /^\.symbol_stub/ ) + { + $chk[++$i] = $_; + $chkcat[$i] = 'dyld'; + $chksymb[$i] = ''; } elsif ( $TargetPlatform =~ /^powerpc-apple-.*/ && /^\.lazy_symbol_pointer/ ) { $chk[++$i] = $_; @@ -700,13 +706,15 @@ sub mangle_asm { $p =~ s/^\tpushl\s+\%edi\n//; $p =~ s/^\tpushl\s+\%esi\n//; $p =~ s/^\tpushl\s+\%ebx\n//; + $p =~ s/^\tmovl\s+\%esi,\s*\d*\(\%esp\)\n//; + $p =~ s/^\tmovl\s+\%edi,\s*\d*\(\%esp\)\n//; $p =~ s/^\tsubl\s+\$\d+,\s*\%esp\n//; $p =~ s/^\tmovl\s+\$\d+,\s*\%eax\n\tcall\s+__alloca\n// if ($TargetPlatform =~ /^.*-cygwin32/); # GCC 3.1 is in the habit of adding spurious writes to the # stack in the prologue. Just to be on the safe side, # chuck these over the fence into the main code. - while ($p =~ /^\tmovl\s+(\$\d+|\%edi),\s*\d*\(\%esp\)\n/) { + while ($p =~ /^\tmovl\s+\$\d+,\s*\d*\(\%esp\)\n/) { # print "Spurious instruction: $&"; $p = $` . $'; $r = $& . $r; @@ -759,13 +767,19 @@ sub mangle_asm { $p =~ s/^\tbcl 20,31,L\d+\$pb\n//; $p =~ s/^L\d+\$pb:\n//; $p =~ s/^\tmflr r31\n//; + + # This is bad: GCC 3 seems to zero-fill some local variables in the prologue + # under some circumstances, only when generating position dependent code. + # I have no idea why, and I don't think it is necessary, so let's toss it. + $p =~ s/^\tli r\d+,0\n//g; + $p =~ s/^\tstw r\d+,\d+\(r1\)\n//g; } else { print STDERR "$Pgm: unknown prologue mangling? $TargetPlatform\n"; } # HWL HACK: dont die, just print a warning #print stderr "HWL: this should die! Prologue junk?: $p\n" if $p =~ /^\t[^\.]/; - die "Prologue junk?: $p\n" if $p =~ /^\t[^\.]/; + die "Prologue junk?: $p\n" if $p =~ /^\s+[^\s\.]/; if ($TargetPlatform =~ /^powerpc-apple-.*/ && $pcrel_label ne "") { # on PowerPC, we have to keep a part of the prologue @@ -834,7 +848,7 @@ sub mangle_asm { # toss the register-windowing save/restore/ret* instructions # directly: if ( $TargetPlatform =~ /^sparc-/ ) { - $c =~ s/^\t(save.*|restore|ret|retl)\n//g; + $c =~ s/^\t(save.*|restore.*|ret|retl)\n//g; # throw away PROLOGUE comments $c =~ s/^\t!#PROLOGUE# 0\n\t!#PROLOGUE# 1\n//; } @@ -843,6 +857,7 @@ sub mangle_asm { # toss all calls to __DISCARD__ $c =~ s/^\t(call|jbsr|jal)\s+${T_US}__DISCARD__\n//go; + $c =~ s/^\tjsr\s+\$26\s*,\s*${T_US}__DISCARD__\n//go if $TargetPlatform =~ /^alpha-/; $c =~ s/^\tbl\s+L___DISCARD__\$stub\n//go if $TargetPlatform =~ /^powerpc-apple-.*/; # IA64: mangle tailcalls into jumps here @@ -907,16 +922,18 @@ sub mangle_asm { if ( $TargetPlatform =~ /^alpha-/ && $c =~ /^\t\.ent\s+(\S+)/ ) { $ent = $1; # toss all prologue stuff, except for loading gp, and the ..ng address - if (($p, $r) = split(/^\t\.prologue/, $c)) { - if (($keep, $junk) = split(/\.\.ng:/, $p)) { - $keep =~ s/^\t\.frame.*\n/\t.frame \$30,0,\$26,0\n/; - $keep =~ s/^\t\.(mask|fmask).*\n//g; - $c = $keep . "..ng:\n"; - } else { - print STDERR "malformed code block ($ent)?\n" - } - } - $c .= "\t.prologue" . $r; + unless ($c =~ /\.ent.*\n\$.*\.\.ng:/) { + if (($p, $r) = split(/^\t\.prologue/, $c)) { + if (($keep, $junk) = split(/\.\.ng:/, $p)) { + $keep =~ s/^\t\.frame.*\n/\t.frame \$30,0,\$26,0\n/; + $keep =~ s/^\t\.(mask|fmask).*\n//g; + $c = $keep . "..ng:\n"; + } else { + print STDERR "malformed code block ($ent)?\n" + } + } + $c .= "\t.prologue" . $r; + } } $c =~ s/FUNNY#END#THING//; @@ -1106,11 +1123,37 @@ sub mangle_asm { $c =~ s/^\tjmp ${T_US}${symb}_fast\d+.*\n\tnop\n//; $c =~ s/^\tjmp ${T_US}${symb}_fast\d+.*\n//; } elsif ( $TargetPlatform =~ /^powerpc-apple-.*/ ) { - $c =~ s/^\taddis r9,r31,ha16\(L_${symb}_fast\d*\$non_lazy_ptr-L\d+\$pb\)\n\tlwz r9,lo16\(L_${symb}_fast\d*\$non_lazy_ptr-L\d+\$pb\)\(r9\)\n\tmtctr r9\n\tbctr\n//; - # addis r9,r31,ha16(L_XXXX_fast3$non_lazy_ptr-L32$pb) - # lwz r9,lo16(L_XXXX_fast3$non_lazy_ptr-L32$pb)(r9) + if ( $c =~ s/^\taddis r9,r31,ha16\(L_${symb}_fast\d*\$non_lazy_ptr-L\d+\$pb\)\n\tlwz r9,lo16\(L_${symb}_fast\d*\$non_lazy_ptr-L\d+\$pb\)\(r9\)\n\tmtctr r9\n\tbctr$// ) { + # for Position-Independent Code, GCC 2: + # addis r9,r31,ha16(L_XXXX_fast3$non_lazy_ptr-Lxxx$pb) + # lwz r9,lo16(L_XXXX_fast3$non_lazy_ptr-Lxxx$pb)(r9) # mtctr r9 # bctr + + } elsif ( $c =~ s/^\taddis r9,r31,ha16\(L_${symb}_fast\d*\$non_lazy_ptr-L\d+\$pb\)\n\tlwz r29,lo16\(L_${symb}_fast\d*\$non_lazy_ptr-L\d+\$pb\)\(r9\)\nL(\d+):\n\tmtctr r29\n\tbctr$// ) { + # for Position-Independent Code, GCC 3: + # addis r9,r31,ha16(L_XXXX_fast3$non_lazy_ptr-Lxxx$pb) + # lwz r29,lo16(L_XXXX_fast3$non_lazy_ptr-Lxxx$pb)(r9) + # Lyyy: + # mtctr r29 + # bctr + $label = $1; + $c =~ s/^\tb L${label}\n/\tmtctr r29\n\tbctr\n/g; + } elsif ( $c =~ s/^\tlis r9,ha16\(L_${symb}_fast\d*\$non_lazy_ptr\)\n\tlwz r31,lo16\(L_${symb}_fast\d*\$non_lazy_ptr\)\(r9\)\nL(\d+):\n\tmtctr r31\n\tbctr$// ) { + # for -mdynamic-no-pic Code, GCC 3: + # lis r9,ha16(L_XXXX_fast3$non_lazy_ptr) + # lwz r31,lo16(L_XXXX_fast3$non_lazy_ptr-Lxxx$pb)(r9) + # Lyyy: + # mtctr r31 + # bctr + $label = $1; + $c =~ s/^\tb L${label}\n/\tmtctr r31\n\tbctr\n/g; + } else { + + print STDERR "slow-fast dropthrough not mangled\n"; + print STDERR $c; + print STDERR "\n\n"; + } } elsif ( $TargetPlatform =~ /^sparc-/ ) { $c =~ s/^\tcall\s+${T_US}${symb}_fast\d+,.*\n\t\s*nop\n//; $c =~ s/^\tcall\s+${T_US}${symb}_fast\d+,.*\n(\t\s*[a-z].*\n)/$1/; @@ -1298,7 +1341,7 @@ sub print_doctored { # jmp * # - s/^\tmovl\s+\$${T_US}(.*),(\%e[abcd]x)\n\tjmp\s+\*\2/\tjmp $T_US$1/g; + s/^\tmovl\s+\$${T_US}(.*),\s*(\%e[abcd]x)\n\tjmp\s+\*\2/\tjmp $T_US$1/g; if ($StolenX86Regs <= 2 ) { # YURGH! spurious uses of esi? s/^\tmovl\s+(.*),\s*\%esi\n\tjmp\s+\*%esi\n/\tmovl $1,\%eax\n\tjmp \*\%eax\n/g;