Export nameEnvUniqueElts, similar to nameEnvElts, but giving the Unique as well.
[ghc-hetmet.git] / driver / mangler / ghc-asm.lprl
index ab43cdc..576c005 100644 (file)
@@ -344,6 +344,32 @@ sub init_TARGET_STUFF {
     $T_HDR_vector   = "\t\.text\n\t\.align 2\n";
 
     #--------------------------------------------------------#
+    } elsif ( $TargetPlatform =~ /^x86_64-apple-darwin.*/ ) {
+                               # Apple PowerPC Darwin/MacOS X.
+    $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     = 'DOESNT APPLY'; # regexp that says what comes before APP/NO_APP
+    $T_CONST_LBL    = '^\LC\d+:'; # regexp for what such a lbl looks like
+    $T_POST_LBL            = ':';
+
+    $T_MOVE_DIRVS   = '^(\s*(\.align \d+|\.text|\.data|\.const_data|\.cstring|\.non_lazy_symbol_pointer|\.const|\.static_const|\.literal4|\.literal8|\.static_data|\.globl \S+|\.section .*|\.lcomm.*)\n)';
+    $T_COPY_DIRVS   = '\.(globl|lcomm)';
+
+    $T_DOT_WORD            = '\.(quad|long|short|byte|fill|space)';
+    $T_DOT_GLOBAL   = '\.globl';
+    $T_HDR_toc      = "\.toc\n";
+    $T_HDR_literal16= "\t\.literal8\n\t\.align 4\n";
+    $T_HDR_literal  = "\t\.const\n\t\.align 4\n";
+    $T_HDR_misc            = "\t\.text\n\t\.align 2\n";
+    $T_HDR_data            = "\t\.data\n\t\.align 2\n";
+    $T_HDR_rodata   = "\t\.const\n\t\.align 2\n";
+    $T_HDR_relrodata= "\t\.const_data\n\t\.align 2\n";
+    $T_HDR_closure  = "\t\.data\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_vector   = "\t\.text\n\t\.align 2\n";
+
+    #--------------------------------------------------------#
     } elsif ( $TargetPlatform =~ /^powerpc-.*-linux/ ) {
                                # PowerPC Linux
     $T_STABBY      = 0; # 1 iff .stab things (usually if a.out format)
@@ -446,8 +472,8 @@ sub init_TARGET_STUFF {
     $T_CONST_LBL    = '^\.LLC(\d+):$'; # regexp for what such a lbl looks like
     $T_POST_LBL     = ':';
 
-    $T_MOVE_DIRVS   = '^((\s+\.align\s+\d+|\s+\.proc\s+\d+|\s+\.global\s+\S+|\.text|\.data|\.seg|\.stab.*|\s+?\.section.*|\s+\.type.*|\s+\.size.*)\n)';
-    $T_COPY_DIRVS   = '\.(global|globl|proc|stab)';
+    $T_MOVE_DIRVS   = '^((\s+\.align\s+\d+|\s+\.proc\s+\d+|\s+\.global\s+\S+|\s+\.local\s+\S+|\.text|\.data|\.seg|\.stab.*|\s+?\.section.*|\s+\.type.*|\s+\.size.*)\n)';
+    $T_COPY_DIRVS   = '\.(global|local|globl|proc|stab)';
 
     $T_DOT_WORD     = '\.(long|word|nword|xword|byte|half|short|skip|uahalf|uaword)';
     $T_DOT_GLOBAL   = '^\t\.global';
@@ -699,7 +725,7 @@ sub mangle_asm {
            $chkcat[$i]  = 'data';
            $chksymb[$i] = '';
 
-        } elsif ( /^${T_US}([A-Za-z0-9_]+)_hpc?${T_POST_LBL}$/o ) {
+        } elsif ( /^${T_US}([A-Za-z0-9_]+)_hpc${T_POST_LBL}$/o ) {
            # hpc shares tick boxes across modules
            $chk[++$i]   = $_;
            $chkcat[$i]  = 'data';
@@ -788,6 +814,8 @@ sub mangle_asm {
        }
     }
     $numchks = $#chk + 1;
+    $chk[$numchks] = ''; # We might push .note.GNU-stack into this
+    $chkcat[$numchks] = 'verbatim'; # If we do, write it straight back out
 
     # open CHUNKS, ">/tmp/chunks1" or die "Cannot open /tmp/chunks1: $!\n";
     # for (my $i = 0; $i < @chk; ++$i) { print CHUNKS "======= $i =======\n", $chk[$i] }
@@ -1148,12 +1176,18 @@ sub mangle_asm {
                }
            }
 
-           elsif ( $i < ($numchks - 1)
-             && ( $to_move =~ /${T_COPY_DIRVS}/
-               || ($TargetPlatform =~ /^hppa/ && $to_move =~ /align/ && $chkcat[$i+1] eq 'literal') )) {
-               $chk[$i + 1] = $to_move . $chk[$i + 1];
-               # otherwise they're tossed
-           }
+            elsif (   (    $i < ($numchks - 1)
+                       && ( $to_move =~ /${T_COPY_DIRVS}/
+                           || (   $TargetPlatform =~ /^hppa/
+                               && $to_move =~ /align/
+                               && $chkcat[$i+1] eq 'literal')
+                          )
+                      )
+                   || ($to_move =~ /^[ \t]*\.section[ \t]+\.note\.GNU-stack,/)
+                  ) {
+                $chk[$i + 1] = $to_move . $chk[$i + 1];
+                # otherwise they're tossed
+            }
 
            $c =~ s/${T_MOVE_DIRVS}FUNNY#END#THING/FUNNY#END#THING/o;
        }
@@ -1255,7 +1289,8 @@ sub mangle_asm {
        }
     }
 
-    for ($i = $FIRST_MANGLABLE; $i < $numchks; $i++) {
+    # $numchks + 1 as we have the extra one for .note.GNU-stack
+    for ($i = $FIRST_MANGLABLE; $i < $numchks + 1; $i++) {
 #      print STDERR "$i: cat $chkcat[$i], symb $chksymb[$i]\n";
 
        next if $chkcat[$i] eq 'DONE ALREADY';
@@ -1266,6 +1301,9 @@ sub mangle_asm {
                &print_doctored($chk[$i], 0);
            }
 
+       } elsif ( $chkcat[$i] eq 'verbatim' ) {
+           print OUTASM $chk[$i];
+
        } elsif ( $chkcat[$i] eq 'toss' ) {
            print STDERR "*** NB: TOSSING code for $chksymb[$i] !!! ***\n";
 
@@ -1730,6 +1768,20 @@ sub rev_tbl {
        }
     }
 
+    if ( $TargetPlatform =~ /x86_64-apple-darwin/ ) {
+        # Tack a label to the front of the info table, too.
+        # For now, this just serves to work around a crash in Apple's new
+        # 64-bit linker (it seems to assume that there is no data before the
+        # first label in a section).
+        
+        # The plan for the future is to do this on all Darwin platforms, and
+        # to add a reference to this label after the entry code, just as the
+        # NCG does, so we can enable dead-code-stripping in the linker without
+        # losing our info tables. (Hence the name _dsp, for dead-strip preventer)
+        
+        $before .= "\n${infoname}_dsp:\n";    
+    }
+
     $tbl = $before
         . (($TargetPlatform !~ /^hppa/) ? '' : join("\n", @imports) . "\n")
         . join("\n", @words) . "\n"