From 8d3d7eaac5e4242ae30c4ad334b558d6cbd1e53a Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 14 Jun 2023 06:40:36 -0700 Subject: [PATCH] Add delay load hook for singlefilehost and enable delay load of version.dll (#87495) `coreclr` delay loads `version.dll` and adds a hook such that it loads from the system directory. In single-file, we lost this behaviour since it uses static library version of `coreclr`. This adds the same mechanism to single-file. --- src/coreclr/dlls/mscoree/CMakeLists.txt | 2 +- src/native/corehost/apphost/static/CMakeLists.txt | 7 ++++++- .../libs/Common/delayloadhook_windows.cpp} | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) rename src/{coreclr/dlls/mscoree/delayloadhook.cpp => native/libs/Common/delayloadhook_windows.cpp} (97%) diff --git a/src/coreclr/dlls/mscoree/CMakeLists.txt b/src/coreclr/dlls/mscoree/CMakeLists.txt index dc22c27..7856557 100644 --- a/src/coreclr/dlls/mscoree/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/CMakeLists.txt @@ -11,7 +11,7 @@ set(CLR_SOURCES if(CLR_CMAKE_TARGET_WIN32) list(APPEND CLR_SOURCES - delayloadhook.cpp + ${CLR_SRC_NATIVE_DIR}/libs/Common/delayloadhook_windows.cpp Native.rc ) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index c491311..5fa0663 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -56,7 +56,9 @@ endif() if(CLR_CMAKE_TARGET_WIN32) add_definitions(-DUNICODE) list(APPEND SOURCES - ../apphost.windows.cpp) + ../apphost.windows.cpp + ${CLR_SRC_NATIVE_DIR}/libs/Common/delayloadhook_windows.cpp + ) list(APPEND HEADERS ../apphost.windows.h) @@ -106,6 +108,9 @@ if(CLR_CMAKE_TARGET_WIN32) # Delay load libraries required for WinRT as that is not supported on all platforms add_linker_flag("/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll") + + # Delay load version.dll so that we can specify how to search when loading it as it is not part of Windows' known DLLs + add_linker_flag("/DELAYLOAD:version.dll") endif() if(CLR_CMAKE_TARGET_WIN32) diff --git a/src/coreclr/dlls/mscoree/delayloadhook.cpp b/src/native/libs/Common/delayloadhook_windows.cpp similarity index 97% rename from src/coreclr/dlls/mscoree/delayloadhook.cpp rename to src/native/libs/Common/delayloadhook_windows.cpp index b09cd75..901ac56 100644 --- a/src/coreclr/dlls/mscoree/delayloadhook.cpp +++ b/src/native/libs/Common/delayloadhook_windows.cpp @@ -4,8 +4,7 @@ // File: delayloadhook.cpp // -#include "stdafx.h" - +#include #include FARPROC WINAPI secureDelayHook(unsigned dliNotify, PDelayLoadInfo pdli) -- 2.7.4