'MSVC C++ find out what function requires linker symbol

I have a special situation. In my project the kernel32.lib is replaced by a substition library (Windows realtime extension RTX). So I do not link to kernel32.lib, user32.lib, etc.

This substitution library (rtapi.lib) is supposed to have the same external ABI as the kernel32 library. This all worked fine when compiling under Visual Studio 2019. But now I would like to upgrade to Visual Studio 2022 and all of a sudden I get a number of linker errors:

1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SetFileInformationByHandle referenced in function __crtSetFileInformationByHandle
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_InitializeSRWLock referenced in function __crtInitializeSRWLock
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_ReleaseSRWLockExclusive referenced in function __crtReleaseSRWLockExclusive
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_AcquireSRWLockExclusive referenced in function __crtAcquireSRWLockExclusive
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_InitializeConditionVariable referenced in function __crtInitializeConditionVariable
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_WakeConditionVariable referenced in function __crtWakeConditionVariable
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_WakeAllConditionVariable referenced in function __crtWakeAllConditionVariable
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SleepConditionVariableCS referenced in function __crtSleepConditionVariableCS
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SleepConditionVariableSRW referenced in function __crtSleepConditionVariableSRW
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateEventExW referenced in function __crtCreateEventExW
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateSemaphoreExW referenced in function __crtCreateSemaphoreExW
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_FlushProcessWriteBuffers referenced in function __crtFlushProcessWriteBuffers
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_FreeLibraryWhenCallbackReturns referenced in function __crtFreeLibraryWhenCallbackReturns
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateThreadpoolWork referenced in function __crtCreateThreadpoolWork
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SubmitThreadpoolWork referenced in function __crtSubmitThreadpoolWork
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CloseThreadpoolWork referenced in function __crtCloseThreadpoolWork
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateThreadpoolTimer referenced in function __crtCreateThreadpoolTimer
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SetThreadpoolTimer referenced in function __crtSetThreadpoolTimer
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_WaitForThreadpoolTimerCallbacks referenced in function __crtWaitForThreadpoolTimerCallbacks
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CloseThreadpoolTimer referenced in function __crtCloseThreadpoolTimer
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateThreadpoolWait referenced in function __crtCreateThreadpoolWait
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SetThreadpoolWait referenced in function __crtSetThreadpoolWait
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CloseThreadpoolWait referenced in function __crtCloseThreadpoolWait
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_GetFileInformationByHandleEx referenced in function __crtGetFileInformationByHandleEx
1>libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateSymbolicLinkW referenced in function __crtCreateSymbolicLinkW

My guess is that in winapisupp.cpp which is part of the STL requires now some newer functions in kernel32. My guess is that the newer version of the STL uses some function to support the new parallel alrogithms. Therefore it requires os services like a task scheduler or a thread pool. In the source code on github I see this:

// TRANSITION, ABI: preserved for binary compatibility
extern "C" VOID __cdecl __crtSubmitThreadpoolWork(_Inout_ PTP_WORK const pwk) {
    SubmitThreadpoolWork(pwk);
}

and

STOREFUNCTIONPOINTER(hKernel32, SubmitThreadpoolWork);

The next step that I tried was to diff the output of dumpbin for the two versions of libcpmtd.lib

PS C:\> dumpbin /all "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.29.30133\lib\x64\libcpmtd.lib" > c:\dev\libcpmtd.lib.2022.sym
PS C:\> dumpbin /all "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\lib\x64\libcpmtd.lib" > c:\dev\libcpmtd.lib.2019.sym

In the diff between these two versions I see that in the 2022 version 70 symbols have been added. Among them, these I got from the linker errors.

So my program calls a function that calls through many sub calls, for example the __crtSubmitThreadpoolWork function. My question now is how I can find out what call graph requires this function?

It would help if the STL had a #define to avoid using these new kernel32 functions (like e.g. DISABLE_PARALLEL_ALGORITHMS). But since I doubt that this is available, I need to replace the parts of the STL that requires these by another library (maybe absl?)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source