Fix typo in CONTRIBUTING.md
[openssl.git] / crypto / perlasm / arm-xlate.pl
index af6f7d31885abe16573f16c87a47e18054f8893b..3b0dcad4139f90ddb091dfa4868f741341619e31 100755 (executable)
@@ -1,5 +1,5 @@
 #! /usr/bin/env perl
-# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2015-2023 The OpenSSL Project Authors. All Rights Reserved.
 #
 # Licensed under the Apache License 2.0 (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
@@ -22,6 +22,7 @@ my $dotinlocallabels=($flavour=~/linux/)?1:0;
 ################################################################
 my $arch = sub {
     if ($flavour =~ /linux/)   { ".arch\t".join(',',@_); }
+    elsif ($flavour =~ /win64/) { ".arch\t".join(',',@_); }
     else                       { ""; }
 };
 my $fpu = sub {
@@ -37,6 +38,7 @@ my $rodata = sub {
 };
 my $hidden = sub {
     if ($flavour =~ /ios/)     { ".private_extern\t".join(',',@_); }
+    elsif ($flavour =~ /win64/) { ""; }
     else                       { ".hidden\t".join(',',@_); }
 };
 my $comm = sub {
@@ -85,6 +87,15 @@ my $type = sub {
                                        "#endif";
                                  }
                                }
+    elsif ($flavour =~ /win64/) { if (join(',',@_) =~ /(\w+),%function/) {
+                # See https://sourceware.org/binutils/docs/as/Pseudo-Ops.html
+                # Per https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#coff-symbol-table,
+                # the type for functions is 0x20, or 32.
+                ".def $1\n".
+                "   .type 32\n".
+                ".endef";
+            }
+        }
     else                       { ""; }
 };
 my $size = sub {
@@ -150,7 +161,7 @@ while(my $line=<>) {
     if ($line =~ m/^\s*(#|@|\/\/)/)    { print $line; next; }
 
     $line =~ s|/\*.*\*/||;     # get rid of C-style comments...
-    $line =~ s|^\s+||;         # ... and skip white spaces in beginning...
+    $line =~ s|^\s+||;         # ... and skip whitespace in beginning...
     $line =~ s|\s+$||;         # ... and at the end
 
     {
@@ -159,9 +170,8 @@ while(my $line=<>) {
     }
 
     {
-       $line =~ s|(^[\.\w]+)\:\s*||;
-       my $label = $1;
-       if ($label) {
+       if ($line =~ s|(^[\.\w]+)\:\s*||) {
+           my $label = $1;
            printf "%s:",($GLOBALS{$label} or $label);
        }
     }
@@ -187,8 +197,18 @@ while(my $line=<>) {
        }
     }
 
+    # ldr REG, #VALUE psuedo-instruction - avoid clang issue with Neon registers
+    #
+    if ($line =~ /^\s*ldr\s+([qd]\d\d?)\s*,\s*=(\w+)/i) {
+        # Immediate load via literal pool into qN or DN - clang max is 2^32-1
+        my ($reg, $value) = ($1, $2);
+        # If $value is hex, 0x + 8 hex chars = 10 chars total will be okay
+        # If $value is decimal, 2^32 - 1 = 4294967295 will be okay (also 10 chars)
+        die("$line: immediate load via literal pool into $reg: value too large for clang - redo manually") if length($value) > 10;
+    }
+
     print $line if ($line);
     print "\n";
 }
 
-close STDOUT;
+close STDOUT or die "error closing STDOUT: $!";