Skip to content

Commit 9c3f8b3

Browse files
authored
Windows executables: only load imported DLLs from System32 (dotnet#89311)
By using the /DEPENDENTLOADFLAG link.exe flag, we can tell the Windows loader to only look for referenced DLLs in the System32 directory. The application of PGO is commented out until updated PGO files are available.
1 parent 8a2cc6d commit 9c3f8b3

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

eng/native/configurecompiler.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ add_compile_definitions("$<$<OR:$<CONFIG:RELEASE>,$<CONFIG:RELWITHDEBINFO>>:NDEB
5656
if (MSVC)
5757
add_linker_flag(/guard:cf)
5858

59+
# Load all imported DLLs from the System32 directory.
60+
add_linker_flag(/DEPENDENTLOADFLAG:0x800)
61+
5962
# Linker flags
6063
#
6164
set (WINDOWS_SUBSYSTEM_VERSION 6.01)

eng/native/ijw/IJW.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ if (CLR_CMAKE_HOST_WIN32)
7070
remove_ijw_incompatible_options("${dirCompileOptions}" dirCompileOptions)
7171
set_directory_properties(PROPERTIES COMPILE_OPTIONS "${dirCompileOptions}")
7272

73+
# IJW tests needs to load DLLs from somewhere other than System32
74+
string(REPLACE "/DEPENDENTLOADFLAG:0x800" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
75+
string(REPLACE "/DEPENDENTLOADFLAG:0x800" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
76+
7377
set(CLR_SDK_REF_PACK_OUTPUT "")
7478
set(CLR_SDK_REF_PACK_DISCOVERY_ERROR "")
7579
set(CLR_SDK_REF_PACK_DISCOVERY_RESULT 0)

src/coreclr/build-runtime.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ if %__BuildNative% EQU 1 (
428428
goto ExitWithCode
429429
)
430430

431+
@REM Temporarily disabling PGO until updated files with new linker flag are available.
432+
@REM https://github.com/dotnet/runtime/pull/89311
433+
GOTO :SkipNativeBuild
434+
431435
if %__EnforcePgo% EQU 1 (
432436
set PgoCheckCmd="!PYTHON!" "!__ProjectDir!\scripts\pgocheck.py" "!__BinDir!\coreclr.dll" "!__BinDir!\clrjit.dll"
433437
echo !PgoCheckCmd!

src/coreclr/pgosupport.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ function(add_pgo TargetName)
5959
message("Cannot use PGO optimization built with Ninja from MSBuild. Re-run build with Ninja to apply PGO information")
6060
else(NOT EXISTS ${ProfilePath})
6161
if(CLR_CMAKE_HOST_WIN32)
62-
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
63-
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
64-
add_compile_definitions(WITH_NATIVE_PGO)
62+
# Temporarily disabling PGO until updated files with new linker flag are available.
63+
# https://github.com/dotnet/runtime/pull/89311
64+
# set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
65+
# set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
66+
# add_compile_definitions(WITH_NATIVE_PGO)
6567
else(CLR_CMAKE_HOST_WIN32)
6668
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
6769
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16))

0 commit comments

Comments
 (0)