Do not silently truncate files on perlasm errors
[openssl.git] / crypto / modes / asm / ghash-armv4.pl
index 245ac921d298cbbbd219354b39f7c8fd3d84e6a6..0b94340d3b44b475e672599cedcc7bd5e513c577 100644 (file)
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2010-2018 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
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
 #
 # ====================================================================
 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
@@ -47,7 +54,7 @@
 #
 # Câmara, D.; Gouvêa, C. P. L.; López, J. & Dahab, R.: Fast Software
 # Polynomial Multiplication on ARM Processors using the NEON Engine.
-# 
+#
 # http://conradoplg.cryptoland.net/files/2010/12/mocrysen13.pdf
 
 # ====================================================================
 # *native* byte order on current platform. See gcm128.c for working
 # example...
 
-$flavour = shift;
-if ($flavour=~/^\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
-else { while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {} }
+# $output is the last argument if it looks like a file (it has an extension)
+# $flavour is the first argument if it doesn't look like a file
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
 
 if ($flavour && $flavour ne "void") {
     $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
@@ -81,9 +89,10 @@ if ($flavour && $flavour ne "void") {
     ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
     die "can't locate arm-xlate.pl";
 
-    open STDOUT,"| \"$^X\" $xlate $flavour $output";
+    open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
+        or die "can't call $xlate: $!";
 } else {
-    open STDOUT,">$output";
+    $output and open STDOUT,">$output";
 }
 
 $Xi="r0";      # argument block
@@ -135,18 +144,18 @@ ___
 $code=<<___;
 #include "arm_arch.h"
 
-.text
-#if defined(__thumb2__) && !defined(__APPLE__)
+#if defined(__thumb2__) || defined(__clang__)
 .syntax        unified
+#define ldrplb  ldrbpl
+#define ldrneb  ldrbne
+#endif
+#if defined(__thumb2__)
 .thumb
 #else
 .code  32
 #endif
 
-#ifdef  __clang__
-#define ldrplb  ldrbpl
-#define ldrneb  ldrbne
-#endif
+.text
 
 .type  rem_4bit,%object
 .align 5
@@ -519,7 +528,7 @@ $code.=<<___;
 #ifdef __ARMEL__
        vrev64.8        $Xl,$Xl
 #endif
-       sub             $Xi,#16 
+       sub             $Xi,#16
        vst1.64         $Xl#hi,[$Xi]!           @ write out Xi
        vst1.64         $Xl#lo,[$Xi]
 
@@ -542,4 +551,4 @@ foreach (split("\n",$code)) {
 
        print $_,"\n";
 }
-close STDOUT; # enforce flush
+close STDOUT or die "error closing STDOUT"; # enforce flush