From 9dc862d0b7fbb31c150501f6d11dfe81bbfa673c Mon Sep 17 00:00:00 2001 From: Gaurav Khanna Date: Fri, 29 Apr 2016 08:00:17 -0700 Subject: [PATCH] Enable crossgen to load JIT from a custom location Continue to link the JIT in for Windows Arm64 builds until 4717 is fixed. --- clrdefinitions.cmake | 4 ++++ src/inc/zapper.h | 7 ++++++ src/tools/crossgen/crossgen.cpp | 25 ++++++++++++++++++++- src/zap/zapper.cpp | 50 +++++++++++++++++++++++++++++++---------- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/clrdefinitions.cmake b/clrdefinitions.cmake index c5352c0..58b9ad2 100644 --- a/clrdefinitions.cmake +++ b/clrdefinitions.cmake @@ -134,7 +134,11 @@ add_definitions(-DFEATURE_MERGE_CULTURE_SUPPORT_AND_ENGINE) # TODO_DJIT: Remove this "set" to commence loading JIT dynamically. if(NOT WIN32) set(FEATURE_MERGE_JIT_AND_ENGINE 1) +elseif (CLR_CMAKE_TARGET_ARCH_ARM64) + # TODO_DJIT: Remove this as part of enabling cross-compiling standalone JIT binary. + set(FEATURE_MERGE_JIT_AND_ENGINE 1) endif(NOT WIN32) + if(FEATURE_MERGE_JIT_AND_ENGINE) # Disable the following for UNIX altjit on Windows add_definitions(-DFEATURE_MERGE_JIT_AND_ENGINE) diff --git a/src/inc/zapper.h b/src/inc/zapper.h index 1ff429e..0f92e85 100644 --- a/src/inc/zapper.h +++ b/src/inc/zapper.h @@ -124,6 +124,9 @@ class Zapper SString m_platformWinmdPaths; #endif // FEATURE_CORECLR || CROSSGEN_COMPILE +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + SString m_CLRJITPath; +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) bool m_fForceFullTrust; SString m_outputFilename; @@ -445,6 +448,10 @@ class Zapper void SetForceFullTrust(bool val); #endif // FEATURE_CORECLR || CROSSGEN_COMPILE +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + void SetCLRJITPath(LPCWSTR pwszCLRJITPath); +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + void SetOutputFilename(LPCWSTR pwszOutputFilename); SString GetOutputFileName(); diff --git a/src/tools/crossgen/crossgen.cpp b/src/tools/crossgen/crossgen.cpp index 6998354..f174f22 100644 --- a/src/tools/crossgen/crossgen.cpp +++ b/src/tools/crossgen/crossgen.cpp @@ -34,7 +34,7 @@ enum ReturnValues #define NumItems(s) (sizeof(s) / sizeof(s[0])) STDAPI CreatePDBWorker(LPCWSTR pwzAssemblyPath, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzAppNiPaths, LPCWSTR pwzPdbPath, BOOL fGeneratePDBLinesInfo, LPCWSTR pwzManagedPdbSearchPath, LPCWSTR pwzPlatformWinmdPaths); -STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL); +STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL, LPCWSTR pwszCLRJITPath = nullptr); void SetSvcLogger(ICorSvcLogger *pCorSvcLogger); #ifdef FEATURE_CORECLR void SetMscorlibPath(LPCWSTR wzSystemDirectory); @@ -155,6 +155,10 @@ void PrintUsageHelper() W(" /Tuning - Generate an instrumented image to collect\n") W(" scenario traces, which can be used with ibcmerge.exe\n") #endif +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + W(" /JITPath\n") + W(" - Specifies the absolute file path to JIT compiler to be used.\n") +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) #ifdef FEATURE_READYTORUN_COMPILER W(" /ReadyToRun - Generate images resilient to the runtime and\n") W(" dependency versions\n") @@ -450,6 +454,10 @@ int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv) LPCWSTR pwzOutputFilename = NULL; LPCWSTR pwzPublicKeys = nullptr; +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + LPCWSTR pwszCLRJITPath = nullptr; +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + HRESULT hr; #ifndef PLATFORM_UNIX @@ -526,6 +534,16 @@ int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv) // We dont explicitly set the flag here again so that if "/PartialTrust" is specified, then it will successfully override the default // fulltrust behaviour. } +#if !defined(FEATURE_MERGE_JIT_AND_ENGINE) + else if (MatchParameter(*argv, W("JITPath")) && (argc > 1)) + { + pwszCLRJITPath = argv[1]; + + // skip JIT Path + argv++; + argc--; + } +#endif // !defined(FEATURE_MERGE_JIT_AND_ENGINE) #endif #ifdef FEATURE_WINMD_RESILIENT else if (MatchParameter(*argv, W("WinMDResilient"))) @@ -925,6 +943,11 @@ int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv) pwzAppPaths, pwzOutputFilename, pwzPlatformWinmdPaths +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + , + NULL, // ICorSvcLogger + pwszCLRJITPath +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) ); } diff --git a/src/zap/zapper.cpp b/src/zap/zapper.cpp index 80ab2ef..e2182fe 100644 --- a/src/zap/zapper.cpp +++ b/src/zap/zapper.cpp @@ -142,7 +142,7 @@ static HRESULT GetAssemblyName( #if defined(FEATURE_CORECLR) || defined(CROSSGEN_COMPILE) -STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL) +STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL, LPCWSTR pwszCLRJITPath = nullptr) { HRESULT hr = S_OK; @@ -209,6 +209,11 @@ STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembl if (pwzPlatformWinmdPaths != nullptr) zap->SetPlatformWinmdPaths(pwzPlatformWinmdPaths); +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + if (pwszCLRJITPath != nullptr) + zap->SetCLRJITPath(pwszCLRJITPath); +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + zap->SetForceFullTrust(!!(dwFlags & NGENWORKER_FLAGS_FULLTRUSTDOMAIN)); g_fNGenMissingDependenciesOk = !!(dwFlags & NGENWORKER_FLAGS_MISSINGDEPENDENCIESOK); @@ -698,24 +703,38 @@ void Zapper::LoadAndInitializeJITForNgen(LPCWSTR pwzJitName, OUT HINSTANCE* phJi #if defined(FEATURE_CORECLR) || defined(FEATURE_MERGE_JIT_AND_ENGINE) // Note: FEATURE_MERGE_JIT_AND_ENGINE is defined for the Desktop crossgen compilation as well. // - // For Crossgen, we always look up the JIT from the same location as CoreCLR. PathString CoreClrFolder; extern HINSTANCE g_hThisInst; + +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + if (m_CLRJITPath.GetCount() > 0) + { + // If we have been asked to load a specific JIT binary, load it. + CoreClrFolder.Set(m_CLRJITPath); + hr = S_OK; + } + else +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) if (WszGetModuleFileName(g_hThisInst, CoreClrFolder)) { - if (SUCCEEDED(CopySystemDirectory(CoreClrFolder, CoreClrFolder))) + hr = CopySystemDirectory(CoreClrFolder, CoreClrFolder); + if (SUCCEEDED(hr)) { CoreClrFolder.Append(pwzJitName); - *phJit = ::WszLoadLibrary(CoreClrFolder); - if (*phJit == NULL) - { - hr = HRESULT_FROM_GetLastError(); - } - else - { - hr = S_OK; - } + } + } + + if (SUCCEEDED(hr)) + { + *phJit = ::WszLoadLibrary(CoreClrFolder); + if (*phJit == NULL) + { + hr = HRESULT_FROM_GetLastError(); + } + else + { + hr = S_OK; } } #else @@ -4013,6 +4032,13 @@ void Zapper::PrintErrorMessage(CorZapLogLevel level, HRESULT hr) Print(level, W("%s"), message.GetUnicode()); } +#if defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) +void Zapper::SetCLRJITPath(LPCWSTR pwszCLRJITPath) +{ + m_CLRJITPath.Set(pwszCLRJITPath); +} +#endif // defined(FEATURE_CORECLR) && !defined(FEATURE_MERGE_JIT_AND_ENGINE) + #if defined(FEATURE_CORECLR) || defined(CROSSGEN_COMPILE) void Zapper::SetPlatformAssembliesPaths(LPCWSTR pwzPlatformAssembliesPaths) -- 2.7.4