[PATCH] Fix msvc_gendef.pl for aarch64 (Windows on Arm)

Started by kenji uno2 months ago2 messages
#1kenji uno
h8mastre@gmail.com
1 attachment(s)

I'm going to build psqlODBC (Arm64X binaries) for use with Windows 11 on
Arm.

The problem is that the `msvc_gendef.pl` generates the wrong `postgres.def`
for aarch64 (Windows).

Currently, for aarch64, the preceding underscore is removed like for x86.
However, the expected functionality for aarch64 is the same as for x64:
keep the preceding underscore.

This causes linker errors such as:

postgres.def : error LNK2001: unresolved external symbol

brin_parallel_build_main
[C:\repos\postgresql-17.0\build-last-try-3\src\backend\22e3565@
@postgres@exe.vcxproj]

Example from src/backend/access/brin/brin.c:

/*
* Perform work within a launched parallel process.
*/
void
_brin_parallel_build_main(dsm_segment *seg, shm_toc *toc)
{
// ...
}

The attached file is a patch to fix this issue.

--
kenji uno (h8mastre@gmail.com)

Attachments:

msvc_gendef.patchtext/plain; charset=US-ASCII; name=msvc_gendef.patchDownload
 src/tools/msvc_gendef.pl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/tools/msvc_gendef.pl b/src/tools/msvc_gendef.pl
index 404076dbbc..c23320b1d2 100644
--- a/src/tools/msvc_gendef.pl
+++ b/src/tools/msvc_gendef.pl
@@ -122,7 +122,7 @@ sub writedef
 
 		# Strip the leading underscore for win32, but not x64
 		$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;
 
#2Peter Eisentraut
peter@eisentraut.org
In reply to: kenji uno (#1)
Re: [PATCH] Fix msvc_gendef.pl for aarch64 (Windows on Arm)

On 11.11.25 06:11, kenji uno wrote:

I'm going to build psqlODBC (Arm64X binaries) for use with Windows 11 on
Arm.

The problem is that the `msvc_gendef.pl <http://msvc_gendef.pl&gt;`
generates the wrong `postgres.def` for aarch64 (Windows).

Currently, for aarch64, the preceding underscore is removed like for x86.
However, the expected functionality for aarch64 is the same as for x64:
keep the preceding underscore.

Here is a long-running thread about supporting Windows/MSVC on Arm:
/messages/by-id/CAFPTBD-74+AEuN9n7caJ0YUnW5A0r-KBX8rYoEJWqFPgLKpzdg@mail.gmail.com

The patch you sent is part of the overall patch set being discussed
there but it is not sufficient by itself.