Thread

Commits

  1. Don't use _BitScanForward64/_BitScanReverse64 on 32-bit MSVC builds

  2. Remove newly added asserts from pg_bitutils.h

  3. Add MSVC support for pg_leftmost_one_pos32() and friends

  1. BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen

    The Post Office <noreply@postgresql.org> — 2023-06-07T09:57:49Z

    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=83a611a259d41e305364b8de58f6b33a63cbda66#l88
     
    https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/port/pg_bitutils.h;hb=83a611a259d41e305364b8de58f6b33a63cbda66#l159
     
    
    ### references
    https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64?view=msvc-170#requirements
     
    https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64?view=msvc-170#requirements
     
    
    ### 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
    ```
    
    
  2. Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen

    David Rowley <dgrowleyml@gmail.com> — 2023-06-07T13:00:22Z

    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
    
  3. Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen

    David Rowley <dgrowleyml@gmail.com> — 2023-06-07T22:18:36Z

    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
    
    
    
    
  4. Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen

    Mo Youmiu <moyoumiu@outlook.com> — 2023-06-08T07:56:56Z

    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
    
  5. Re: BUG #17967: [msvc-x86] Failed to build with error LNK2019: unresolved external symbol __BitScanReverse64 referen

    Alvaro Herrera <alvherre@alvh.no-ip.org> — 2023-06-12T10:54:38Z

    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