Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c866593

Browse files
PGI: Load pgort<ver>.dll from the VS native tools env; do not install it (#15114)
On Windows, PGO instrumented builds (build.cmd release <arch> pgoinstrument) introduce a runtime dependency on pgort<ver>.dll for instrumented binaries. This DLL is distributed alongside the C++ compiler, and is made available via the native tools environment that ships with Visual Studio. Previously, we were using cmake to find and "install" this binary alongside the product when doing an instrumented build, so that the resulting bin\Product drop is free of any added external dependencies. However, this approach is fragile, and despite a best effort to make the implementation work across multiple VS releases, it already broke with VS 2017. To fix support for pgoinstrument on VS 2017, and to harden the implementation for future releases of VS, I'm removing the custom cmake install logic for the pgort DLL. Instead, we fall back to the officially supported method: load the correct (native tools) environment before invoking any command that uses an instrumented binary. This happens in one place in the build today--loading the JIT to crossgen System.Private.CoreLib.dll. Note that there's still an existing CLI/Setup bug that requires copying the pgort DLL. We're now doing it from within build.cmd, which is not nearly as fragile for this as cmake is. The workaround is also isolated, so when the referenced issue is fixed, the workaround (as documented) can simply be removed.
1 parent 6a89074 commit c866593

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

build.cmd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,31 @@ set PATH=%PATH%;%WinDir%\Microsoft.Net\Framework64\V4.0.30319;%WinDir%\Microsoft
456456
if %__BuildNativeCoreLib% EQU 1 (
457457
echo %__MsgPrefix%Generating native image of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType%
458458

459+
REM Need VS native tools environment for the **target** arch when running instrumented binaries
460+
if %__PgoInstrument% EQU 1 (
461+
set __VCExecArch=%__BuildArch%
462+
if /i [%__BuildArch%] == [x64] set __VCExecArch=amd64
463+
echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch!
464+
call "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch!
465+
@if defined _echo @echo on
466+
if NOT !errorlevel! == 0 (
467+
echo %__MsgPrefix%Error: Failed to load native tools environment for !__VCExecArch!
468+
goto CrossgenFailure
469+
)
470+
471+
REM HACK: Workaround for [dotnet/coreclr#13970](https://github.com/dotnet/coreclr/issues/13970)
472+
set __PgoRtPath=
473+
for /f "tokens=*" %%f in ('where pgort*.dll') do (
474+
if not defined __PgoRtPath set "__PgoRtPath=%%~f"
475+
)
476+
echo %__MsgPrefix%Copying "!__PgoRtPath!" into "%__BinDir%"
477+
copy /y "!__PgoRtPath!" "%__BinDir%" || (
478+
echo %__MsgPrefix%Error: copy failed
479+
goto CrossgenFailure
480+
)
481+
REM End HACK
482+
)
483+
459484
echo "%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%"\IL /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll"
460485
"%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%"\IL /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll" > "%__CrossGenCoreLibLog%" 2>&1
461486
if NOT !errorlevel! == 0 (

pgosupport.cmake

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,3 @@ function(add_pgo TargetName)
5757
endif(EXISTS ${ProfilePath})
5858
endif(CLR_CMAKE_PGO_INSTRUMENT)
5959
endfunction(add_pgo)
60-
61-
if(WIN32)
62-
if(CLR_CMAKE_PGO_INSTRUMENT)
63-
# Instrumented PGO binaries on Windows introduce an additional runtime dependency, pgort<ver>.dll.
64-
# Make sure we copy it next to the installed product to make it easier to redistribute the package.
65-
66-
string(SUBSTRING ${CMAKE_VS_PLATFORM_TOOLSET} 1 -1 VS_PLATFORM_VERSION_NUMBER)
67-
set(PGORT_FILENAME "pgort${VS_PLATFORM_VERSION_NUMBER}.dll")
68-
69-
get_filename_component(PATH_CXX_ROOTDIR ${CMAKE_CXX_COMPILER} DIRECTORY)
70-
71-
if(CLR_CMAKE_PLATFORM_ARCH_I386)
72-
set(PATH_VS_PGORT_DLL "${PATH_CXX_ROOTDIR}/${PGORT_FILENAME}")
73-
elseif(CLR_CMAKE_PLATFORM_ARCH_AMD64)
74-
set(PATH_VS_PGORT_DLL "${PATH_CXX_ROOTDIR}/../amd64/${PGORT_FILENAME}")
75-
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
76-
set(PATH_VS_PGORT_DLL "${PATH_CXX_ROOTDIR}/../arm/${PGORT_FILENAME}")
77-
else()
78-
clr_pgo_unknown_arch()
79-
endif()
80-
81-
if (EXISTS ${PATH_VS_PGORT_DLL})
82-
message(STATUS "Found PGO runtime: ${PATH_VS_PGORT_DLL}")
83-
install(PROGRAMS ${PATH_VS_PGORT_DLL} DESTINATION .)
84-
else()
85-
message(FATAL_ERROR "file not found: ${PATH_VS_PGORT_DLL}")
86-
endif()
87-
88-
endif(CLR_CMAKE_PGO_INSTRUMENT)
89-
endif(WIN32)

0 commit comments

Comments
 (0)