Minor perlasm updates.
[openssl.git] / crypto / perlasm / x86gas.pl
index fa789a78b95acb7d4b76905ce5f578836a9c6002..e3fbb940f051e8aa18fd6610bdb6fd2b12f9f5e8 100644 (file)
@@ -77,11 +77,11 @@ sub ::jmp_ptr       { &::generic("jmp","*$_[0]");   }
 };
 *::shld = sub
 { my($dst,$src,$bits)=@_;
-    &::emit("shldl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst");
+    &::emit("shldl",$bits eq "cl"?"%cl":"\$$bits","%$src","%$dst");
 };
 *::shrd = sub
 { my($dst,$src,$bits)=@_;
-    &::emit("shrdl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst");
+    &::emit("shrdl",$bits eq "cl"?"%cl":"\$$bits","%$src","%$dst");
 };
 
 sub ::DWP
@@ -124,8 +124,8 @@ 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)
+    {  push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
+    elsif (($::aout and !$::pic) or $::macosx)
     { }
     else
     {  push(@out,".type        $func,\@function\n"); }
@@ -160,7 +160,7 @@ sub ::comment
        }
 
 sub ::external_label
-{   push(@out,".extern\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
+{   foreach(@_) { &::LABEL($_,$nmdecor.$_); }   }
 
 sub ::public_label
 {   push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
@@ -171,6 +171,13 @@ sub ::file_end
        if ($::elf)     { push (@out,"$tmp,4\n"); }
        else            { push (@out,"$tmp\n"); }
     }
+    if ($::macosx)
+    {  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 +202,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]",
+       {   &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
                            $base));
+           &::mov($dst,&::DWP("$sym\@GOT",$dst));
        }
-       &::mov($dst,&::DWP("$nmdecor$sym\@GOT",$dst));
     }
     else
     {  &::lea($dst,&::DWP($sym));      }
@@ -224,6 +236,13 @@ ___
     {   $initseg.=<<___;       # applies to both Cygwin and Mingw
 .section       .ctors
 .long  $f
+___
+    }
+    elsif ($::macosx)
+    {  $initseg.=<<___;
+.mod_init_func
+.align 2
+.long   $f
 ___
     }
     elsif ($::aout)
@@ -239,4 +258,7 @@ ___
     }
 }
 
+sub ::dataseg
+{   push(@out,".data\n");   }
+
 1;