libressl / portable

LibreSSL Portable itself. This includes the build scaffold and compatibility layer that builds portable LibreSSL from the OpenBSD source code. Pull requests or patches sent to tech@openbsd.org are welcome.
https://www.libressl.org
1.37k stars 265 forks source link

3.9.2 fails to build in release mode on windows #1089

Open d3x0r opened 2 months ago

d3x0r commented 2 months ago

266 has a reference to _CrtSetReportMode so I assume it was added because of this

'_CrtSetReportMode' is only available in the debug c runtime... according to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode?view=msvc-170

Libraries: Debug versions of the C runtime libraries only.

Unfortunately _DEBUG which is normally defined by Visual studio default projects isn't set when cmake generates the project file (without additional code in the cmakelists)

But then RelWithDebugInfo cmake builds link against release runtime, but should also have _DEBUG enabled... I added a few lines like the following to the cmake lists and then put #if defined _MSC_VER && _MSC_VER >= 1900 && defined( _DEBUG ) && !defined( _REL_DEBUG ) around the code in crypto\compat\posix_win.c that defines using _CrtSetReportMode..

if( ${CMAKE_BUILD_TYPE} MATCHES "[rR][eE][lL][wW][iI].*" )
   ADD_DEFINITIONS( -D_REL_DEBUG )
endif()

if( ${CMAKE_BUILD_TYPE} MATCHES "[dD][eE][bB][uU][gG]"
   OR ${CMAKE_BUILD_TYPE} MATCHES "[rR][eE][lL][wW][iI].*" )
   ADD_DEFINITIONS( -D_DEBUG )
endif()

as a side note, NDEBUG is defined for release builds of projects created by Visual Studio, and again, not by CMake.

datadiode commented 1 month ago

My understanding is that a RelWithDebugInfo cmake build should see the exact same source code as a Release cmake build. For either of them, I'd expect _DEBUG to not be defined.

d3x0r commented 1 month ago

other than it says 'With Debug Info' ...it's not part of visual studio's default practices... but even so...

https://github.com/libressl/portable/blob/master/crypto/compat/posix_win.c#L155

has no specification of debug or release, so it will just build if MSVC, which under release will fail or relwithdebug info (since they should both link against release runtime) regardless of whether debug in the app/library is enabled.

datadiode commented 1 month ago

https://learn.microsoft.com/en-us/cpp/c-runtime-library/debug?view=msvc-170 should make it clear enough.