Skip to content

Commit

Permalink
Prevent MSVC from merging identical functions - we need them to have …
Browse files Browse the repository at this point in the history
…separate pointer addresses
  • Loading branch information
fholger committed Jan 12, 2022
1 parent 8ff475f commit 50091df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ include_directories(
)

add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
# do not merge functions with identical bodies; we need them to be separate entities for hooking purposes
add_link_options("/OPT:NOICF")

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DWIN64)
Expand Down
7 changes: 2 additions & 5 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ namespace {
}

HMODULE WINAPI Hook_LoadLibraryW(LPCWSTR lpFileName) {
// necessary, or else VS merges this function with Hook_LoadLibraryA and assigns them the same address
std::wstring fileName (lpFileName);
HMODULE handle = vrperfkit::hooks::CallOriginal(Hook_LoadLibraryW)(fileName.c_str());
HMODULE handle = vrperfkit::hooks::CallOriginal(Hook_LoadLibraryW)(lpFileName);

if (handle != nullptr && handle != vrperfkit::g_moduleSelf) {
InstallVrHooks();
Expand All @@ -66,8 +64,7 @@ namespace {
}

HMODULE WINAPI Hook_LoadLibraryExW(LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags) {
std::wstring fileName (lpFileName);
HMODULE handle = vrperfkit::hooks::CallOriginal(Hook_LoadLibraryExW)(fileName.c_str(), hFile, dwFlags);
HMODULE handle = vrperfkit::hooks::CallOriginal(Hook_LoadLibraryExW)(lpFileName, hFile, dwFlags);

if (handle != nullptr && handle != vrperfkit::g_moduleSelf && (dwFlags & (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE)) == 0) {
InstallVrHooks();
Expand Down

0 comments on commit 50091df

Please sign in to comment.