Skip to content

Conversation

@youngwise
Copy link

Fix Windows build issues: OSSL_provider_init export and C4702 unreachable code

This PR fixes two issues encountered when building and running gost-engine on Windows using MSVC.

1. Fix missing export for OSSL_provider_init

Problem
When attempting to load the provider on Windows, OpenSSL fails with the following error:

1C240000:error:1280006A:DSO support routines:win32_bind_func:could not bind to the requested symbol name:crypto\dso\dso_win32.c:182:symname(OSSL_provider_init)
1C240000:error:1280006A:DSO support routines:DSO_bind_func:could not bind to the requested symbol name:crypto\dso\dso_lib.c:171:
1C240000:error:0788010C:common libcrypto routines:provider_init:unsupported:crypto\provider_core.c:962:name=gostprov, provider has no provider init function

Cause
On Windows, the entry point function OSSL_provider_init must be explicitly exported from the DLL. While OPENSSL_EXPORT is used, in some build configurations with MSVC and macro aliasing, the symbol might not be correctly added to the export table.

Solution
Added #pragma comment(linker, "/EXPORT:OSSL_provider_init") for Windows builds to ensure the symbol is visible to OpenSSL's DSO loader regardless of the build environment specifics.

2. Fix MSVC Warning/Error C4702 (Unreachable Code)

Problem
Build fails in Release configuration with the following error:

[ 95%] Building C object CMakeFiles/gost12sum.dir/gost12sum.c.obj gost12sum.c
engine\gost12sum.c(91) : error C2220: following warning treated as error
engine\gost12sum.c(91) : warning C4702: unreachable code

Cause
In gost12sum.c, the help() function internally calls exit(). Therefore, the exit(0) following the help() call in the switch statement is unreachable. This triggers a compiler error when "Warnings as Errors" is enabled.

Solution
Removed the redundant exit(0) call after help().

Environment

  • OS: Windows 11 Pro 25H2 x64
  • Compiler: Visual Studio 2026 Community (v18.2.1) / MSVC Toolset v14.50.18.0
  • OpenSSL Version: OpenSSL 3.6.0 1 Oct 2025 (Library: OpenSSL 3.6.0 1 Oct 2025)

@chipitsine
Copy link
Contributor

we do have windows builds in CI

https://github.com/gost-engine/engine/blob/201c1f9a24918626fb9d10e0f5b47c4e19686806/.github/workflows/windows.yml

no issues encountered. can you provide repro steps ?
or compare steps taken by you with listed in workflow file

@chipitsine
Copy link
Contributor

btw, your pull request seems to failed on CI, please have a look

@youngwise
Copy link
Author

Thanks for the feedback! I investigated the differences between the CI environment and my setup, and here is what I found:

1. Regarding the export issue (OSSL_provider_init):
The CI uses windows-latest (currently Visual Studio 2022 / MSVC 19.4x). I am building with Visual Studio 2026 (MSVC 19.5x).
It appears that the newer MSVC toolset handles symbol aliasing differently, causing __declspec(dllexport) to be ignored for the aliased OSSL_provider_init symbol. I verified this with dumpbin /exports: the export table was empty on my build without the fix.

MSVC 19.5 (Visual Studio 26):

Microsoft (R) COFF/PE Dumper Version 14.50.35723.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file bin\Debug\gostprov.dll

File Type: DLL

  Summary

        1000 .00cfg
        F000 .data
        5000 .idata
        4000 .pdata
      19B000 .rdata
        A000 .reloc
        1000 .rsrc
       FD000 .text

MSVC 19.4 (Visual Studio 22):

Microsoft (R) COFF/PE Dumper Version 14.44.35222.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file bin\Debug\gostprov.dll

File Type: DLL

  Section contains the following exports for gostprov.dll

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names

    ordinal hint RVA      name

          1    0 0000122B OSSL_provider_init = @ILT+550(OSSL_provider_init)

  Summary

        1000 .00cfg
        F000 .data
        5000 .idata
        4000 .pdata
      19B000 .rdata
        A000 .reloc
        1000 .rsrc
       FE000 .text

Update:
Instead of adding #pragma to the source code, I modified CMakeLists.txt to use target_link_options for MSVC. This explicitly forces the export at the linker level:

if(MSVC)
  target_link_options(gost_prov PRIVATE "/EXPORT:OSSL_provider_init")
endif()

2. Regarding the unreachable code (C4702):
The CI workflow runs tests in Debug mode. The C4702 error occurs specifically in Release builds where MSVC performs aggressive static analysis and detects that exit(0) after help() is unreachable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants