Skip to content

Commit

Permalink
Windows executables: only load imported DLLs from System32 (#89311)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AustinWise authored Aug 29, 2023
1 parent 8a2cc6d commit 9c3f8b3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ add_compile_definitions("$<$<OR:$<CONFIG:RELEASE>,$<CONFIG:RELWITHDEBINFO>>:NDEB
if (MSVC)
add_linker_flag(/guard:cf)

# Load all imported DLLs from the System32 directory.
add_linker_flag(/DEPENDENTLOADFLAG:0x800)

# Linker flags
#
set (WINDOWS_SUBSYSTEM_VERSION 6.01)
Expand Down
4 changes: 4 additions & 0 deletions eng/native/ijw/IJW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ if (CLR_CMAKE_HOST_WIN32)
remove_ijw_incompatible_options("${dirCompileOptions}" dirCompileOptions)
set_directory_properties(PROPERTIES COMPILE_OPTIONS "${dirCompileOptions}")

# IJW tests needs to load DLLs from somewhere other than System32
string(REPLACE "/DEPENDENTLOADFLAG:0x800" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "/DEPENDENTLOADFLAG:0x800" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")

set(CLR_SDK_REF_PACK_OUTPUT "")
set(CLR_SDK_REF_PACK_DISCOVERY_ERROR "")
set(CLR_SDK_REF_PACK_DISCOVERY_RESULT 0)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/build-runtime.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ if %__BuildNative% EQU 1 (
goto ExitWithCode
)

@REM Temporarily disabling PGO until updated files with new linker flag are available.
@REM https://github.com/dotnet/runtime/pull/89311
GOTO :SkipNativeBuild

if %__EnforcePgo% EQU 1 (
set PgoCheckCmd="!PYTHON!" "!__ProjectDir!\scripts\pgocheck.py" "!__BinDir!\coreclr.dll" "!__BinDir!\clrjit.dll"
echo !PgoCheckCmd!
Expand Down
8 changes: 5 additions & 3 deletions src/coreclr/pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function(add_pgo TargetName)
message("Cannot use PGO optimization built with Ninja from MSBuild. Re-run build with Ninja to apply PGO information")
else(NOT EXISTS ${ProfilePath})
if(CLR_CMAKE_HOST_WIN32)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
add_compile_definitions(WITH_NATIVE_PGO)
# Temporarily disabling PGO until updated files with new linker flag are available.
# https://github.com/dotnet/runtime/pull/89311
# set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
# set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
# add_compile_definitions(WITH_NATIVE_PGO)
else(CLR_CMAKE_HOST_WIN32)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16))
Expand Down

0 comments on commit 9c3f8b3

Please sign in to comment.