Mac OS X x86 assembler support.
authorAndy Polyakov <appro@openssl.org>
Tue, 18 Dec 2007 17:28:22 +0000 (17:28 +0000)
committerAndy Polyakov <appro@openssl.org>
Tue, 18 Dec 2007 17:28:22 +0000 (17:28 +0000)
crypto/perlasm/x86asm.pl
crypto/perlasm/x86gas.pl

index 4f3b5063c448dc1788648e27730cdea03a0c53ad..3ec97221a93bed0ca3852015fade7527ea895348 100644 (file)
@@ -170,7 +170,7 @@ sub ::asm_init
     $filename=$fn;
     $i386=$cpu;
 
-    $elf=$cpp=$coff=$aout=$win32=$netware=$mwerks=0;
+    $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=0;
     if    (($type eq "elf"))
     {  $elf=1;                 require "x86gas.pl";    }
     elsif (($type eq "a\.out"))
@@ -185,6 +185,8 @@ sub ::asm_init
     #{ $netware=1; $mwerks=1;  require "x86nasm.pl";   }
     elsif (($type eq "win32"))
     {  $win32=1;               require "x86masm.pl";   }
+    elsif (($type eq "macosx"))
+    {  $aout=1; $macosx=1;     require "x86gas.pl";    }
     else
     {  print STDERR <<"EOF";
 Pick one target type from
@@ -193,6 +195,7 @@ Pick one target type from
        coff    - GAS/COFF such as Win32 targets
        win32n  - Windows 95/Windows NT NASM format
        nw-nasm - NetWare NASM format
+       macosx  - Mac OS X
 EOF
        exit(1);
     }
index fa789a78b95acb7d4b76905ce5f578836a9c6002..575b13325267ed4da700f5da0014cf34d5383e5c 100644 (file)
@@ -125,7 +125,7 @@ sub ::function_begin_B
     push(@out,".globl\t$func\n")       if ($global);
     if ($::coff)
     {  push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
-    elsif ($::aout and !$::pic)
+    elsif (($::aout and !$::pic) or $::macosx)
     { }
     else
     {  push(@out,".type        $func,\@function\n"); }
@@ -171,6 +171,14 @@ sub ::file_end
        if ($::elf)     { push (@out,"$tmp,4\n"); }
        else            { push (@out,"$tmp\n"); }
     }
+    if ($::macosx)
+    {  grep {s/^\.extern\s+.*$//} @out;
+       if (%non_lazy_ptr)
+       {   push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
+           foreach $i (keys %non_lazy_ptr)
+           {   push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n");   }
+       }
+    }
     push(@out,$initseg) if ($initseg);
 }
 
@@ -195,14 +203,19 @@ sub ::picmeup
        {   &::call(&::label("PIC_me_up"));
            &::set_label("PIC_me_up");
            &::blindpop($dst);
-           &::add($dst,"\$${nmdecor}_GLOBAL_OFFSET_TABLE_+[.-".
-                           &::label("PIC_me_up") . "]");
+           $base=$dst;
+           $reflabel=&::label("PIC_me_up");
+       }
+       if ($::macosx)
+       {   my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr");
+           &::mov($dst,&::DWP("$indirect-$reflabel",$base));
+           $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
        }
        else
        {   &::lea($dst,&::DWP("${nmdecor}_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
                            $base));
+           &::mov($dst,&::DWP("$nmdecor$sym\@GOT",$dst));
        }
-       &::mov($dst,&::DWP("$nmdecor$sym\@GOT",$dst));
     }
     else
     {  &::lea($dst,&::DWP($sym));      }
@@ -224,6 +237,13 @@ ___
     {   $initseg.=<<___;       # applies to both Cygwin and Mingw
 .section       .ctors
 .long  $f
+___
+    }
+    elsif ($::macosx)
+    {  $initseg.=<<___;
+.mod_init_func
+.align 2
+.long   $f
 ___
     }
     elsif ($::aout)