pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen
5+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2023-06-07 53ea2b7ad0  Don't use _BitScanForward64/_BitScanReverse64 on 32-bit MSVC builds
* BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen
@ 2023-06-07 09:57 PG Bug reporting form <noreply@postgresql.org>
  2023-06-07 13:00 ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: PG Bug reporting form @ 2023-06-07 09:57 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: moyoumiu@outlook.com

The following bug has been logged on the website:

Bug reference:      17967
Logged by:          Youmiu Mo
Email address:      moyoumiu@outlook.com
PostgreSQL version: 15.3
Operating system:   Windows
Description:        

The file `src/bin/pg_verifybackup/pg_verifybackup.c` fails to compile using
msvc under x86, there is no `_BitScanForward64` and `_BitScanReverse64`
under **x86** for head `src/include/port/pg_bitutils.h`.

### output
```log
F:\repo\postgresql\src\include\port\pg_bitutils.h(88,13): warning C4013:
'_BitScanReverse64' undefined; assuming extern returning int (compiling
source file src/bin/pg_verifybackup/pg_verifybackup.c)
[F:\repo\postgresql\pg_verifybackup.vcxproj]
pg_verifybackup.obj : error LNK2019: unresolved external symbol
__BitScanReverse64 referenced in function _manifest_files_compute_parameters
[F:\repo\postgresql\pg_verifybackup.vcxproj]
```

### related lines
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/port/pg_bitutils.h;hb=83a61...
 
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/port/pg_bitutils.h;hb=83a61...
 

### references
https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64?view=msvc-170#requi...
 
https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64?view=msvc-170#requi...
 

### steps to reproduce
```cmd
"C:\Program Files\Microsoft Visual
Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=x86
-arch=x86
cd F:\repo\postgresql\src\tools\msvc
set PATH=F:\repo\tools;F:\tools\gnuwin32\bin;%PATH%
build RELEASE
cd F:\repo\postgresql
msbuild /m /p:Platform=Win32 /p:Configuration=Release
/p:PlatformToolset=v143 /p:WindowsTargetPlatformVersion=10.0.22621.0
pgsql.sln /verbosity:normal /t:Rebuild 2>&1
```



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen
  2023-06-07 09:57 BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen PG Bug reporting form <noreply@postgresql.org>
@ 2023-06-07 13:00 ` David Rowley <dgrowleyml@gmail.com>
  2023-06-07 22:18   ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: David Rowley @ 2023-06-07 13:00 UTC (permalink / raw)
  To: moyoumiu@outlook.com; pgsql-bugs@lists.postgresql.org

On Wed, 7 Jun 2023 at 23:26, PG Bug reporting form
<noreply@postgresql.org> wrote:
> The file `src/bin/pg_verifybackup/pg_verifybackup.c` fails to compile using
> msvc under x86, there is no `_BitScanForward64` and `_BitScanReverse64`
> under **x86** for head `src/include/port/pg_bitutils.h`.

I guess not many people are building on 32-bit MSVC these days.

I've not tested it, but I imagine the attached patch should fix it.

The ARM-64 part I included in the patch is just future-proofing.
Maybe I shouldn't bother with it.

David

Attachments:

dont_use_64-bit_bitscans_on_32bit_msvc_builds.patch (application/octet-stream, 754B) download diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h index 158ef73a2b..21a4fa0341 100644 --- a/src/include/port/pg_bitutils.h +++ b/src/include/port/pg_bitutils.h @@ -81,7 +81,7 @@ pg_leftmost_one_pos64(uint64 word) #error must have a working 64-bit integer datatype #endif /* HAVE_LONG_INT_64 */ -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_ARM64)) unsigned long result; bool non_zero; @@ -152,7 +152,7 @@ pg_rightmost_one_pos64(uint64 word) #error must have a working 64-bit integer datatype #endif /* HAVE_LONG_INT_64 */ -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_ARM64)) unsigned long result; bool non_zero;
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen
  2023-06-07 09:57 BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen PG Bug reporting form <noreply@postgresql.org>
  2023-06-07 13:00 ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
@ 2023-06-07 22:18   ` David Rowley <dgrowleyml@gmail.com>
  2023-06-08 07:56     ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen Mo Youmiu <moyoumiu@outlook.com>
  0 siblings, 1 reply; 5+ messages in thread

From: David Rowley @ 2023-06-07 22:18 UTC (permalink / raw)
  To: moyoumiu@outlook.com; pgsql-bugs@lists.postgresql.org

On Thu, 8 Jun 2023 at 01:00, David Rowley <dgrowleyml@gmail.com> wrote:
> I've not tested it, but I imagine the attached patch should fix it.

I've just pushed that patch to master only.

I noticed your report mentioned that this was for version 15.3. I
assumed this was a mistake as I didn't see any usage of the bit
scanning functions in v15. Commit 677319746 [1] introduced these,
which is new to v16.

Many thanks for reporting this!

David

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=677319746





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen
  2023-06-07 09:57 BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen PG Bug reporting form <noreply@postgresql.org>
  2023-06-07 13:00 ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
  2023-06-07 22:18   ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
@ 2023-06-08 07:56     ` Mo Youmiu <moyoumiu@outlook.com>
  2023-06-12 10:54       ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Mo Youmiu @ 2023-06-08 07:56 UTC (permalink / raw)
  To: David Rowley <dgrowleyml@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

Thanks for your replies and corrections, and apologies for the confusing version I mentioned.

For this commit, PostgreSQL was successfully built with msvc on both x86 and amd64.

Glad my report was helpful.

Mo

________________________________
From: David Rowley <dgrowleyml@gmail.com>
Sent: Thursday, June 8, 2023 6:18
To: moyoumiu@outlook.com <moyoumiu@outlook.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen

On Thu, 8 Jun 2023 at 01:00, David Rowley <dgrowleyml@gmail.com> wrote:
> I've not tested it, but I imagine the attached patch should fix it.

I've just pushed that patch to master only.

I noticed your report mentioned that this was for version 15.3. I
assumed this was a mistake as I didn't see any usage of the bit
scanning functions in v15. Commit 677319746 [1] introduced these,
which is new to v16.

Many thanks for reporting this!

David

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=677319746

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen
  2023-06-07 09:57 BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen PG Bug reporting form <noreply@postgresql.org>
  2023-06-07 13:00 ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
  2023-06-07 22:18   ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen David Rowley <dgrowleyml@gmail.com>
  2023-06-08 07:56     ` Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen Mo Youmiu <moyoumiu@outlook.com>
@ 2023-06-12 10:54       ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Alvaro Herrera @ 2023-06-12 10:54 UTC (permalink / raw)
  To: Mo Youmiu <moyoumiu@outlook.com>; +Cc: David Rowley <dgrowleyml@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

Hello Mo Youmiu,

On 2023-Jun-08, Mo Youmiu wrote:

> Thanks for your replies and corrections, and apologies for the confusing version I mentioned.
> 
> For this commit, PostgreSQL was successfully built with msvc on both x86 and amd64.
> 
> Glad my report was helpful.

You know what else would be extremely helpful?  A buildfarm animal that
runs with this configuration.  We should have noticed this problem as
soon as that problematic commit was introduced; a buildfarm animal would
have alerted us to it pretty much immediately rather than four months
after the fact.  Would you be in a position to running one?  It's a
moderately easy task, you just need to keep a machine (or VM) running
permanently.  You can find instructions here:
https://wiki.postgresql.org/wiki/PostgreSQL_Buildfarm_Howto

Regards

-- 
Álvaro Herrera





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2023-06-12 10:54 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 09:57 BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen PG Bug reporting form <noreply@postgresql.org>
2023-06-07 13:00 ` David Rowley <dgrowleyml@gmail.com>
2023-06-07 22:18   ` David Rowley <dgrowleyml@gmail.com>
2023-06-08 07:56     ` Mo Youmiu <moyoumiu@outlook.com>
2023-06-12 10:54       ` Alvaro Herrera <alvherre@alvh.no-ip.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox