On 2024-01-30 Tu 17:54, Dave Cramer wrote:



On Tue, Jan 30, 2024 at 4:56 PM Andrew Dunstan <and...@dunslane.net> wrote:


    On 2024-01-30 Tu 09:50, Dave Cramer wrote:


    On Tue, 30 Jan 2024 at 08:38, Andrew Dunstan
    <and...@dunslane.net> wrote:


        On 2024-01-29 Mo 11:20, Dave Cramer wrote:

        Dave Cramer
        www.postgres.rocks <http://www.postgres.rocks>


        On Mon, 29 Jan 2024 at 11:16, Andrew Dunstan
        <and...@dunslane.net> wrote:


            On 2024-01-26 Fr 09:18, Dave Cramer wrote:


            On Fri, 26 Jan 2024 at 07:36, Andrew Dunstan
            <and...@dunslane.net> wrote:


                On 2024-01-25 Th 20:32, Michael Paquier wrote:
                > On Thu, Jan 25, 2024 at 04:52:30PM -0500, Dave
                Cramer wrote:
                >> On Thu, 25 Jan 2024 at 16:32, Andrew Dunstan
                <and...@dunslane.net> wrote:
                >>> On 2024-01-25 Th 16:17, Dave Cramer wrote:
                >>> Yeah, I think the default Developer Command
                Prompt for VS2022 is set up
                >>> for x86 builds. AIUI you should start by
                executing "vcvarsall x64_arm64".
                >> Yup, now I'm in the same state you are
                > Wait a minute here. Based on [1], x64_arm64 means
                you can use a x64
                > host and you'll be able to produce ARM64 builds,
                still these will not
                > be able to run on the host where they were built.
                How much of the
                > patch posted upthread is required to produce such
                builds?  Basically
                > everything from it, I guess, so as build
                dependencies can be
                > satisfied?
                >
                > [1]:
                
https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170


                If you look at the table here x86 and x64 are the
                only supported host
                architectures. But that's OK, the x64 binaries will
                run on arm64 (W11
                ARM64 has x64 emulation builtin). If that didn't
                work Dave and I would
                not have got as far as we have. But you want the
                x64_arm64 argument to
                vcvarsall so you will get ARM64 output.


            I've rebuilt it using x64_arm64 and with the attached
            (very naive patch) and I still get an x64 binary :(


            With this patch I still get a build error, but it's
            different :-)


            [1406/2088] "link" @src/backend/postgres.exe.rsp
            FAILED: src/backend/postgres.exe src/backend/postgres.pdb
            "link" @src/backend/postgres.exe.rsp
               Creating library src\backend\postgres.exe.lib

            storage_lmgr_s_lock.c.obj : error LNK2019: unresolved
            external symbol spin_delay referenced in function
            perform_spin_delay

            src\backend\postgres.exe : fatal error LNK1120: 1
            unresolved externals


        Did you add the latest lock.patch ?




        I'm a bit confused about exactly what needs to be applied.
        Can you supply a complete patch to be applied to a pristine
        checkout that will let me build?


        cheers


    See attached.



    No, that is what is giving me the error shown above (just tried
    again to be certain). And it's not surprising, as patch 2 #ifdef's
    out the definition of spin_delay().

    If you can get a complete build with these patches then I suspect
    you're not doing a proper ARM64 build.


Okay I will look when I get home in a week


I made some progress. The attached is mostly taken from <https://postgr.es/m/dbee741f-b9b7-a0d5-1b1b-f9b532bb6...@linaro.org>

With it applied I was able to get a successful build using the buildfarm client. However, there are access violations when running some tests, so there is still some work to do, apparently.


cheers


andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index ed5b285a5e..d9b8649dab 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -4150,7 +4150,7 @@ make: *** [postgres] Error 1
    <sect3 id="install-windows-full-64-bit">
     <title>Special Considerations for 64-Bit Windows</title>
     <para>
-     PostgreSQL will only build for the x64 architecture on 64-bit Windows.
+     PostgreSQL will only build for the x64 and ARM64 architecture on 64-bit Windows.
     </para>
     <para>
      Mixing 32- and 64-bit versions in the same build tree is not supported.
diff --git a/meson.build b/meson.build
index 8ed51b6aae..14aea924ec 100644
--- a/meson.build
+++ b/meson.build
@@ -2046,8 +2046,11 @@ int main(void)
 elif host_cpu == 'arm' or host_cpu == 'aarch64'
 
   prog = '''
+#ifdef _MSC_VER
+#include <intrin.h>
+#else
 #include <arm_acle.h>
-
+#endif
 int main(void)
 {
     unsigned int crc = 0;
@@ -2061,7 +2064,11 @@ int main(void)
 }
 '''
 
-  if cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd without -march=armv8-a+crc',
+  if cc.get_id() == 'msvc'
+    cdata.set('USE_ARMV8_CRC32C', false)
+    cdata.set('USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 1)
+    have_optimized_crc = true
+  elif cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd without -march=armv8-a+crc',
       args: test_c_args)
     # Use ARM CRC Extension unconditionally
     cdata.set('USE_ARMV8_CRC32C', 1)
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 69582f4ae7..44abd42691 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -707,15 +707,31 @@ typedef LONG slock_t;
 
 #define SPIN_DELAY() spin_delay()
 
-/* If using Visual C++ on Win64, inline assembly is unavailable.
- * Use a _mm_pause intrinsic instead of rep nop.
+/*
+ * If using Visual C++ on Win64, inline assembly is unavailable.
+ * Use architecture specific intrinsics.
  */
 #if defined(_WIN64)
+/*
+ * For Arm64, use __isb intrinsic. See aarch64 inline assembly definition for details.
+ */
+#ifdef _M_ARM64
+static __forceinline void
+spin_delay(void)
+{
+	 /* Reference: https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics#BarrierRestrictions */
+	__isb(_ARM64_BARRIER_SY);
+}
+#else
+/*
+ * For x64, use _mm_pause intrinsic instead of rep nop.
+ */
 static __forceinline void
 spin_delay(void)
 {
 	_mm_pause();
 }
+#endif
 #else
 static __forceinline void
 spin_delay(void)
diff --git a/src/port/pg_crc32c_armv8.c b/src/port/pg_crc32c_armv8.c
index d47d838c50..f18903a68a 100644
--- a/src/port/pg_crc32c_armv8.c
+++ b/src/port/pg_crc32c_armv8.c
@@ -14,7 +14,9 @@
  */
 #include "c.h"
 
+#ifndef _MSC_VER
 #include <arm_acle.h>
+#endif
 
 #include "port/pg_crc32c.h"
 
diff --git a/src/tools/msvc_gendef.pl b/src/tools/msvc_gendef.pl
index 12c49ed265..dfb26916bd 100644
--- a/src/tools/msvc_gendef.pl
+++ b/src/tools/msvc_gendef.pl
@@ -120,9 +120,9 @@ sub writedef
 	{
 		my $isdata = $def->{$f} eq 'data';
 
-		# Strip the leading underscore for win32, but not x64
+		# Strip the leading underscore for win32, but not x64 and aarch64
 		$f =~ s/^_//
-		  unless ($arch eq "x86_64");
+		  unless ($arch eq "x86_64" || $arch eq "aarch64");
 
 		# Emit just the name if it's a function symbol, or emit the name
 		# decorated with the DATA option for variables.
@@ -143,7 +143,7 @@ sub writedef
 sub usage
 {
 	die("Usage: msvc_gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files-or-directories\n"
-		  . "    arch: x86 | x86_64\n"
+		  . "    arch: x86 | x86_64 | aarch64\n"
 		  . "    deffile: path of the generated file\n"
 		  . "    tempdir: directory for temporary files\n"
 		  . "    files or directories: object files or directory containing object files\n"
@@ -160,7 +160,7 @@ GetOptions(
 	'tempdir:s' => \$tempdir,) or usage();
 
 usage("arch: $arch")
-  unless ($arch eq 'x86' || $arch eq 'x86_64');
+  unless ($arch eq 'x86' || $arch eq 'x86_64' || $arch eq 'aarch64');
 
 my @files;
 

Reply via email to