From: simonmar Date: Tue, 13 Jun 2000 15:35:29 +0000 (+0000) Subject: [project @ 2000-06-13 15:35:29 by simonmar] X-Git-Tag: Approximately_9120_patches~4226 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=4ccbb70fcea6ff393ca954cc9dca3729f8c31edd;p=ghc-hetmet.git [project @ 2000-06-13 15:35:29 by simonmar] Push directives over literal chunks when attempting to move them to the following chunk on x86. Occasionally gcc generates a .glob directive some distance before the symbol it refers to, and we were ending up with a whole load of .glob directives attached to strings, and duplicated in each .o file when splitting. This change reduces the size of my libHSstd_p.a from 43M (!!!) to 9M. I think this problem must have appeared with gcc 2.95.2, but it's a little strange that I didn't notice it until now. --- diff --git a/ghc/driver/mangler/ghc-asm.lprl b/ghc/driver/mangler/ghc-asm.lprl index 70f500d..4b221fe 100644 --- a/ghc/driver/mangler/ghc-asm.lprl +++ b/ghc/driver/mangler/ghc-asm.lprl @@ -69,7 +69,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.align 3\n"; $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.align 3\n"; - $T_HDR_srt = "\.data\n\t\.align 3\n"; + $T_HDR_srt = "\.text\n\t\.align 3\n"; $T_HDR_info = "\.text\n\t\.align 3\n"; $T_HDR_entry = "\.text\n\t\.align 3\n"; $T_HDR_fast = "\.text\n\t\.align 3\n"; @@ -104,7 +104,7 @@ sub init_TARGET_STUFF { $T_HDR_direct = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$CODE\$\n\t\.align 4\n"; #--------------------------------------------------------# - } elsif ( $TargetPlatform =~ /^i386-.*-(linuxaout|freebsd2|nextstep3|cygwin32|mingw32)$/ ) { + } elsif ( $TargetPlatform =~ /^i386-.*-(linuxaout|freebsd2|netbsd|nextstep3|cygwin32|mingw32)$/ ) { # NeXT added but not tested. CaS $T_STABBY = 1; # 1 iff .stab things (usually if a.out format) @@ -127,7 +127,7 @@ sub init_TARGET_STUFF { $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.align 2\n"; $T_HDR_closure = "\.data\n\t\.align 2\n\t.long 0\n" if ( $TargetPlatform =~ /.*-mingw32$/ ); - $T_HDR_srt = "\.data\n\t\.align 2\n"; + $T_HDR_srt = "\.text\n\t\.align 2\n"; $T_HDR_info = "\.text\n\t\.align 2\n"; # NB: requires padding $T_HDR_entry = "\.text\n"; # no .align so we're right next to _info (arguably wrong...?) $T_HDR_fast = "\.text\n\t\.align 2,0x90\n"; @@ -135,12 +135,12 @@ sub init_TARGET_STUFF { $T_HDR_direct = "\.text\n\t\.align 2,0x90\n"; #--------------------------------------------------------# - } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|freebsd3)$/ ) { + } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|freebsd|netbsd_elf)$/ ) { $T_STABBY = 0; # 1 iff .stab things (usually if a.out format) $T_US = ''; # _ if symbols have an underscore on the front $T_PRE_APP = # regexp that says what comes before APP/NO_APP - ($TargetPlatform =~ /-(linux|freebsd3)$/) ? '#' : '/' ; + ($TargetPlatform =~ /-(linux|freebsd|netbsd_elf)$/) ? '#' : '/' ; $T_CONST_LBL = '^\.LC(\d+):$'; # regexp for what such a lbl looks like $T_POST_LBL = ':'; $T_X86_PRE_LLBL_PAT = '\.L'; @@ -150,7 +150,7 @@ sub init_TARGET_STUFF { $T_MOVE_DIRVS = '^(\s*(\.(p2)?align\s+\d+(,0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.Lfe.*\n\t\.size\s+.*|\.size\s+.*|\.ident.*)\n)'; $T_COPY_DIRVS = '\.(globl)'; - if ( $TargetPlatform =~ /freebsd3/ ) { + if ( $TargetPlatform =~ /freebsd|netbsd_elf/ ) { $T_hsc_cc_PAT = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"'; } else { $T_hsc_cc_PAT = '\.string.*\)(hsc|cc) (.*)\\\\t(.*)"'; @@ -163,7 +163,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.align 4\n"; # ToDo: change align?? $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.align 4\n"; # ToDo: change align? - $T_HDR_srt = "\.data\n\t\.align 4\n"; # ToDo: change align? + $T_HDR_srt = "\.text\n\t\.align 4\n"; # ToDo: change align? $T_HDR_info = "\.text\n\t\.align 4\n"; # NB: requires padding $T_HDR_entry = "\.text\n"; # no .align so we're right next to _info (arguably wrong...?) $T_HDR_fast = "\.text\n\t\.align 4\n"; @@ -190,7 +190,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.even\n"; $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.even\n"; - $T_HDR_srt = "\.data\n\t\.even\n"; + $T_HDR_srt = "\.text\n\t\.even\n"; $T_HDR_info = "\.text\n\t\.even\n"; $T_HDR_entry = "\.text\n\t\.even\n"; $T_HDR_fast = "\.text\n\t\.even\n"; @@ -217,7 +217,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\t\.data\n\t\.align 2\n"; $T_HDR_consist = 'TOO LAZY TO DO THIS TOO'; $T_HDR_closure = "\t\.data\n\t\.align 2\n"; - $T_HDR_srt = "\t\.data\n\t\.align 2\n"; + $T_HDR_srt = "\t\.text\n\t\.align 2\n"; $T_HDR_info = "\t\.text\n\t\.align 2\n"; $T_HDR_entry = "\t\.text\n\t\.align 2\n"; $T_HDR_fast = "\t\.text\n\t\.align 2\n"; @@ -478,6 +478,11 @@ sub mangle_asm { $srtchk{$1} = $i; + } elsif ( /^$TUS[@]?([A-Za-z0-9_]+)_ct$TPOSTLBL[@]?$/o ) { + $chk[++$i] = $_; + $chkcat[$i] = 'data'; + $chksymb[$i] = ''; + } elsif ( /^$TUS[@]?ghc.*c_ID$TPOSTLBL/o ) { $chk[++$i] = $_; $chkcat[$i] = 'consist'; @@ -487,7 +492,6 @@ sub mangle_asm { } elsif ( /^$TUS[A-Za-z0-9_]+\.\d+$TPOSTLBL[@]?$/o || /^$TUS[@]?.*_CAT$TPOSTLBL[@]?$/o # PROF: _entryname_CAT - || /^$TUS[@]?CC_.*_struct$TPOSTLBL[@]?$/o # PROF: _CC_ccident_struct || /^$TUS[@]?.*_done$TPOSTLBL[@]?$/o # PROF: _module_done || /^$TUS[@]?_module_registered$TPOSTLBL[@]?$/o # PROF: _module_registered ) { @@ -505,7 +509,7 @@ sub mangle_asm { $chkcat[$i] = 'toc'; $chksymb[$i] = $1; - } elsif ( /^$TUS[@]?CC(S)?_.*$/ ) { + } elsif ( /^$TUS[@]?([A-Za-z0-9_]+)_cc(s)?$TPOSTLBL[@]?$/o ) { # all CC_ symbols go in the data section... $chk[++$i] = $_; $chkcat[$i] = 'data'; @@ -560,7 +564,7 @@ sub mangle_asm { unless $KNOWN_FUNNY_THING{$thing} || /^$TUS[@]?stg_.*$TPOSTLBL[@]?$/o # RTS internals || /^$TUS[@]__fexp_.*$TPOSTLBL$/o # foreign export - || /^$TUS[@]?_reg.*$TPOSTLBL$/o # PROF: __reg + || /^$TUS[@]?__init.*$TPOSTLBL$/o # __init || /^$TUS[@]?.*_btm$TPOSTLBL$/o # large bitmaps || /^$TUS[@]?.*_closure_tbl$TPOSTLBL$/o; # closure tables $chk[++$i] = $_; @@ -683,6 +687,9 @@ sub mangle_asm { 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[^\.]/ + # && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test die "Prologue junk?: $p\n" if $p =~ /^\t[^\.]/ && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test @@ -706,6 +713,7 @@ sub mangle_asm { $e =~ s/^\tpopl \%esi\n//; $e =~ s/^\tpopl \%ecx\n//; $e =~ s/^\taddl \$\d+,\%esp\n//; + $e =~ s/^\tsubl \$-\d+,\%esp\n//; } elsif ($TargetPlatform =~ /^m68k-/) { $e =~ s/^\tunlk a6\n//; $e =~ s/^\trts\n//; @@ -723,6 +731,9 @@ sub mangle_asm { } else { print STDERR "$Pgm: unknown epilogue mangling? $TargetPlatform\n"; } + # HWL HACK: dont die, just print a warning + #print stderr "HWL: this should die! Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/ + # && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/ && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test @@ -736,7 +747,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//; } @@ -771,7 +782,28 @@ sub mangle_asm { # (this SEGVs perl4 on alphas, you see) $to_move = $1; - if ( $i < ($numchks - 1) + + # on x86 we try not to copy any directives into a literal + # chunk, rather we keep looking for the next real chunk. This + # is because we get things like + # + # .globl blah_closure + # .LC32 + # .string "..." + # blah_closure: + # ... + # + if ( $TargetPlatform =~ /^i386/ && $to_move =~ /$TCOPYDIRVS/ ) { + $j = $i + 1; + while ( $j < ($numchks - 1) && $chk[$j] =~ /$T_CONST_LBL/) { + $j++; + } + if ( $j < ($numchks - 1)) { + $chk[$j] = $to_move . $chk[$j]; + } + } + + elsif ( $i < ($numchks - 1) && ( $to_move =~ /$TCOPYDIRVS/ || ($TargetPlatform =~ /^hppa/ && $to_move =~ /align/ && $chkcat[$i+1] eq 'literal') )) { $chk[$i + 1] = $to_move . $chk[$i + 1]; @@ -877,7 +909,7 @@ sub mangle_asm { }; &print_doctored($chk[$i], 0); if ($TargetPlatform =~ /^powerpc-|^rs6000-/ && $printDS) { -#ok if ($chksymb[$i] !~ /\_regMain/) { +#ok if ($chksymb[$i] !~ /\__init_Main/) { print OUTASM "\.csect ${chksymb[$i]}[DS]\n"; print OUTASM "${p}TOC[tc0], 0\n"; #ok } @@ -1017,8 +1049,8 @@ sub mangle_asm { } elsif ( $TargetPlatform =~ /^powerpc-|^rs6000-/ ) { $c =~ s/^\tb \.${T_US}${symb}_fast\d+\n//; } elsif ( $TargetPlatform =~ /^sparc-/ ) { - $c =~ s/^\tcall ${T_US}${symb}_fast\d+,.*\n\tnop\n//; - $c =~ s/^\tcall ${T_US}${symb}_fast\d+,.*\n(\t[a-z].*\n)/$1/; + $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/; } else { print STDERR "$Pgm: mystery slow-fast dropthrough: $TargetPlatform\n"; } @@ -1158,7 +1190,7 @@ sub print_doctored { if ( $TargetPlatform !~ /^i386-/ || ! /^\t[a-z]/ # no instructions in here, apparently - || /^${T_US}_reg[A-Za-z0-9_]+${T_POST_LBL}/) { + || /^${T_US}__init_[A-Za-z0-9_]+${T_POST_LBL}/) { print OUTASM $_; return; }