From 7872a2baf13c728662c8b73daa8fad6002845523 Mon Sep 17 00:00:00 2001 From: vsadov Date: Sat, 17 Oct 2020 06:45:37 -0700 Subject: [PATCH 1/7] Statically linking coreclr and clrjit in single file host. --- src/coreclr/src/vm/ceemain.cpp | 6 ++ src/coreclr/src/vm/threads.cpp | 1 + .../cli/apphost/static/CMakeLists.txt | 57 ++++++++++--------- .../hostpolicy/static/coreclr_resolver.cpp | 29 ---------- .../netcoreapp/pkg/Directory.Build.props | 4 -- 5 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index d731c6d674ef1e..9d0a42ccfe5119 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -637,6 +637,12 @@ void EEStartupHelper() { g_fEEInit = true; +#if CORECLR_EMBEDDED + HINSTANCE curModule = WszGetModuleHandle(NULL); + g_hmodCoreCLR = curModule; + g_hThisInst = curModule; +#endif + #ifndef CROSSGEN_COMPILE // We cache the SystemInfo for anyone to use throughout the life of the EE. diff --git a/src/coreclr/src/vm/threads.cpp b/src/coreclr/src/vm/threads.cpp index 588de0e7a1115c..63e60f896313ca 100644 --- a/src/coreclr/src/vm/threads.cpp +++ b/src/coreclr/src/vm/threads.cpp @@ -1137,6 +1137,7 @@ void InitThreadManager() // All patched helpers should fit into one page. // If you hit this assert on retail build, there is most likely problem with BBT script. + _ASSERTE_ALL_BUILDS("clr/src/VM/threads.cpp", (BYTE*)JIT_PatchedCodeLast - (BYTE*)JIT_PatchedCodeStart > (ptrdiff_t)0); _ASSERTE_ALL_BUILDS("clr/src/VM/threads.cpp", (BYTE*)JIT_PatchedCodeLast - (BYTE*)JIT_PatchedCodeStart < (ptrdiff_t)GetOsPageSize()); #ifdef FEATURE_WRITEBARRIER_COPY diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index 0542a1155d0a08..22ae83ad0401f5 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -51,6 +51,10 @@ if(CLR_CMAKE_TARGET_WIN32) set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_FLAGS "/MANIFEST:NO" ) + + # Incremental linking results in the linker inserting extra padding and routing function calls via thunks that can break the + # invariants (e.g. size of region between Jit_PatchedCodeLast-Jit_PatchCodeStart needs to fit in a page). + add_linker_flag("/INCREMENTAL:NO") endif() # Specify non-default Windows libs to be used for Arm/Arm64 builds @@ -66,8 +70,8 @@ message ("Looking for coreclr_static lib at location: '${CORECLR_STATIC_LIB_LOCA if(CLR_CMAKE_TARGET_WIN32) set(CORECLR_LIBRARIES - # Disable superhost on Win32 for now. - # ${CORECLR_STATIC_LIB_LOCATION}/coreclr_static.lib + ${CORECLR_STATIC_LIB_LOCATION}/coreclr_static.lib + ${CORECLR_STATIC_LIB_LOCATION}/System.Globalization.Native.lib ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB} kernel32.lib @@ -81,7 +85,7 @@ if(CLR_CMAKE_TARGET_WIN32) bcrypt.lib RuntimeObject.lib ) -elseif(CLR_CMAKE_TARGET_LINUX) +else() set(CORECLR_LIBRARIES ${CORECLR_STATIC_LIB_LOCATION}/libcoreclr_static.a ${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a @@ -89,32 +93,29 @@ elseif(CLR_CMAKE_TARGET_LINUX) ${CORECLR_STATIC_LIB_LOCATION}/libeventprovider.a ${CORECLR_STATIC_LIB_LOCATION}/libnativeresourcestring.a ) +endif() - # currently linking coreclr into the singlefilehost is only supported on linux - # the following code here would be needed if/when BSD and OSX are supported too - # - # if(CLR_CMAKE_TARGET_OSX) - # find_library(COREFOUNDATION CoreFoundation) - # find_library(CORESERVICES CoreServices) - # find_library(SECURITY Security) - # find_library(SYSTEM System) - # - # LIST(APPEND CORECLR_LIBRARIES - # ${COREFOUNDATION} - # ${CORESERVICES} - # ${SECURITY} - # ${SYSTEM} - # ) - # endif(CLR_CMAKE_TARGET_OSX) - # - # if(CLR_CMAKE_TARGET_NETBSD) - # find_library(KVM kvm) - # - # LIST(APPEND CORECLR_LIBRARIES - # ${KVM} - # ) - # endif(CLR_CMAKE_TARGET_NETBSD) -endif(CLR_CMAKE_TARGET_WIN32) +if(CLR_CMAKE_TARGET_OSX) + find_library(COREFOUNDATION CoreFoundation) + find_library(CORESERVICES CoreServices) + find_library(SECURITY Security) + find_library(SYSTEM System) + + LIST(APPEND CORECLR_LIBRARIES + ${COREFOUNDATION} + ${CORESERVICES} + ${SECURITY} + ${SYSTEM} + ) +endif(CLR_CMAKE_TARGET_OSX) + +if(CLR_CMAKE_TARGET_NETBSD) + find_library(KVM kvm) + + LIST(APPEND CORECLR_LIBRARIES + ${KVM} + ) +endif(CLR_CMAKE_TARGET_NETBSD) # Path like: artifacts/bin/native/net5.0-Linux-Release-arm/ set(NATIVE_LIBS_LOCATION "${NATIVE_LIBS_ARTIFACTS}") diff --git a/src/installer/corehost/cli/hostpolicy/static/coreclr_resolver.cpp b/src/installer/corehost/cli/hostpolicy/static/coreclr_resolver.cpp index 66d3544e704fed..bc3f9138e96bf0 100644 --- a/src/installer/corehost/cli/hostpolicy/static/coreclr_resolver.cpp +++ b/src/installer/corehost/cli/hostpolicy/static/coreclr_resolver.cpp @@ -42,33 +42,6 @@ extern "C" } -#if !defined(TARGET_LINUX) - -bool coreclr_resolver_t::resolve_coreclr(const pal::string_t& libcoreclr_path, coreclr_resolver_contract_t& coreclr_resolver_contract) -{ - pal::string_t coreclr_dll_path(libcoreclr_path); - append_path(&coreclr_dll_path, LIBCORECLR_NAME); - - if (!pal::load_library(&coreclr_dll_path, &coreclr_resolver_contract.coreclr)) - { - return false; - } - - coreclr_resolver_contract.coreclr_initialize = reinterpret_cast(pal::get_symbol(coreclr_resolver_contract.coreclr, "coreclr_initialize")); - coreclr_resolver_contract.coreclr_shutdown = reinterpret_cast(pal::get_symbol(coreclr_resolver_contract.coreclr, "coreclr_shutdown_2")); - coreclr_resolver_contract.coreclr_execute_assembly = reinterpret_cast(pal::get_symbol(coreclr_resolver_contract.coreclr, "coreclr_execute_assembly")); - coreclr_resolver_contract.coreclr_create_delegate = reinterpret_cast(pal::get_symbol(coreclr_resolver_contract.coreclr, "coreclr_create_delegate")); - - assert(coreclr_resolver_contract.coreclr_initialize != nullptr - && coreclr_resolver_contract.coreclr_shutdown != nullptr - && coreclr_resolver_contract.coreclr_execute_assembly != nullptr - && coreclr_resolver_contract.coreclr_create_delegate != nullptr); - - return true; -} - -#else - bool coreclr_resolver_t::resolve_coreclr(const pal::string_t& libcoreclr_path, coreclr_resolver_contract_t& coreclr_resolver_contract) { coreclr_resolver_contract.coreclr = nullptr; @@ -79,5 +52,3 @@ bool coreclr_resolver_t::resolve_coreclr(const pal::string_t& libcoreclr_path, c return true; } - -#endif diff --git a/src/installer/pkg/projects/netcoreapp/pkg/Directory.Build.props b/src/installer/pkg/projects/netcoreapp/pkg/Directory.Build.props index 8a3887ead8b597..40e6a6f9e6375b 100644 --- a/src/installer/pkg/projects/netcoreapp/pkg/Directory.Build.props +++ b/src/installer/pkg/projects/netcoreapp/pkg/Directory.Build.props @@ -21,13 +21,9 @@ - - - - From 4fac39a8c0c4bcdf8594baa5dc65ba9c4d0d54d0 Mon Sep 17 00:00:00 2001 From: vsadov Date: Sat, 17 Oct 2020 07:21:41 -0700 Subject: [PATCH 2/7] setting g_hmodCoreCLR on Unix --- src/coreclr/src/vm/ceemain.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index 9d0a42ccfe5119..e6e86be507dd40 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -638,7 +638,13 @@ void EEStartupHelper() g_fEEInit = true; #if CORECLR_EMBEDDED + +#ifdef TARGET_WINDOWS HINSTANCE curModule = WszGetModuleHandle(NULL); +#else + HINSTANCE curModule = PAL_LoadLibraryDirect(NULL); +#endif + g_hmodCoreCLR = curModule; g_hThisInst = curModule; #endif From 038d2af561e7abd45931d31a7eda4a9fd5319419 Mon Sep 17 00:00:00 2001 From: vsadov Date: Sat, 17 Oct 2020 09:38:28 -0700 Subject: [PATCH 3/7] System.Globalization.Native.lib must build with coreclr to be linkable with it --- .../corehost/cli/apphost/static/CMakeLists.txt | 2 +- .../Unix/System.Globalization.Native/CMakeLists.txt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index 22ae83ad0401f5..6af310080016ef 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -88,6 +88,7 @@ if(CLR_CMAKE_TARGET_WIN32) else() set(CORECLR_LIBRARIES ${CORECLR_STATIC_LIB_LOCATION}/libcoreclr_static.a + ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Globalization.Native.a ${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a ${CORECLR_STATIC_LIB_LOCATION}/libpalrt.a ${CORECLR_STATIC_LIB_LOCATION}/libeventprovider.a @@ -137,7 +138,6 @@ if(NOT CLR_CMAKE_TARGET_LINUX) ) else() set(NATIVE_LIBS - ${NATIVE_LIBS_LOCATION}/libSystem.Globalization.Native.a ${NATIVE_LIBS_LOCATION}/libSystem.IO.Compression.Native.a ${NATIVE_LIBS_LOCATION}/libSystem.Native.a ${NATIVE_LIBS_LOCATION}/libSystem.Net.Security.Native.a diff --git a/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt index c21d79f3d7c348..834a86ec1cca01 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt @@ -91,7 +91,16 @@ add_library(System.Globalization.Native-Static set_target_properties(System.Globalization.Native-Static PROPERTIES OUTPUT_NAME System.Globalization.Native CLEAN_DIRECT_OUTPUT 1) -install (TARGETS System.Globalization.Native-Static DESTINATION .) +if (GEN_SHARED_LIB) + # this builds with libs to check for libs-level warnings + install (TARGETS System.Globalization.Native-Static DESTINATION .) +else() + # this one builds with coreclr and used by singlefilehost. + # it needs to build with coreclr in order to be linkable with it on Windows + # coreclr and static libraries must match because linker does not permit mixing modules + # with different C runtimes (i.e. Debug vs. Release) + install (TARGETS System.Globalization.Native-Static DESTINATION lib) +endif() if(NOT CLR_CMAKE_TARGET_OSX AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) if (GEN_SHARED_LIB) From c34ca9bde570ff6f2b74389659ba2ec47f4f2421 Mon Sep 17 00:00:00 2001 From: vsadov Date: Sat, 17 Oct 2020 11:48:04 -0700 Subject: [PATCH 4/7] Always use system unwind libs on FREEBSD --- .../corehost/cli/apphost/static/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index 6af310080016ef..244eea29a4dd73 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -118,11 +118,11 @@ if(CLR_CMAKE_TARGET_NETBSD) ) endif(CLR_CMAKE_TARGET_NETBSD) -# Path like: artifacts/bin/native/net5.0-Linux-Release-arm/ -set(NATIVE_LIBS_LOCATION "${NATIVE_LIBS_ARTIFACTS}") -message ("Looking for native libs at location: '${NATIVE_LIBS_LOCATION}'.") +# On *BSD, we always use the libunwind that's part of the OS +if(CLR_CMAKE_TARGET_FREEBSD) + set(CLR_CMAKE_USE_SYSTEM_LIBUNWIND 1) +endif() -# If/when OSX and *BSD are supported, they should also use the libunwind that's part of the OS if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) find_unwind_libs(UNWIND_LIBS) @@ -131,6 +131,10 @@ if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) ) endif() +# Path like: artifacts/bin/native/net5.0-Linux-Release-arm/ +set(NATIVE_LIBS_LOCATION "${NATIVE_LIBS_ARTIFACTS}") +message ("Looking for native libs at location: '${NATIVE_LIBS_LOCATION}'.") + if(NOT CLR_CMAKE_TARGET_LINUX) set(NATIVE_LIBS # Native libs linked into singlefilehost is supported only on Linux for now. From 7a4dc8f7870f962bc24e159ef7be58e5ac8e5ee9 Mon Sep 17 00:00:00 2001 From: vsadov Date: Sat, 17 Oct 2020 13:31:53 -0700 Subject: [PATCH 5/7] no DllMain when coreclr is statically linked --- src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt | 1 + src/coreclr/src/dlls/mscoree/mscoree.cpp | 12 ++++++------ src/coreclr/src/vm/ceemain.cpp | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt index 75ebe97f91cf67..a8f9a2c065edfb 100644 --- a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -170,6 +170,7 @@ target_sources(coreclr PUBLIC $) target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks) target_sources(coreclr_static PUBLIC $) target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static cee_wks_mergeable) +target_compile_definitions(coreclr_static PUBLIC CORECLR_EMBEDDED) # Create the runtime module index header file containing the coreclr build id # for xplat and the timestamp/size on Windows. diff --git a/src/coreclr/src/dlls/mscoree/mscoree.cpp b/src/coreclr/src/dlls/mscoree/mscoree.cpp index e32041c647e4ad..c610e9e91a10e5 100644 --- a/src/coreclr/src/dlls/mscoree/mscoree.cpp +++ b/src/coreclr/src/dlls/mscoree/mscoree.cpp @@ -17,16 +17,13 @@ #include -// Globals -extern HINSTANCE g_hThisInst; +#if !defined(CROSSGEN_COMPILE) && !defined(CORECLR_EMBEDDED) -// Locals. BOOL STDMETHODCALLTYPE EEDllMain( // TRUE on success, FALSE on error. HINSTANCE hInst, // Instance handle of the loaded module. DWORD dwReason, // Reason for loading. - LPVOID lpReserved); // Unused. + LPVOID lpReserved); // Unused. -#ifndef CROSSGEN_COMPILE //***************************************************************************** // Handle lifetime of loaded library. //***************************************************************************** @@ -48,7 +45,10 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved) return EEDllMain((HINSTANCE)hInstance, dwReason, lpReserved); } -#endif // CROSSGEN_COMPILE +#endif // !defined(CROSSGEN_COMPILE) && !defined(CORECLR_EMBEDDED) + +// Globals +extern HINSTANCE g_hThisInst; HINSTANCE GetModuleInst() { diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index e6e86be507dd40..c530e680801463 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -1810,6 +1810,8 @@ LONG DllMainFilter(PEXCEPTION_POINTERS p, PVOID pv) return EXCEPTION_EXECUTE_HANDLER; } +#if !defined(CORECLR_EMBEDDED) + //***************************************************************************** // This is the part of the old-style DllMain that initializes the // stuff that the EE team works on. It's called from the real DllMain @@ -1890,6 +1892,8 @@ BOOL STDMETHODCALLTYPE EEDllMain( // TRUE on success, FALSE on error. return TRUE; } +#endif // !defined(CORECLR_EMBEDDED) + struct TlsDestructionMonitor { ~TlsDestructionMonitor() From 250d3fc2774f25e256017cf9a22507ca9feb0aae Mon Sep 17 00:00:00 2001 From: vsadov Date: Tue, 20 Oct 2020 13:37:06 -0700 Subject: [PATCH 6/7] Handle cases when coreclr configuration is different from libraries --- .../corehost/Windows/gen-buildsys-win.bat | 2 +- src/installer/corehost/build.cmd | 1 + .../cli/apphost/static/CMakeLists.txt | 55 ++++++++++++++++--- src/installer/corehost/cli/common.cmake | 8 --- src/installer/corehost/cli/fxr/CMakeLists.txt | 1 - src/installer/corehost/cli/fxr/files.cmake | 37 +++++++++++++ .../cli/fxr/standalone/CMakeLists.txt | 15 +---- .../corehost/cli/fxr/static/CMakeLists.txt | 44 --------------- .../corehost/cli/hostcommon/CMakeLists.txt | 39 +------------ .../corehost/cli/hostcommon/files.cmake | 43 +++++++++++++++ .../corehost/cli/hostpolicy/CMakeLists.txt | 1 - .../corehost/cli/hostpolicy/files.cmake | 40 ++++++++++++++ .../cli/hostpolicy/standalone/CMakeLists.txt | 35 +----------- .../cli/hostpolicy/static/CMakeLists.txt | 50 ----------------- src/installer/corehost/corehost.proj | 1 + 15 files changed, 175 insertions(+), 197 deletions(-) create mode 100644 src/installer/corehost/cli/fxr/files.cmake delete mode 100644 src/installer/corehost/cli/fxr/static/CMakeLists.txt create mode 100644 src/installer/corehost/cli/hostcommon/files.cmake create mode 100644 src/installer/corehost/cli/hostpolicy/files.cmake delete mode 100644 src/installer/corehost/cli/hostpolicy/static/CMakeLists.txt diff --git a/src/installer/corehost/Windows/gen-buildsys-win.bat b/src/installer/corehost/Windows/gen-buildsys-win.bat index d5cea94ee1b28b..ec29912133740c 100644 --- a/src/installer/corehost/Windows/gen-buildsys-win.bat +++ b/src/installer/corehost/Windows/gen-buildsys-win.bat @@ -43,7 +43,7 @@ popd :DoGen set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%" set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__LatestCommit%" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" -set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCORECLR_ARTIFACTS=%__CoreClrArtifacts% " "-DNATIVE_LIBS_ARTIFACTS=%__NativeLibsArtifacts%" +set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCORECLR_ARTIFACTS=%__CoreClrArtifacts% " "-DRUNTIME_CONFIG=%__RuntimeConfiguration%" "-DNATIVE_LIBS_ARTIFACTS=%__NativeLibsArtifacts%" set __ExtraCmakeParams=%__ExtraCmakeParams% "-DRUNTIME_FLAVOR=%__RuntimeFlavor% " set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" "-DCLR_ENG_NATIVE_DIR=%__sourceDir%\..\..\..\eng\native" diff --git a/src/installer/corehost/build.cmd b/src/installer/corehost/build.cmd index 26b6115c65d727..5983277aa53bc9 100644 --- a/src/installer/corehost/build.cmd +++ b/src/installer/corehost/build.cmd @@ -41,6 +41,7 @@ if /i [%1] == [rootDir] ( set __rootDir=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [coreclrartifacts] (set __CoreClrArtifacts=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [nativelibsartifacts] (set __NativeLibsArtifacts=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [runtimeflavor] (set __RuntimeFlavor=%2&&shift&&shift&goto Arg_Loop) +if /i [%1] == [runtimeconfiguration] (set __RuntimeConfiguration=%2&&shift&&shift&goto Arg_Loop) shift diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index 244eea29a4dd73..e1275f3289d460 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES ../bundle_marker.cpp ./hostfxr_resolver.cpp ./hostpolicy_resolver.cpp + ../../hostpolicy/static/coreclr_resolver.cpp ) set(HEADERS @@ -30,7 +31,15 @@ set(HEADERS ../../../hostfxr_resolver.h ) -list(APPEND SOURCES $ $) +add_definitions(-D_NO_ASYNCRTIMP) +add_definitions(-D_NO_PPLXIMP) +add_definitions(-DEXPORT_SHARED_API=1) +add_definitions(-DHOSTPOLICY_EMBEDDED) + + +include(../../fxr/files.cmake) +include(../../hostpolicy/files.cmake) +include(../../hostcommon/files.cmake) if(CLR_CMAKE_TARGET_WIN32) list(APPEND SOURCES @@ -46,12 +55,47 @@ include(configure.cmake) add_definitions(-DFEATURE_APPHOST=1) add_definitions(-DFEATURE_STATIC_HOST=1) -# Disable manifest generation into the file .exe on Windows if(CLR_CMAKE_TARGET_WIN32) - set_property(TARGET ${PROJECT_NAME} PROPERTY - LINK_FLAGS "/MANIFEST:NO" + # Disable manifest generation into the file .exe on Windows + add_linker_flag("/MANIFEST:NO") + + get_property(ALL_COMPILE_OPTIONS TARGET ${PROJECT_NAME} PROPERTY COMPILE_OPTIONS) + string(TOUPPER ${RUNTIME_CONFIG} UPPERCASE_RUNTIME_CONFIG) + + # make sure that certain compiler and linker settings match the runtime config + # we need to ensure that to be able to link with coreclr in mixed builds (ex: Debug with Release runtime) + if(UPPERCASE_RUNTIME_CONFIG STREQUAL DEBUG OR UPPERCASE_RUNTIME_CONFIG STREQUAL CHECKED) + # add_compile_options(/MTd) + # per-config options will win, so we have to use this syntax to override + set_property(TARGET ${PROJECT_NAME} PROPERTY + COMPILE_OPTIONS "${ALL_COMPILE_OPTIONS};$<$:/MTd>" + ) + + remove_definitions(-DNDEBUG) + add_definitions(-DDEBUG -D_DEBUG -D_DBG) + + # ignore runtime libraries that could have been added so far based on the config + add_linker_flag("/NODEFAULTLIB:ucrt.lib") + add_linker_flag("/NODEFAULTLIB:libucrt.lib") + add_linker_flag("/NODEFAULTLIB:libcmt.lib") + + # make sure we use statically linked crt + add_linker_flag("/DEFAULTLIB:libucrtd.lib") + else() + # add_compile_options(/MT) + # per-config options will win, so we have to use this syntax to override + set_property(TARGET ${PROJECT_NAME} PROPERTY + COMPILE_OPTIONS "${ALL_COMPILE_OPTIONS};$<$:/MT>" ) + remove_definitions(-DDEBUG -D_DEBUG -D_DBG) + add_definitions(-DNDEBUG) + + # Force uCRT to be dynamically linked for Release build + add_linker_flag("/NODEFAULTLIB:libucrt.lib") + add_linker_flag("/DEFAULTLIB:ucrt.lib") + endif() + # Incremental linking results in the linker inserting extra padding and routing function calls via thunks that can break the # invariants (e.g. size of region between Jit_PatchedCodeLast-Jit_PatchCodeStart needs to fit in a page). add_linker_flag("/INCREMENTAL:NO") @@ -72,8 +116,6 @@ if(CLR_CMAKE_TARGET_WIN32) set(CORECLR_LIBRARIES ${CORECLR_STATIC_LIB_LOCATION}/coreclr_static.lib ${CORECLR_STATIC_LIB_LOCATION}/System.Globalization.Native.lib - ${STATIC_MT_CRT_LIB} - ${STATIC_MT_VCRT_LIB} kernel32.lib advapi32.lib ole32.lib @@ -212,7 +254,6 @@ endif(NOT CLR_CMAKE_TARGET_LINUX) set_property(TARGET singlefilehost PROPERTY ENABLE_EXPORTS 1) target_link_libraries(singlefilehost - libhostcommon ${CORECLR_LIBRARIES} ${START_WHOLE_ARCHIVE} diff --git a/src/installer/corehost/cli/common.cmake b/src/installer/corehost/cli/common.cmake index 2c131d975becf8..e54e47e436a9f8 100644 --- a/src/installer/corehost/cli/common.cmake +++ b/src/installer/corehost/cli/common.cmake @@ -3,14 +3,6 @@ project(${DOTNET_PROJECT_NAME}) -if(CLR_CMAKE_HOST_WIN32) - add_compile_options($<$:/MT>) - add_compile_options($<$:/MT>) - add_compile_options($<$:/MTd>) -else() - add_compile_options(-fvisibility=hidden) -endif() - include(${CMAKE_CURRENT_LIST_DIR}/setup.cmake) # Include directories diff --git a/src/installer/corehost/cli/fxr/CMakeLists.txt b/src/installer/corehost/cli/fxr/CMakeLists.txt index dbd0bc51dd6964..61ff7bc8bd9754 100644 --- a/src/installer/corehost/cli/fxr/CMakeLists.txt +++ b/src/installer/corehost/cli/fxr/CMakeLists.txt @@ -1,5 +1,4 @@ # Licensed to the .NET Foundation under one or more agreements. # The .NET Foundation licenses this file to you under the MIT license. -add_subdirectory(static) add_subdirectory(standalone) diff --git a/src/installer/corehost/cli/fxr/files.cmake b/src/installer/corehost/cli/fxr/files.cmake new file mode 100644 index 00000000000000..1d46688166aaa0 --- /dev/null +++ b/src/installer/corehost/cli/fxr/files.cmake @@ -0,0 +1,37 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. + +# Include directories +include_directories(${CMAKE_CURRENT_LIST_DIR}/../json) +include_directories(${CMAKE_CURRENT_LIST_DIR}/../fxr) + +# CMake does not recommend using globbing since it messes with the freshness checks +list(APPEND SOURCES + ${CMAKE_CURRENT_LIST_DIR}/command_line.cpp + ${CMAKE_CURRENT_LIST_DIR}/corehost_init.cpp + ${CMAKE_CURRENT_LIST_DIR}/hostfxr.cpp + ${CMAKE_CURRENT_LIST_DIR}/fx_muxer.cpp + ${CMAKE_CURRENT_LIST_DIR}/fx_resolver.cpp + ${CMAKE_CURRENT_LIST_DIR}/fx_resolver.messages.cpp + ${CMAKE_CURRENT_LIST_DIR}/framework_info.cpp + ${CMAKE_CURRENT_LIST_DIR}/host_context.cpp + ${CMAKE_CURRENT_LIST_DIR}/sdk_info.cpp + ${CMAKE_CURRENT_LIST_DIR}/sdk_resolver.cpp +) + +list(APPEND HEADERS + ${CMAKE_CURRENT_LIST_DIR}/../corehost_context_contract.h + ${CMAKE_CURRENT_LIST_DIR}/../hostpolicy.h + ${CMAKE_CURRENT_LIST_DIR}/../fx_definition.h + ${CMAKE_CURRENT_LIST_DIR}/../fx_reference.h + ${CMAKE_CURRENT_LIST_DIR}/../roll_fwd_on_no_candidate_fx_option.h + ${CMAKE_CURRENT_LIST_DIR}/command_line.h + ${CMAKE_CURRENT_LIST_DIR}/corehost_init.h + ${CMAKE_CURRENT_LIST_DIR}/fx_muxer.h + ${CMAKE_CURRENT_LIST_DIR}/fx_resolver.h + ${CMAKE_CURRENT_LIST_DIR}/framework_info.h + ${CMAKE_CURRENT_LIST_DIR}/host_context.h + ${CMAKE_CURRENT_LIST_DIR}/sdk_info.h + ${CMAKE_CURRENT_LIST_DIR}/sdk_resolver.h +) + diff --git a/src/installer/corehost/cli/fxr/standalone/CMakeLists.txt b/src/installer/corehost/cli/fxr/standalone/CMakeLists.txt index c6b07eba340c9b..78f43925f15d21 100644 --- a/src/installer/corehost/cli/fxr/standalone/CMakeLists.txt +++ b/src/installer/corehost/cli/fxr/standalone/CMakeLists.txt @@ -5,28 +5,17 @@ project(hostfxr) set(DOTNET_PROJECT_NAME "hostfxr") -# Include directories -include_directories(../../json) -include_directories(../../fxr) - # CMake does not recommend using globbing since it messes with the freshness checks set(SOURCES ./hostpolicy_resolver.cpp - $ ) set(HEADERS - ../command_line.h - ../corehost_init.h - ../fx_muxer.h - ../fx_resolver.h - ../framework_info.h - ../host_context.h - ../sdk_info.h - ../sdk_resolver.h ../hostpolicy_resolver.h ) +include(../files.cmake) + if(CLR_CMAKE_TARGET_WIN32) list(APPEND SOURCES hostfxr.def) diff --git a/src/installer/corehost/cli/fxr/static/CMakeLists.txt b/src/installer/corehost/cli/fxr/static/CMakeLists.txt deleted file mode 100644 index 10928733fe68cd..00000000000000 --- a/src/installer/corehost/cli/fxr/static/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -project(hostfxr_static) - -set(DOTNET_PROJECT_NAME "hostfxr_static") - -# Include directories -include_directories(../../json) -include_directories(../../fxr) - -# CMake does not recommend using globbing since it messes with the freshness checks -set(SOURCES - ../command_line.cpp - ../corehost_init.cpp - ../hostfxr.cpp - ../fx_muxer.cpp - ../fx_resolver.cpp - ../fx_resolver.messages.cpp - ../framework_info.cpp - ../host_context.cpp - ../sdk_info.cpp - ../sdk_resolver.cpp -) - -set(HEADERS - ../../corehost_context_contract.h - ../../hostpolicy.h - ../../fx_definition.h - ../../fx_reference.h - ../../roll_fwd_on_no_candidate_fx_option.h - ../command_line.h - ../corehost_init.h - ../fx_muxer.h - ../fx_resolver.h - ../framework_info.h - ../host_context.h - ../sdk_info.h - ../sdk_resolver.h -) - -set(SKIP_VERSIONING 1) -set(BUILD_OBJECT_LIBRARY 1) -include(../../lib_static.cmake) diff --git a/src/installer/corehost/cli/hostcommon/CMakeLists.txt b/src/installer/corehost/cli/hostcommon/CMakeLists.txt index d2e6162ba3b728..36b9d140cb95c3 100644 --- a/src/installer/corehost/cli/hostcommon/CMakeLists.txt +++ b/src/installer/corehost/cli/hostcommon/CMakeLists.txt @@ -5,44 +5,7 @@ project(hostcommon) set(DOTNET_PROJECT_NAME "hostcommon") -# Include directories -include_directories(../fxr) -include_directories(../json) - -# CMake does not recommend using globbing since it messes with the freshness checks -set(SOURCES - ../json_parser.cpp - ../deps_format.cpp - ../deps_entry.cpp - ../host_startup_info.cpp - ../roll_forward_option.cpp - ../fx_definition.cpp - ../fx_reference.cpp - ../fxr/fx_ver.cpp - ../version.cpp - ../version_compatibility_range.cpp - ../runtime_config.cpp - ../bundle/info.cpp - ../bundle/reader.cpp - ../bundle/header.cpp -) - -set(HEADERS - ../json_parser.h - ../deps_format.h - ../deps_entry.h - ../host_startup_info.h - ../roll_forward_option.h - ../fx_definition.h - ../fx_reference.h - ../fxr/fx_ver.h - ../version.h - ../version_compatibility_range.h - ../runtime_config.h - ../bundle/info.h - ../bundle/reader.h - ../bundle/header.h -) +include(files.cmake) set(SKIP_VERSIONING 1) include(../lib_static.cmake) diff --git a/src/installer/corehost/cli/hostcommon/files.cmake b/src/installer/corehost/cli/hostcommon/files.cmake new file mode 100644 index 00000000000000..b838cc2210ffde --- /dev/null +++ b/src/installer/corehost/cli/hostcommon/files.cmake @@ -0,0 +1,43 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. + +# Include directories +include_directories(${CMAKE_CURRENT_LIST_DIR}/../fxr) +include_directories(${CMAKE_CURRENT_LIST_DIR}/../json) + +# CMake does not recommend using globbing since it messes with the freshness checks +list(APPEND SOURCES + ${CMAKE_CURRENT_LIST_DIR}/../json_parser.cpp + ${CMAKE_CURRENT_LIST_DIR}/../deps_format.cpp + ${CMAKE_CURRENT_LIST_DIR}/../deps_entry.cpp + ${CMAKE_CURRENT_LIST_DIR}/../host_startup_info.cpp + ${CMAKE_CURRENT_LIST_DIR}/../roll_forward_option.cpp + ${CMAKE_CURRENT_LIST_DIR}/../fx_definition.cpp + ${CMAKE_CURRENT_LIST_DIR}/../fx_reference.cpp + ${CMAKE_CURRENT_LIST_DIR}/../fxr/fx_ver.cpp + ${CMAKE_CURRENT_LIST_DIR}/../version.cpp + ${CMAKE_CURRENT_LIST_DIR}/../version_compatibility_range.cpp + ${CMAKE_CURRENT_LIST_DIR}/../runtime_config.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/info.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/reader.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/header.cpp +) + +list(APPEND HEADERS + ${CMAKE_CURRENT_LIST_DIR}/../json_parser.h + ${CMAKE_CURRENT_LIST_DIR}/../deps_format.h + ${CMAKE_CURRENT_LIST_DIR}/../deps_entry.h + ${CMAKE_CURRENT_LIST_DIR}/../host_startup_info.h + ${CMAKE_CURRENT_LIST_DIR}/../roll_forward_option.h + ${CMAKE_CURRENT_LIST_DIR}/../fx_definition.h + ${CMAKE_CURRENT_LIST_DIR}/../fx_reference.h + ${CMAKE_CURRENT_LIST_DIR}/../fxr/fx_ver.h + ${CMAKE_CURRENT_LIST_DIR}/../version.h + ${CMAKE_CURRENT_LIST_DIR}/../version_compatibility_range.h + ${CMAKE_CURRENT_LIST_DIR}/../runtime_config.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/info.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/reader.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/header.h +) + + diff --git a/src/installer/corehost/cli/hostpolicy/CMakeLists.txt b/src/installer/corehost/cli/hostpolicy/CMakeLists.txt index dbd0bc51dd6964..61ff7bc8bd9754 100644 --- a/src/installer/corehost/cli/hostpolicy/CMakeLists.txt +++ b/src/installer/corehost/cli/hostpolicy/CMakeLists.txt @@ -1,5 +1,4 @@ # Licensed to the .NET Foundation under one or more agreements. # The .NET Foundation licenses this file to you under the MIT license. -add_subdirectory(static) add_subdirectory(standalone) diff --git a/src/installer/corehost/cli/hostpolicy/files.cmake b/src/installer/corehost/cli/hostpolicy/files.cmake new file mode 100644 index 00000000000000..0dfabb55135b83 --- /dev/null +++ b/src/installer/corehost/cli/hostpolicy/files.cmake @@ -0,0 +1,40 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. + +# Include directories +include_directories(${CMAKE_CURRENT_LIST_DIR}/../fxr) +include_directories(${CMAKE_CURRENT_LIST_DIR}/../json) + +# CMake does not recommend using globbing since it messes with the freshness checks +list(APPEND SOURCES + ${CMAKE_CURRENT_LIST_DIR}/args.cpp + ${CMAKE_CURRENT_LIST_DIR}/breadcrumbs.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreclr.cpp + ${CMAKE_CURRENT_LIST_DIR}/deps_resolver.cpp + ${CMAKE_CURRENT_LIST_DIR}/hostpolicy_context.cpp + ${CMAKE_CURRENT_LIST_DIR}/hostpolicy.cpp + ${CMAKE_CURRENT_LIST_DIR}/hostpolicy_init.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/dir_utils.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/extractor.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/file_entry.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/manifest.cpp + ${CMAKE_CURRENT_LIST_DIR}/../bundle/runner.cpp +) + +list(APPEND HEADERS + ${CMAKE_CURRENT_LIST_DIR}/args.h + ${CMAKE_CURRENT_LIST_DIR}/breadcrumbs.h + ${CMAKE_CURRENT_LIST_DIR}/coreclr.h + ${CMAKE_CURRENT_LIST_DIR}/deps_resolver.h + ${CMAKE_CURRENT_LIST_DIR}/hostpolicy_context.h + ${CMAKE_CURRENT_LIST_DIR}/hostpolicy_init.h + ${CMAKE_CURRENT_LIST_DIR}/../hostpolicy.h + ${CMAKE_CURRENT_LIST_DIR}/../corehost_context_contract.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/dir_utils.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/extractor.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/file_entry.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/manifest.h + ${CMAKE_CURRENT_LIST_DIR}/../bundle/runner.h + ${CMAKE_CURRENT_LIST_DIR}/../../coreclr_resolver.h +) + diff --git a/src/installer/corehost/cli/hostpolicy/standalone/CMakeLists.txt b/src/installer/corehost/cli/hostpolicy/standalone/CMakeLists.txt index cca4648e800244..a0cbbe87f691d5 100644 --- a/src/installer/corehost/cli/hostpolicy/standalone/CMakeLists.txt +++ b/src/installer/corehost/cli/hostpolicy/standalone/CMakeLists.txt @@ -5,44 +5,11 @@ project(hostpolicy) set(DOTNET_PROJECT_NAME "hostpolicy") -# Include directories -include_directories(../../fxr) -include_directories(../../json) - -# CMake does not recommend using globbing since it messes with the freshness checks set(SOURCES - ../args.cpp - ../breadcrumbs.cpp - ../coreclr.cpp - ../deps_resolver.cpp - ../hostpolicy_context.cpp - ../hostpolicy.cpp - ../hostpolicy_init.cpp - ../../bundle/dir_utils.cpp - ../../bundle/extractor.cpp - ../../bundle/file_entry.cpp - ../../bundle/manifest.cpp - ../../bundle/runner.cpp ./coreclr_resolver.cpp ) -set(HEADERS - ../args.h - ../breadcrumbs.h - ../coreclr.h - ../deps_resolver.h - ../hostpolicy_context.h - ../hostpolicy_init.h - ../../hostpolicy.h - ../../corehost_context_contract.h - ../../bundle/dir_utils.h - ../../bundle/extractor.h - ../../bundle/file_entry.h - ../../bundle/manifest.h - ../../bundle/runner.h - ../../../coreclr_resolver.h -) - +include(../files.cmake) if(CLR_CMAKE_TARGET_WIN32) list(APPEND SOURCES diff --git a/src/installer/corehost/cli/hostpolicy/static/CMakeLists.txt b/src/installer/corehost/cli/hostpolicy/static/CMakeLists.txt deleted file mode 100644 index fcf95656f5fb15..00000000000000 --- a/src/installer/corehost/cli/hostpolicy/static/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -project(hostpolicy_static) - -set(DOTNET_PROJECT_NAME "hostpolicy_static") - -# Include directories -include_directories(../../fxr) -include_directories(../../json) - -# CMake does not recommend using globbing since it messes with the freshness checks -set(SOURCES - ../args.cpp - ../breadcrumbs.cpp - ../coreclr.cpp - ../deps_resolver.cpp - ../hostpolicy_context.cpp - ../hostpolicy.cpp - ../hostpolicy_init.cpp - ../../bundle/dir_utils.cpp - ../../bundle/extractor.cpp - ../../bundle/file_entry.cpp - ../../bundle/manifest.cpp - ../../bundle/runner.cpp - ./coreclr_resolver.cpp -) - -set(HEADERS - ../args.h - ../breadcrumbs.h - ../coreclr.h - ../deps_resolver.h - ../hostpolicy_context.h - ../hostpolicy_init.h - ../../hostpolicy.h - ../../corehost_context_contract.h - ../../bundle/dir_utils.h - ../../bundle/extractor.h - ../../bundle/file_entry.h - ../../bundle/manifest.h - ../../bundle/runner.h - ../../../coreclr_resolver.h -) - -set(SKIP_VERSIONING 1) -set(BUILD_OBJECT_LIBRARY 1) -include(../../lib_static.cmake) - -add_definitions(-DHOSTPOLICY_EMBEDDED) diff --git a/src/installer/corehost/corehost.proj b/src/installer/corehost/corehost.proj index de52644fa1a93f..385036b7faba72 100644 --- a/src/installer/corehost/corehost.proj +++ b/src/installer/corehost/corehost.proj @@ -92,6 +92,7 @@ $(BuildArgs) coreclrartifacts $(CoreCLRArtifactsPath) $(BuildArgs) nativelibsartifacts $(LibrariesArtifactsPath)/bin/native/$(NetCoreAppCurrent)-$(TargetOS)-$(LibrariesConfiguration)-$(TargetArchitecture) $(BuildArgs) runtimeflavor $(RuntimeFlavor) + $(BuildArgs) runtimeconfiguration $(RuntimeConfiguration)