Add two new build targets to enable the possibility of using clang-cl as
authorEverton Constantino <everton.constantino@linaro.org>
Thu, 27 Oct 2022 18:07:48 +0000 (15:07 -0300)
committerHugo Landau <hlandau@openssl.org>
Thu, 24 Nov 2022 06:36:47 +0000 (06:36 +0000)
an assembler for Windows on Arm builds and also clang-cl as the compiler
as well. Make appropriate changes to armcap source and peralsm scripts.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19523)

Configurations/50-win-clang-cl.conf [new file with mode: 0644]
Configurations/windows-makefile.tmpl
crypto/armcap.c
crypto/perlasm/arm-xlate.pl

diff --git a/Configurations/50-win-clang-cl.conf b/Configurations/50-win-clang-cl.conf
new file mode 100644 (file)
index 0000000..cfc96ef
--- /dev/null
@@ -0,0 +1,35 @@
+## -*- mode: perl; -*-
+# Windows on Arm clang-cl targets.
+#
+
+my %targets = (
+    "VC-WIN64-CLANGASM-ARM" => {
+        inherit_from    => [ "VC-noCE-common" ],
+        defines         => add("_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE",
+                               "OPENSSL_SYS_WIN_CORE"),
+        bn_ops          => "SIXTY_FOUR_BIT RC4_CHAR",
+        multilib        => "-arm64",
+        asm_arch        => "aarch64",
+        AS        => "clang-cl.exe",
+        ASFLAGS   => "/nologo /Zi",
+        asflags   => "/c",
+        asoutflag => "/Fo",
+        perlasm_scheme => "win64",
+        uplink_arch      => 'armv8',
+    },
+    "VC-CLANG-WIN64-CLANGASM-ARM" => {
+        CC => "clang-cl",
+        inherit_from    => [ "VC-noCE-common" ],
+        defines         => add("_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE",
+                               "OPENSSL_SYS_WIN_CORE"),
+        bn_ops          => "SIXTY_FOUR_BIT RC4_CHAR",
+        multilib        => "-arm64",
+        asm_arch        => "aarch64",
+        AS        => "clang-cl.exe",
+        ASFLAGS   => "/nologo /Zi",
+        asflags   => "/c",
+        asoutflag => "/Fo",
+        perlasm_scheme => "win64",
+        uplink_arch      => 'armv8',
+    },
+);
index 5d41af41bca2cebb2546c289180410fbdc37345e..f9c58eae94f7b7dea7b37545b02b70a7d0d5e04b 100644 (file)
@@ -780,7 +780,7 @@ EOF
           }
           return <<"EOF";
 $target: "$gen0" $deps
-       \$(CPP) $incs $cppflags $defs "$gen0" > \$@.i
+       \$(CPP) /D__ASSEMBLER__ $incs $cppflags $defs "$gen0" > \$@.i
        move /Y \$@.i \$@
 EOF
       } elsif ($gen0 =~ m|^.*\.in$|) {
index 0aa11baed4b93585c25e17b5b6c6e21116579187..a43f17304b02ea96e061863b184156c5efcc3ceb 100644 (file)
 #include <sys/sysctl.h>
 #endif
 #include "internal/cryptlib.h"
+#ifndef _WIN32
 #include <unistd.h>
-
+#else
+#include <windows.h>
+#endif
 #include "arm_arch.h"
 
 unsigned int OPENSSL_armcap_P = 0;
 unsigned int OPENSSL_arm_midr = 0;
 unsigned int OPENSSL_armv8_rsa_neonized = 0;
 
-#if __ARM_MAX_ARCH__<7
+#ifdef _WIN32
+void OPENSSL_cpuid_setup(void)
+{
+    OPENSSL_armcap_P |= ARMV7_NEON;
+    OPENSSL_armv8_rsa_neonized = 1;
+    if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) {
+        // These are all covered by one call in Windows
+        OPENSSL_armcap_P |= ARMV8_AES;
+        OPENSSL_armcap_P |= ARMV8_PMULL;
+        OPENSSL_armcap_P |= ARMV8_SHA1;
+        OPENSSL_armcap_P |= ARMV8_SHA256;
+    }
+}
+
+uint32_t OPENSSL_rdtsc(void)
+{
+    return 0;
+}
+#elif __ARM_MAX_ARCH__<7
 void OPENSSL_cpuid_setup(void)
 {
 }
index a90885905c0fdbf7c4f1b830d644181883720c99..df10ddc7fabb87cdbe157ee4ab5c3f39c5373d54 100755 (executable)
@@ -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 {