From f93065f9f05f7ebe8cf5aade4746d9d8c3154b08 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Sun, 28 Jun 2020 21:21:46 -0700 Subject: [PATCH] Host with coreclr linked in (#36847) * make all-inclusive coreclr_static.lib and link into singlefilehost * Disable superhost linking on windows for now (issues with mixed Debug-on-Release builds) * shim coreclr policy between singlefile and standalone hosts * enable exports on singlefilehost executable * export __progname, perhaps it will make FreeBSD happy. * add environ too * mergeable wks and jit * ignore empty clr_path in single_file_bundle * hide R2R specific assert behind R2R ifdef * produce separate obj files from platform specific asm files for mergeable WKS - to make CMake happy * remove libcoreclr and libclrjit from netcoreapp/pkg * temporary disable setting up GS cookie on OSX superhost * renamed clrjit_static folder dll->static * extract JIT dllmain.cpp and eliminate clrjit_mergeable * make coreclr_static dependent on def/exports files instead of coreclr. * reducing double-build in cee_wks to just few files. Most of cee_wks is built once as an obj library and reused. * bring back cee_wks_mergeable and push shared object lib stuff lower to cee_wks_core * A comment about FreeBSD-specific workaround. * move finding unwind libs to a CMake function * since we have files compiled differently between embedded and standalone coreclr, we do not need EMBEDDED_RUNTIME marker. * renamed host_resolver_t.h and host_resolver_t.cpp to not have "_t" * path separating slash when forming CORECLR_STATIC_LIB_LOCATION --- eng/native/functions.cmake | 70 +++++++++------ src/coreclr/src/binder/CMakeLists.txt | 2 +- .../src/classlibnative/bcltype/CMakeLists.txt | 2 +- .../src/classlibnative/float/CMakeLists.txt | 2 +- .../src/debug/debug-pal/CMakeLists.txt | 2 +- src/coreclr/src/debug/di/CMakeLists.txt | 2 +- src/coreclr/src/debug/ee/wks/CMakeLists.txt | 8 +- .../src/debug/ildbsymlib/CMakeLists.txt | 2 +- .../dlls/mscordac/mscordac_unixexports.src | 2 + .../src/dlls/mscoree/coreclr/CMakeLists.txt | 29 +++++-- .../src/dlls/mscoree/unixinterface.cpp | 30 ++++--- src/coreclr/src/dlls/mscorrc/CMakeLists.txt | 2 +- src/coreclr/src/gcinfo/CMakeLists.txt | 2 +- src/coreclr/src/inc/CMakeLists.txt | 2 +- src/coreclr/src/interop/CMakeLists.txt | 2 +- src/coreclr/src/jit/CMakeLists.txt | 15 ++-- src/coreclr/src/jit/codegenarmarch.cpp | 2 + src/coreclr/src/jit/dllmain.cpp | 42 +++++++++ src/coreclr/src/jit/ee_il_dll.cpp | 30 ------- .../src/jit/{dll => static}/CMakeLists.txt | 17 ++-- .../src/jit/{dll => static}/clrjit.def | 0 src/coreclr/src/md/ceefilegen/CMakeLists.txt | 2 +- src/coreclr/src/md/compiler/CMakeLists.txt | 2 +- src/coreclr/src/md/enc/CMakeLists.txt | 2 +- src/coreclr/src/md/hotdata/CMakeLists.txt | 2 +- src/coreclr/src/md/runtime/CMakeLists.txt | 2 +- .../src/nativeresources/CMakeLists.txt | 1 + src/coreclr/src/pal/inc/pal.h | 2 +- src/coreclr/src/pal/src/CMakeLists.txt | 33 +------ src/coreclr/src/pal/src/init/pal.cpp | 6 +- src/coreclr/src/pal/src/loader/module.cpp | 46 ++++++++-- src/coreclr/src/unwinder/CMakeLists.txt | 2 +- src/coreclr/src/utilcode/CMakeLists.txt | 2 +- src/coreclr/src/vm/CMakeLists.txt | 11 ++- src/coreclr/src/vm/ceemain.cpp | 15 +++- src/coreclr/src/vm/debughelp.cpp | 4 - .../src/vm/eventing/eventpipe/CMakeLists.txt | 2 +- src/coreclr/src/vm/wks/CMakeLists.txt | 28 ++++-- src/installer/corehost/build.cmd | 2 + src/installer/corehost/build.proj | 2 + src/installer/corehost/build.sh | 7 +- .../cli/apphost/standalone/CMakeLists.txt | 4 +- ...xr_resolver_t.cpp => hostfxr_resolver.cpp} | 2 +- .../cli/apphost/static/CMakeLists.txt | 87 ++++++++++++++++++- ...xr_resolver_t.cpp => hostfxr_resolver.cpp} | 2 +- .../apphost/static/hostpolicy_resolver.cpp | 18 ++-- .../static/singlefilehost_unixexports.src | 9 ++ .../corehost/cli/dotnet/CMakeLists.txt | 2 +- src/installer/corehost/cli/exe.cmake | 2 +- src/installer/corehost/cli/hostpolicy.h | 2 +- .../corehost/cli/hostpolicy/coreclr.cpp | 79 +++-------------- .../cli/hostpolicy/hostpolicy_context.cpp | 20 +++-- .../cli/hostpolicy/standalone/CMakeLists.txt | 42 +++++++-- .../standalone/coreclr_resolver.cpp | 33 +++++++ .../cli/hostpolicy/static/CMakeLists.txt | 2 + .../hostpolicy/static/coreclr_resolver.cpp | 84 ++++++++++++++++++ .../corehost/cli/ijwhost/CMakeLists.txt | 2 +- src/installer/corehost/coreclr_resolver.h | 62 +++++++++++++ src/installer/corehost/corehost.cpp | 2 +- ...ostfxr_resolver_t.h => hostfxr_resolver.h} | 0 .../netcoreapp/pkg/Directory.Build.props | 4 - .../CMakeLists.txt | 2 +- 62 files changed, 622 insertions(+), 276 deletions(-) create mode 100644 src/coreclr/src/jit/dllmain.cpp rename src/coreclr/src/jit/{dll => static}/CMakeLists.txt (59%) rename src/coreclr/src/jit/{dll => static}/clrjit.def (100%) rename src/installer/corehost/cli/apphost/standalone/{hostfxr_resolver_t.cpp => hostfxr_resolver.cpp} (98%) rename src/installer/corehost/cli/apphost/static/{hostfxr_resolver_t.cpp => hostfxr_resolver.cpp} (98%) create mode 100644 src/installer/corehost/cli/apphost/static/singlefilehost_unixexports.src create mode 100644 src/installer/corehost/cli/hostpolicy/standalone/coreclr_resolver.cpp create mode 100644 src/installer/corehost/cli/hostpolicy/static/coreclr_resolver.cpp create mode 100644 src/installer/corehost/coreclr_resolver.h rename src/installer/corehost/{hostfxr_resolver_t.h => hostfxr_resolver.h} (100%) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 44790724ea0c3b..8b73581ed1426a 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -68,21 +68,46 @@ endfunction(get_include_directories) function(get_include_directories_asm IncludeDirectories) get_directory_property(dirs INCLUDE_DIRECTORIES) - if (CLR_CMAKE_HOST_ARCH_ARM AND WIN32) - list(APPEND INC_DIRECTORIES "-I ") - endif() - foreach(dir IN LISTS dirs) - if (CLR_CMAKE_HOST_ARCH_ARM AND WIN32) - list(APPEND INC_DIRECTORIES ${dir};) - else() - list(APPEND INC_DIRECTORIES -I${dir}) - endif() + list(APPEND INC_DIRECTORIES -I${dir};) endforeach() set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE) endfunction(get_include_directories_asm) +# Finds and returns unwind libs +function(find_unwind_libs UnwindLibs) + if(CLR_CMAKE_HOST_ARCH_ARM) + find_library(UNWIND_ARCH NAMES unwind-arm) + endif() + + if(CLR_CMAKE_HOST_ARCH_ARM64) + find_library(UNWIND_ARCH NAMES unwind-aarch64) + endif() + + if(CLR_CMAKE_HOST_ARCH_AMD64) + find_library(UNWIND_ARCH NAMES unwind-x86_64) + endif() + + if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) + set(UNWIND_LIBS ${UNWIND_ARCH}) + endif() + + find_library(UNWIND_GENERIC NAMES unwind-generic) + + if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND) + set(UNWIND_LIBS ${UNWIND_LIBS} ${UNWIND_GENERIC}) + endif() + + find_library(UNWIND NAMES unwind) + + if(UNWIND STREQUAL UNWIND-NOTFOUND) + message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.") + endif() + + set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE) +endfunction(find_unwind_libs) + # Set the passed in RetSources variable to the list of sources with added current source directory # to form absolute paths. # The parameters after the RetSources are the input files. @@ -118,10 +143,10 @@ function(preprocess_file inputFilename outputFilename) PROPERTIES GENERATED TRUE) endfunction() -# preprocess_compile_asm(ASM_FILES file1 [file2 ...] OUTPUT_OBJECTS [variableName]) +# preprocess_compile_asm(TARGET target ASM_FILES file1 [file2 ...] OUTPUT_OBJECTS [variableName]) function(preprocess_compile_asm) set(options "") - set(oneValueArgs OUTPUT_OBJECTS) + set(oneValueArgs TARGET OUTPUT_OBJECTS) set(multiValueArgs ASM_FILES) cmake_parse_arguments(PARSE_ARGV 0 COMPILE_ASM "${options}" "${oneValueArgs}" "${multiValueArgs}") @@ -135,28 +160,21 @@ function(preprocess_compile_asm) file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${name}.asm" ASM_PREPROCESSED_FILE) preprocess_file(${ASM_FILE} ${ASM_PREPROCESSED_FILE}) - # We do not pass any defines since we have already done pre-processing above - set (ASM_CMDLINE "-o ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj ${ASM_PREPROCESSED_FILE}") - - # Generate the batch file that will invoke the assembler - file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/runasm_${name}.cmd" ASM_SCRIPT_FILE) - - file(GENERATE OUTPUT "${ASM_SCRIPT_FILE}" - CONTENT "\"${CMAKE_ASM_MASM_COMPILER}\" -g ${ASM_INCLUDE_DIRECTORIES} ${ASM_CMDLINE}") - - message("Generated - ${ASM_SCRIPT_FILE}") + # Produce object file where CMake would store .obj files for an OBJECT library. + # ex: artifacts\obj\coreclr\Windows_NT.arm64.Debug\src\vm\wks\cee_wks.dir\Debug\AsmHelpers.obj + set (OBJ_FILE "${CMAKE_CURRENT_BINARY_DIR}/${COMPILE_ASM_TARGET}.dir/${CMAKE_CFG_INTDIR}/${name}.obj") # Need to compile asm file using custom command as include directories are not provided to asm compiler - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj - COMMAND ${ASM_SCRIPT_FILE} + add_custom_command(OUTPUT ${OBJ_FILE} + COMMAND "${CMAKE_ASM_MASM_COMPILER}" -g ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_PREPROCESSED_FILE} DEPENDS ${ASM_PREPROCESSED_FILE} - COMMENT "Assembling ${ASM_PREPROCESSED_FILE} - ${ASM_SCRIPT_FILE}") + COMMENT "Assembling ${ASM_PREPROCESSED_FILE} ---> \"${CMAKE_ASM_MASM_COMPILER}\" -g ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_PREPROCESSED_FILE}") # mark obj as source that does not require compile - set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${name}.obj PROPERTIES EXTERNAL_OBJECT TRUE) + set_source_files_properties(${OBJ_FILE} PROPERTIES EXTERNAL_OBJECT TRUE) # Add the generated OBJ in the dependency list so that it gets consumed during linkage - list(APPEND ASSEMBLED_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj) + list(APPEND ASSEMBLED_OBJECTS ${OBJ_FILE}) endforeach() set(${COMPILE_ASM_OUTPUT_OBJECTS} ${ASSEMBLED_OBJECTS} PARENT_SCOPE) diff --git a/src/coreclr/src/binder/CMakeLists.txt b/src/coreclr/src/binder/CMakeLists.txt index 3a66c81e10e84f..9c242ed1518df0 100644 --- a/src/coreclr/src/binder/CMakeLists.txt +++ b/src/coreclr/src/binder/CMakeLists.txt @@ -83,7 +83,7 @@ convert_to_absolute_path(BINDER_SOURCES ${BINDER_SOURCES}) convert_to_absolute_path(BINDER_CROSSGEN_SOURCES ${BINDER_CROSSGEN_SOURCES}) add_library_clr(v3binder - STATIC + OBJECT ${BINDER_SOURCES} ) add_dependencies(v3binder eventing_headers) diff --git a/src/coreclr/src/classlibnative/bcltype/CMakeLists.txt b/src/coreclr/src/classlibnative/bcltype/CMakeLists.txt index 391f70eff4383e..c3122ec12ec3d8 100644 --- a/src/coreclr/src/classlibnative/bcltype/CMakeLists.txt +++ b/src/coreclr/src/classlibnative/bcltype/CMakeLists.txt @@ -11,7 +11,7 @@ set(BCLTYPE_SOURCES ) add_library_clr(bcltype - STATIC + OBJECT ${BCLTYPE_SOURCES} ) diff --git a/src/coreclr/src/classlibnative/float/CMakeLists.txt b/src/coreclr/src/classlibnative/float/CMakeLists.txt index 44d40c9259210a..2345ad0b91354b 100644 --- a/src/coreclr/src/classlibnative/float/CMakeLists.txt +++ b/src/coreclr/src/classlibnative/float/CMakeLists.txt @@ -8,7 +8,7 @@ set(FLOAT_SOURCES ) add_library_clr(comfloat_wks - STATIC + OBJECT ${FLOAT_SOURCES} ) diff --git a/src/coreclr/src/debug/debug-pal/CMakeLists.txt b/src/coreclr/src/debug/debug-pal/CMakeLists.txt index ac1e48fb5fb4d8..12a0005c053220 100644 --- a/src/coreclr/src/debug/debug-pal/CMakeLists.txt +++ b/src/coreclr/src/debug/debug-pal/CMakeLists.txt @@ -34,4 +34,4 @@ if(CLR_CMAKE_HOST_UNIX) endif(CLR_CMAKE_HOST_UNIX) -_add_library(debug-pal STATIC ${TWO_WAY_PIPE_SOURCES}) +_add_library(debug-pal OBJECT ${TWO_WAY_PIPE_SOURCES}) diff --git a/src/coreclr/src/debug/di/CMakeLists.txt b/src/coreclr/src/debug/di/CMakeLists.txt index d600ad3dcd08b7..6cfedda1d89900 100644 --- a/src/coreclr/src/debug/di/CMakeLists.txt +++ b/src/coreclr/src/debug/di/CMakeLists.txt @@ -59,7 +59,7 @@ if(CLR_CMAKE_HOST_WIN32) if ((CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64) AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD) convert_to_absolute_path(CORDBDI_SOURCES_ASM_FILE ${CORDBDI_SOURCES_ASM_FILE}) - preprocess_compile_asm(ASM_FILES ${CORDBDI_SOURCES_ASM_FILE} OUTPUT_OBJECTS CORDBDI_SOURCES_ASM_FILE) + preprocess_compile_asm(TARGET cordbdi ASM_FILES ${CORDBDI_SOURCES_ASM_FILE} OUTPUT_OBJECTS CORDBDI_SOURCES_ASM_FILE) endif() elseif(CLR_CMAKE_HOST_UNIX) diff --git a/src/coreclr/src/debug/ee/wks/CMakeLists.txt b/src/coreclr/src/debug/ee/wks/CMakeLists.txt index ee6c482ce76177..a6891ebb052cb3 100644 --- a/src/coreclr/src/debug/ee/wks/CMakeLists.txt +++ b/src/coreclr/src/debug/ee/wks/CMakeLists.txt @@ -9,9 +9,9 @@ if (CLR_CMAKE_TARGET_WIN32) if(CLR_CMAKE_HOST_ARCH_ARM OR CLR_CMAKE_HOST_ARCH_ARM64) - preprocess_compile_asm(ASM_FILES ${ASM_FILE} OUTPUT_OBJECTS ASM_OBJECTS) + preprocess_compile_asm(TARGET cordbee_wks ASM_FILES ${ASM_FILE} OUTPUT_OBJECTS ASM_OBJECTS) - add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ${ASM_OBJECTS}) + add_library_clr(cordbee_wks OBJECT ${CORDBEE_SOURCES_WKS} ${ASM_FILE} ${ASM_OBJECTS}) else () @@ -23,14 +23,14 @@ if (CLR_CMAKE_TARGET_WIN32) set_source_files_properties(${ASM_FILE} PROPERTIES COMPILE_OPTIONS "${ASM_OPTIONS}") - add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ${ASM_FILE}) + add_library_clr(cordbee_wks OBJECT ${CORDBEE_SOURCES_WKS} ${ASM_FILE}) endif() else () if(CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CMAKE_HOST_ARCH_ARM OR CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_I386) - add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S) + add_library_clr(cordbee_wks OBJECT ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S) else() message(FATAL_ERROR "Unknown platform") endif() diff --git a/src/coreclr/src/debug/ildbsymlib/CMakeLists.txt b/src/coreclr/src/debug/ildbsymlib/CMakeLists.txt index 88364658f110ed..b5b249228d26f6 100644 --- a/src/coreclr/src/debug/ildbsymlib/CMakeLists.txt +++ b/src/coreclr/src/debug/ildbsymlib/CMakeLists.txt @@ -10,5 +10,5 @@ set( ILDBSYMLIB_SOURCES symwrite.cpp ) -add_library_clr(ildbsymlib ${ILDBSYMLIB_SOURCES}) +add_library_clr(ildbsymlib OBJECT ${ILDBSYMLIB_SOURCES}) diff --git a/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src index 8423cff692ccc0..1ab10f83f19b76 100644 --- a/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src @@ -34,6 +34,8 @@ nativeStringResourceTable_mscorrc #PAL_GetPALDirectoryW #PAL_get_stdout #PAL_get_stderr +#PAL_GetApplicationGroupId +#PAL_GetTransportName #PAL_GetCurrentThread #PAL_GetCpuLimit #PAL_GetNativeExceptionHolderHead diff --git a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt index c6909ebcde64ae..f01133ce40ffbc 100644 --- a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -5,7 +5,8 @@ if (CLR_CMAKE_TARGET_WIN32) endif (CLR_CMAKE_TARGET_WIN32) if (CLR_CMAKE_HOST_WIN32) - preprocess_file(${DEF_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def) + set (DEF_FILE ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def) + preprocess_file(${DEF_SOURCES} ${DEF_FILE}) list(APPEND CLR_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def) @@ -65,8 +66,18 @@ add_library_clr(coreclr ${CLR_SOURCES} ) +add_library_clr(coreclr_static + STATIC + ${CLR_SOURCES} +) + add_custom_target(coreclr_exports DEPENDS ${EXPORTS_FILE}) +add_custom_target(coreclr_def DEPENDS ${DEF_FILE}) + +add_dependencies(coreclr coreclr_def) add_dependencies(coreclr coreclr_exports) +add_dependencies(coreclr_static coreclr_def) +add_dependencies(coreclr_static coreclr_exports) set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION}) set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE}) @@ -75,10 +86,6 @@ if (CLR_CMAKE_HOST_UNIX) set(LIB_UNWINDER unwinder_wks) endif (CLR_CMAKE_HOST_UNIX) -if(FEATURE_MERGE_JIT_AND_ENGINE) - set(CLRJIT_STATIC clrjit_static) -endif(FEATURE_MERGE_JIT_AND_ENGINE) - # IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is # order dependent and changing the order can result in undefined symbols in the shared # library. @@ -88,7 +95,6 @@ set(CORECLR_LIBRARIES cordbee_wks debug-pal ${LIB_UNWINDER} - cee_wks v3binder ${END_LIBRARY_GROUP} # End group of libraries that have circular references mdcompiler_wks @@ -97,7 +103,6 @@ set(CORECLR_LIBRARIES mdhotdata_full bcltype ceefgen - ${CLRJIT_STATIC} comfloat_wks corguids gcinfo @@ -159,7 +164,12 @@ if(FEATURE_EVENT_TRACE) endif(CLR_CMAKE_HOST_UNIX) endif(FEATURE_EVENT_TRACE) -target_link_libraries(coreclr ${CORECLR_LIBRARIES}) +if(FEATURE_MERGE_JIT_AND_ENGINE) + set(CLRJIT_STATIC clrjit_static) +endif(FEATURE_MERGE_JIT_AND_ENGINE) + +target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks cee_wks_core) +target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static cee_wks_mergeable cee_wks_core) # Create the runtime module index header file containing the coreclr build id # for xplat and the timestamp/size on Windows. @@ -218,5 +228,8 @@ endif(CLR_CMAKE_TARGET_WIN32) # add the install targets install_clr(TARGETS coreclr ADDITIONAL_DESTINATION sharedFramework) +# publish coreclr_static lib +_install(TARGETS coreclr_static DESTINATION lib) + # Enable profile guided optimization add_pgo(coreclr) diff --git a/src/coreclr/src/dlls/mscoree/unixinterface.cpp b/src/coreclr/src/dlls/mscoree/unixinterface.cpp index ca4d452a8edaef..9c792fcaa7801c 100644 --- a/src/coreclr/src/dlls/mscoree/unixinterface.cpp +++ b/src/coreclr/src/dlls/mscoree/unixinterface.cpp @@ -25,6 +25,9 @@ // Holder for const wide strings typedef NewArrayHolder ConstWStringHolder; +// Specifies whether coreclr is embedded or standalone +extern bool g_coreclr_embedded; + // Holder for array of wide strings class ConstWStringArrayHolder : public NewArrayHolder { @@ -171,8 +174,21 @@ int coreclr_initialize( unsigned int* domainId) { HRESULT hr; + + LPCWSTR* propertyKeysW; + LPCWSTR* propertyValuesW; + BundleProbe* bundleProbe = nullptr; + + ConvertConfigPropertiesToUnicode( + propertyKeys, + propertyValues, + propertyCount, + &propertyKeysW, + &propertyValuesW, + &bundleProbe); + #ifdef TARGET_UNIX - DWORD error = PAL_InitializeCoreCLR(exePath); + DWORD error = PAL_InitializeCoreCLR(exePath, g_coreclr_embedded); hr = HRESULT_FROM_WIN32(error); // If PAL initialization failed, then we should return right away and avoid @@ -190,18 +206,6 @@ int coreclr_initialize( ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName); - LPCWSTR* propertyKeysW; - LPCWSTR* propertyValuesW; - BundleProbe* bundleProbe = nullptr; - - ConvertConfigPropertiesToUnicode( - propertyKeys, - propertyValues, - propertyCount, - &propertyKeysW, - &propertyValuesW, - &bundleProbe); - if (bundleProbe != nullptr) { static Bundle bundle(StringToUnicode(exePath), bundleProbe); diff --git a/src/coreclr/src/dlls/mscorrc/CMakeLists.txt b/src/coreclr/src/dlls/mscorrc/CMakeLists.txt index 08cf27aaf8020d..ed5ee887650877 100644 --- a/src/coreclr/src/dlls/mscorrc/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscorrc/CMakeLists.txt @@ -19,7 +19,7 @@ if(CLR_CMAKE_HOST_WIN32) else() build_resources(${CMAKE_CURRENT_SOURCE_DIR}/include.rc mscorrc TARGET_CPP_FILE) - add_library_clr(mscorrc STATIC + add_library_clr(mscorrc OBJECT ${TARGET_CPP_FILE} ) endif(CLR_CMAKE_HOST_WIN32) diff --git a/src/coreclr/src/gcinfo/CMakeLists.txt b/src/coreclr/src/gcinfo/CMakeLists.txt index b0b67462562467..3862de8633d0cb 100644 --- a/src/coreclr/src/gcinfo/CMakeLists.txt +++ b/src/coreclr/src/gcinfo/CMakeLists.txt @@ -17,7 +17,7 @@ endif(CLR_CMAKE_TARGET_ARCH_I386) convert_to_absolute_path(GCINFO_SOURCES ${GCINFO_SOURCES}) add_library_clr(gcinfo - STATIC + OBJECT ${GCINFO_SOURCES} ) diff --git a/src/coreclr/src/inc/CMakeLists.txt b/src/coreclr/src/inc/CMakeLists.txt index 60fad88e77dd29..81762201251665 100644 --- a/src/coreclr/src/inc/CMakeLists.txt +++ b/src/coreclr/src/inc/CMakeLists.txt @@ -58,7 +58,7 @@ if(FEATURE_JIT_PITCHING) endif(FEATURE_JIT_PITCHING) # Compile *_i.cpp to lib -_add_library(corguids ${CORGUIDS_SOURCES}) +_add_library(corguids OBJECT ${CORGUIDS_SOURCES}) # Binplace the inc files for packaging later. diff --git a/src/coreclr/src/interop/CMakeLists.txt b/src/coreclr/src/interop/CMakeLists.txt index d7eaa1b04ae63d..b8a0e769318db3 100644 --- a/src/coreclr/src/interop/CMakeLists.txt +++ b/src/coreclr/src/interop/CMakeLists.txt @@ -31,6 +31,6 @@ endif(WIN32) convert_to_absolute_path(INTEROP_SOURCES ${INTEROP_SOURCES}) add_library_clr(interop - STATIC + OBJECT ${INTEROP_SOURCES} ) diff --git a/src/coreclr/src/jit/CMakeLists.txt b/src/coreclr/src/jit/CMakeLists.txt index 675f676d8c4b4f..15aa4d59b63ccd 100644 --- a/src/coreclr/src/jit/CMakeLists.txt +++ b/src/coreclr/src/jit/CMakeLists.txt @@ -305,13 +305,15 @@ convert_to_absolute_path(JIT_ARM_SOURCES ${JIT_ARM_SOURCES}) convert_to_absolute_path(JIT_I386_SOURCES ${JIT_I386_SOURCES}) convert_to_absolute_path(JIT_ARM64_SOURCES ${JIT_ARM64_SOURCES}) +set(JIT_DLL_MAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/dllmain.cpp) if(CLR_CMAKE_TARGET_WIN32) set(CLRJIT_EXPORTS ${CMAKE_CURRENT_LIST_DIR}/ClrJit.exports) set(JIT_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/ClrJit.exports.def) preprocess_file (${CLRJIT_EXPORTS} ${JIT_EXPORTS_FILE}) - set(SHARED_LIB_SOURCES ${SOURCES} ${JIT_EXPORTS_FILE}) + set(JIT_CORE_SOURCES ${SOURCES}) + set(JIT_DEF_FILE ${JIT_EXPORTS_FILE}) else() set(CLRJIT_EXPORTS ${CMAKE_CURRENT_LIST_DIR}/ClrJit.PAL.exports) @@ -325,7 +327,7 @@ else() set_exports_linker_option(${JIT_EXPORTS_FILE}) set(JIT_EXPORTS_LINKER_OPTION ${EXPORTS_LINKER_OPTION}) - set(SHARED_LIB_SOURCES ${SOURCES}) + set(JIT_CORE_SOURCES ${SOURCES}) endif() add_custom_target(jit_exports DEPENDS ${JIT_EXPORTS_FILE}) @@ -373,8 +375,10 @@ function(add_jit jitName) add_library_clr(${jitName} SHARED - ${SHARED_LIB_SOURCES} + ${JIT_CORE_SOURCES} ${JIT_ARCH_SOURCES} + ${JIT_DEF_FILE} + ${JIT_DLL_MAIN_FILE} ) target_precompile_header(TARGET ${jitName} HEADER jitpch.h ADDITIONAL_INCLUDE_DIRECTORIES ${JIT_SOURCE_DIR}) @@ -396,11 +400,12 @@ endfunction() set(JIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) if (FEATURE_MERGE_JIT_AND_ENGINE) - # Despite the directory being named "dll", it creates a static library "clrjit_static" to link into the VM. - add_subdirectory(dll) add_subdirectory(crossgen) endif (FEATURE_MERGE_JIT_AND_ENGINE) +# Creates a static library "clrjit_static" to link into the VM. +add_subdirectory(static) + add_subdirectory(standalone) if (CLR_CMAKE_HOST_ARCH_I386 OR CLR_CMAKE_HOST_ARCH_AMD64) diff --git a/src/coreclr/src/jit/codegenarmarch.cpp b/src/coreclr/src/jit/codegenarmarch.cpp index 496f723f82767f..291645eba9fde5 100644 --- a/src/coreclr/src/jit/codegenarmarch.cpp +++ b/src/coreclr/src/jit/codegenarmarch.cpp @@ -2477,8 +2477,10 @@ void CodeGen::genCallInstruction(GenTreeCall* call) { // Generate a direct call to a non-virtual user defined or helper method assert(callType == CT_HELPER || callType == CT_USER_FUNC); +#ifdef FEATURE_READYTORUN_COMPILER assert(((call->IsR2RRelativeIndir()) && (call->gtEntryPoint.accessType == IAT_PVALUE)) || ((call->IsVirtualStubRelativeIndir()) && (call->gtEntryPoint.accessType == IAT_VALUE))); +#endif // FEATURE_READYTORUN_COMPILER assert(call->gtControlExpr == nullptr); assert(!call->IsTailCall()); diff --git a/src/coreclr/src/jit/dllmain.cpp b/src/coreclr/src/jit/dllmain.cpp new file mode 100644 index 00000000000000..6cd0add128d3e0 --- /dev/null +++ b/src/coreclr/src/jit/dllmain.cpp @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include "jitpch.h" +#ifdef _MSC_VER +#pragma hdrstop +#endif +#include "emit.h" +#include "corexcep.h" + +#ifndef DLLEXPORT +#define DLLEXPORT +#endif // !DLLEXPORT + +extern void jitShutdown(bool processIsTerminating); + +HINSTANCE g_hInst = nullptr; + +/*****************************************************************************/ +extern "C" DLLEXPORT BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID pvReserved) +{ + if (dwReason == DLL_PROCESS_ATTACH) + { + g_hInst = (HINSTANCE)hInstance; + DisableThreadLibraryCalls((HINSTANCE)hInstance); + } + else if (dwReason == DLL_PROCESS_DETACH) + { + // From MSDN: If fdwReason is DLL_PROCESS_DETACH, lpvReserved is NULL if FreeLibrary has + // been called or the DLL load failed and non-NULL if the process is terminating. + bool processIsTerminating = (pvReserved != nullptr); + jitShutdown(processIsTerminating); + } + + return TRUE; +} + +HINSTANCE GetModuleInst() +{ + return (g_hInst); +} diff --git a/src/coreclr/src/jit/ee_il_dll.cpp b/src/coreclr/src/jit/ee_il_dll.cpp index 78d3d8e59274aa..ee3a29dc036aac 100644 --- a/src/coreclr/src/jit/ee_il_dll.cpp +++ b/src/coreclr/src/jit/ee_il_dll.cpp @@ -37,9 +37,6 @@ FILE* jitstdout = nullptr; ICorJitHost* g_jitHost = nullptr; static CILJit* ILJitter = nullptr; // The one and only JITTER I return bool g_jitInitialized = false; -#ifndef FEATURE_MERGE_JIT_AND_ENGINE -HINSTANCE g_hInst = nullptr; -#endif // FEATURE_MERGE_JIT_AND_ENGINE /*****************************************************************************/ @@ -154,33 +151,6 @@ void jitShutdown(bool processIsTerminating) g_jitInitialized = false; } -#ifndef FEATURE_MERGE_JIT_AND_ENGINE - -extern "C" DLLEXPORT BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID pvReserved) -{ - if (dwReason == DLL_PROCESS_ATTACH) - { - g_hInst = (HINSTANCE)hInstance; - DisableThreadLibraryCalls((HINSTANCE)hInstance); - } - else if (dwReason == DLL_PROCESS_DETACH) - { - // From MSDN: If fdwReason is DLL_PROCESS_DETACH, lpvReserved is NULL if FreeLibrary has - // been called or the DLL load failed and non-NULL if the process is terminating. - bool processIsTerminating = (pvReserved != nullptr); - jitShutdown(processIsTerminating); - } - - return TRUE; -} - -HINSTANCE GetModuleInst() -{ - return (g_hInst); -} - -#endif // !FEATURE_MERGE_JIT_AND_ENGINE - /*****************************************************************************/ struct CILJitSingletonAllocator diff --git a/src/coreclr/src/jit/dll/CMakeLists.txt b/src/coreclr/src/jit/static/CMakeLists.txt similarity index 59% rename from src/coreclr/src/jit/dll/CMakeLists.txt rename to src/coreclr/src/jit/static/CMakeLists.txt index ec7cddc78eda4b..b4e62c041cd449 100644 --- a/src/coreclr/src/jit/dll/CMakeLists.txt +++ b/src/coreclr/src/jit/static/CMakeLists.txt @@ -2,17 +2,14 @@ project(ClrJit) set_source_files_properties(${JIT_EXPORTS_FILE} PROPERTIES GENERATED TRUE) +add_library_clr(clrjit_static + OBJECT + ${JIT_CORE_SOURCES} + ${JIT_ARCH_SOURCES} +) + if(CLR_CMAKE_HOST_UNIX) - add_library_clr(clrjit_static - STATIC - ${SHARED_LIB_SOURCES} - ${JIT_ARCH_SOURCES} - ) add_dependencies(clrjit_static coreclrpal gcinfo) -else() - add_library_clr(clrjit_static - ${SHARED_LIB_SOURCES} - ${JIT_ARCH_SOURCES} - ) endif(CLR_CMAKE_HOST_UNIX) + target_precompile_header(TARGET clrjit_static HEADER jitpch.h ADDITIONAL_INCLUDE_DIRECTORIES ${JIT_SOURCE_DIR}) diff --git a/src/coreclr/src/jit/dll/clrjit.def b/src/coreclr/src/jit/static/clrjit.def similarity index 100% rename from src/coreclr/src/jit/dll/clrjit.def rename to src/coreclr/src/jit/static/clrjit.def diff --git a/src/coreclr/src/md/ceefilegen/CMakeLists.txt b/src/coreclr/src/md/ceefilegen/CMakeLists.txt index 90749c806b2322..39864c71817f55 100644 --- a/src/coreclr/src/md/ceefilegen/CMakeLists.txt +++ b/src/coreclr/src/md/ceefilegen/CMakeLists.txt @@ -26,7 +26,7 @@ if (CLR_CMAKE_TARGET_WIN32) endif (CLR_CMAKE_TARGET_WIN32) add_library_clr(ceefgen - STATIC + OBJECT ${CEEFILEGEN_SOURCES} ) target_precompile_header(TARGET ceefgen HEADER stdafx.h) diff --git a/src/coreclr/src/md/compiler/CMakeLists.txt b/src/coreclr/src/md/compiler/CMakeLists.txt index 3b916cdc9fe804..6b89cfa5308de1 100644 --- a/src/coreclr/src/md/compiler/CMakeLists.txt +++ b/src/coreclr/src/md/compiler/CMakeLists.txt @@ -58,7 +58,7 @@ add_library_clr(mdcompiler_dac ${MDCOMPILER_SOURCES}) set_target_properties(mdcompiler_dac PROPERTIES DAC_COMPONENT TRUE) target_precompile_header(TARGET mdcompiler_dac HEADER stdafx.h) -add_library_clr(mdcompiler_wks ${MDCOMPILER_SOURCES}) +add_library_clr(mdcompiler_wks OBJECT ${MDCOMPILER_SOURCES}) target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_EMIT_ALL) target_precompile_header(TARGET mdcompiler_wks HEADER stdafx.h) diff --git a/src/coreclr/src/md/enc/CMakeLists.txt b/src/coreclr/src/md/enc/CMakeLists.txt index 221bb8cab4557e..bf209317d0322d 100644 --- a/src/coreclr/src/md/enc/CMakeLists.txt +++ b/src/coreclr/src/md/enc/CMakeLists.txt @@ -48,7 +48,7 @@ add_library_clr(mdruntimerw_dac ${MDRUNTIMERW_SOURCES}) set_target_properties(mdruntimerw_dac PROPERTIES DAC_COMPONENT TRUE) target_precompile_header(TARGET mdruntimerw_dac HEADER stdafx.h) -add_library_clr(mdruntimerw_wks ${MDRUNTIMERW_SOURCES}) +add_library_clr(mdruntimerw_wks OBJECT ${MDRUNTIMERW_SOURCES}) target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_EMIT_ALL) target_precompile_header(TARGET mdruntimerw_wks HEADER stdafx.h) diff --git a/src/coreclr/src/md/hotdata/CMakeLists.txt b/src/coreclr/src/md/hotdata/CMakeLists.txt index c6168d2a4b0c27..6f7a2891d20c88 100644 --- a/src/coreclr/src/md/hotdata/CMakeLists.txt +++ b/src/coreclr/src/md/hotdata/CMakeLists.txt @@ -33,7 +33,7 @@ add_library_clr(mdhotdata_dac ${MDHOTDATA_SOURCES}) set_target_properties(mdhotdata_dac PROPERTIES DAC_COMPONENT TRUE) target_precompile_header(TARGET mdhotdata_dac HEADER external.h) -add_library_clr(mdhotdata_full ${MDHOTDATA_SOURCES}) +add_library_clr(mdhotdata_full OBJECT ${MDHOTDATA_SOURCES}) target_precompile_header(TARGET mdhotdata_full HEADER external.h) add_library_clr(mdhotdata_crossgen ${MDHOTDATA_SOURCES}) diff --git a/src/coreclr/src/md/runtime/CMakeLists.txt b/src/coreclr/src/md/runtime/CMakeLists.txt index 9b5e3f2afaeffa..99b8bec54958ce 100644 --- a/src/coreclr/src/md/runtime/CMakeLists.txt +++ b/src/coreclr/src/md/runtime/CMakeLists.txt @@ -46,7 +46,7 @@ add_library_clr(mdruntime_dac ${MDRUNTIME_SOURCES}) set_target_properties(mdruntime_dac PROPERTIES DAC_COMPONENT TRUE) target_precompile_header(TARGET mdruntime_dac HEADER stdafx.h) -add_library_clr(mdruntime_wks ${MDRUNTIME_SOURCES}) +add_library_clr(mdruntime_wks OBJECT ${MDRUNTIME_SOURCES}) target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_EMIT_ALL) target_precompile_header(TARGET mdruntime_wks HEADER stdafx.h) diff --git a/src/coreclr/src/nativeresources/CMakeLists.txt b/src/coreclr/src/nativeresources/CMakeLists.txt index 947a9143897071..ab3e53863e3fc9 100644 --- a/src/coreclr/src/nativeresources/CMakeLists.txt +++ b/src/coreclr/src/nativeresources/CMakeLists.txt @@ -5,3 +5,4 @@ add_library_clr(nativeresourcestring resourcestring.cpp ) +_install (TARGETS nativeresourcestring DESTINATION lib) diff --git a/src/coreclr/src/pal/inc/pal.h b/src/coreclr/src/pal/inc/pal.h index 7ffdc2b7ec3205..b7303bfe80a147 100644 --- a/src/coreclr/src/pal/inc/pal.h +++ b/src/coreclr/src/pal/inc/pal.h @@ -377,7 +377,7 @@ PALIMPORT DWORD PALAPI PAL_InitializeCoreCLR( - const char *szExePath); + const char *szExePath, bool runningInExe); /// /// This function shuts down PAL WITHOUT exiting the current process. diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index 1a393638322856..89c3ed934454df 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -17,36 +17,9 @@ if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) add_subdirectory(libunwind) elseif(NOT CLR_CMAKE_TARGET_OSX) - if(CLR_CMAKE_HOST_ARCH_ARM) - find_library(UNWIND_ARCH NAMES unwind-arm) - endif() - - if(CLR_CMAKE_HOST_ARCH_ARM64) - find_library(UNWIND_ARCH NAMES unwind-aarch64) - endif() - - if(CLR_CMAKE_HOST_ARCH_AMD64) - find_library(UNWIND_ARCH NAMES unwind-x86_64) - endif() - - if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) - set(UNWIND_LIBS ${UNWIND_ARCH}) - endif() - - find_library(UNWIND_GENERIC NAMES unwind-generic) - - if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND) - set(UNWIND_LIBS ${UNWIND_LIBS} ${UNWIND_GENERIC}) - endif() - - find_library(UNWIND NAMES unwind) - - if(UNWIND STREQUAL UNWIND-NOTFOUND) - message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.") - endif() - - set(UNWIND_LIBS ${UNWIND_LIBS} ${UNWIND}) + find_unwind_libs(UNWIND_LIBS) endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) + include(configure.cmake) project(coreclrpal) @@ -261,7 +234,7 @@ add_library(coreclrpal # if(CLR_CMAKE_TARGET_LINUX) add_library(tracepointprovider - STATIC + OBJECT misc/tracepointprovider.cpp ) endif(CLR_CMAKE_TARGET_LINUX) diff --git a/src/coreclr/src/pal/src/init/pal.cpp b/src/coreclr/src/pal/src/init/pal.cpp index cd7a5797c9e5cc..5fcd0c5289558d 100644 --- a/src/coreclr/src/pal/src/init/pal.cpp +++ b/src/coreclr/src/pal/src/init/pal.cpp @@ -103,6 +103,8 @@ using namespace CorUnix; extern "C" BOOL CRTInitStdStreams( void ); +extern bool g_running_in_exe; + Volatile init_count = 0; Volatile shutdown_intent = 0; Volatile g_coreclrInitialized = 0; @@ -786,8 +788,10 @@ exit : --*/ PAL_ERROR PALAPI -PAL_InitializeCoreCLR(const char *szExePath) +PAL_InitializeCoreCLR(const char *szExePath, bool runningInExe) { + g_running_in_exe = runningInExe; + // Fake up a command line to call PAL initialization with. int result = Initialize(1, &szExePath, PAL_INITIALIZE_CORECLR); if (result != 0) diff --git a/src/coreclr/src/pal/src/loader/module.cpp b/src/coreclr/src/pal/src/loader/module.cpp index 65168978ba743b..f1b4faa65003ef 100644 --- a/src/coreclr/src/pal/src/loader/module.cpp +++ b/src/coreclr/src/pal/src/loader/module.cpp @@ -87,6 +87,7 @@ MODSTRUCT exe_module; MODSTRUCT *pal_module = nullptr; char * g_szCoreCLRPath = nullptr; +bool g_running_in_exe = false; int MaxWCharToAcpLength = 3; @@ -1436,6 +1437,18 @@ static LPWSTR LOADGetModuleFileName(MODSTRUCT *module) return module->lib_name; } +static bool ShouldRedirectToCurrentLibrary(LPCSTR libraryNameOrPath) +{ + if (!g_running_in_exe) + return false; + + // Getting nullptr as name indicates redirection to current library + if (libraryNameOrPath == nullptr) + return true; + + return false; +} + /* Function: LOADLoadLibraryDirect [internal] @@ -1450,10 +1463,19 @@ Return value: */ static NATIVE_LIBRARY_HANDLE LOADLoadLibraryDirect(LPCSTR libraryNameOrPath) { - _ASSERTE(libraryNameOrPath != nullptr); - _ASSERTE(libraryNameOrPath[0] != '\0'); + NATIVE_LIBRARY_HANDLE dl_handle; + + if (ShouldRedirectToCurrentLibrary(libraryNameOrPath)) + { + dl_handle = dlopen(NULL, RTLD_LAZY); + } + else + { + _ASSERTE(libraryNameOrPath != nullptr); + _ASSERTE(libraryNameOrPath[0] != '\0'); + dl_handle = dlopen(libraryNameOrPath, RTLD_LAZY); + } - NATIVE_LIBRARY_HANDLE dl_handle = dlopen(libraryNameOrPath, RTLD_LAZY); if (dl_handle == nullptr) { SetLastError(ERROR_MOD_NOT_FOUND); @@ -1536,8 +1558,7 @@ Return value: static MODSTRUCT *LOADAddModule(NATIVE_LIBRARY_HANDLE dl_handle, LPCSTR libraryNameOrPath) { _ASSERTE(dl_handle != nullptr); - _ASSERTE(libraryNameOrPath != nullptr); - _ASSERTE(libraryNameOrPath[0] != '\0'); + _ASSERTE(g_running_in_exe || (libraryNameOrPath != nullptr && libraryNameOrPath[0] != '\0')); #if !RETURNS_NEW_HANDLES_ON_REPEAT_DLOPEN /* search module list for a match. */ @@ -1663,7 +1684,8 @@ Function : implementation of LoadLibrary (for use by the A/W variants) Parameters : - LPSTR shortAsciiName : name of module as specified to LoadLibrary + LPSTR shortAsciiName : name of module as specified to LoadLibrary. + Could be nullptr if loading containing executable. BOOL fDynamic : TRUE if dynamic load through LoadLibrary, FALSE if static load through RegisterLibrary @@ -1676,7 +1698,8 @@ static HMODULE LOADLoadLibrary(LPCSTR shortAsciiName, BOOL fDynamic) HMODULE module = nullptr; NATIVE_LIBRARY_HANDLE dl_handle = nullptr; - shortAsciiName = FixLibCName(shortAsciiName); + if (shortAsciiName != nullptr) + shortAsciiName = FixLibCName(shortAsciiName); LockModuleList(); @@ -1762,7 +1785,14 @@ MODSTRUCT *LOADGetPalLibrary() } } - pal_module = (MODSTRUCT *)LOADLoadLibrary(info.dli_fname, FALSE); + if (g_running_in_exe) + { + pal_module = (MODSTRUCT*)LOADLoadLibrary(nullptr, FALSE); + } + else + { + pal_module = (MODSTRUCT*)LOADLoadLibrary(info.dli_fname, FALSE); + } } exit: diff --git a/src/coreclr/src/unwinder/CMakeLists.txt b/src/coreclr/src/unwinder/CMakeLists.txt index 8be5f3b21ea6da..98cdb0c0b7a891 100644 --- a/src/coreclr/src/unwinder/CMakeLists.txt +++ b/src/coreclr/src/unwinder/CMakeLists.txt @@ -20,7 +20,7 @@ list(APPEND UNWINDER_SOURCES convert_to_absolute_path(UNWINDER_SOURCES ${UNWINDER_SOURCES}) if(CLR_CMAKE_HOST_UNIX) - add_library_clr(unwinder_wks ${UNWINDER_SOURCES}) + add_library_clr(unwinder_wks OBJECT ${UNWINDER_SOURCES}) add_dependencies(unwinder_wks eventing_headers) endif(CLR_CMAKE_HOST_UNIX) diff --git a/src/coreclr/src/utilcode/CMakeLists.txt b/src/coreclr/src/utilcode/CMakeLists.txt index b5739712d0edcc..4c1ce806b65101 100644 --- a/src/coreclr/src/utilcode/CMakeLists.txt +++ b/src/coreclr/src/utilcode/CMakeLists.txt @@ -97,7 +97,7 @@ convert_to_absolute_path(UTILCODE_CROSSGEN_SOURCES ${UTILCODE_CROSSGEN_SOURCES}) convert_to_absolute_path(UTILCODE_STATICNOHOST_SOURCES ${UTILCODE_STATICNOHOST_SOURCES}) add_library_clr(utilcode_dac STATIC ${UTILCODE_DAC_SOURCES}) -add_library_clr(utilcode STATIC ${UTILCODE_SOURCES}) +add_library_clr(utilcode OBJECT ${UTILCODE_SOURCES}) add_library_clr(utilcodestaticnohost STATIC ${UTILCODE_STATICNOHOST_SOURCES}) add_library_clr(utilcode_crossgen STATIC ${UTILCODE_CROSSGEN_SOURCES}) diff --git a/src/coreclr/src/vm/CMakeLists.txt b/src/coreclr/src/vm/CMakeLists.txt index a5b98ef3c86b24..b60ec519570a12 100644 --- a/src/coreclr/src/vm/CMakeLists.txt +++ b/src/coreclr/src/vm/CMakeLists.txt @@ -304,7 +304,6 @@ set(VM_SOURCES_WKS cachelinealloc.cpp callhelpers.cpp callsiteinspect.cpp - ceemain.cpp clrconfignative.cpp clrex.cpp clrprivbinderutil.cpp @@ -409,6 +408,9 @@ set(VM_SOURCES_WKS ${VM_SOURCES_GDBJIT} ) +# coreclr needs to compile codeman.cpp differently depending on flavor (i.e. dll vs. static lib)) +list(REMOVE_ITEM VM_SOURCES_WKS codeman.cpp) + set(VM_HEADERS_WKS ${VM_HEADERS_DAC_AND_WKS_COMMON} ../inc/jithelpers.h @@ -910,9 +912,16 @@ if (CLR_CMAKE_TARGET_WIN32) list(APPEND VM_SOURCES_DAC ${VM_HEADERS_DAC}) endif(CLR_CMAKE_TARGET_WIN32) +#these two files we need to compile differently for standalone and mergeable flavors of WKS +set (VM_SOURCES_WKS_SPECIAL + codeman.cpp + ceemain.cpp +) + convert_to_absolute_path(VM_SOURCES_WKS ${VM_SOURCES_WKS}) convert_to_absolute_path(VM_SOURCES_WKS_ARCH_ASM ${VM_SOURCES_WKS_ARCH_ASM}) convert_to_absolute_path(VM_SOURCES_DAC ${VM_SOURCES_DAC}) +convert_to_absolute_path(VM_SOURCES_WKS_SPECIAL ${VM_SOURCES_WKS_SPECIAL}) add_library_clr(cee_dac ${VM_SOURCES_DAC}) add_dependencies(cee_dac eventing_headers) diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index 8375876c527598..cf2e3bb3ea5163 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -240,8 +240,12 @@ extern "C" HRESULT __cdecl CorDBGetInterface(DebugInterface** rcInterface); #endif // DEBUGGING_SUPPORTED #endif // !CROSSGEN_COMPILE - - +// g_coreclr_embedded indicates that coreclr is linked directly into the program +#ifdef CORECLR_EMBEDDED +bool g_coreclr_embedded = true; +#else +bool g_coreclr_embedded = false; +#endif // Remember how the last startup of EE went. HRESULT g_EEStartupStatus = S_OK; @@ -481,6 +485,13 @@ void InitGSCookie() } CONTRACTL_END; +#if defined(TARGET_OSX) && defined(CORECLR_EMBEDDED) + // OSX does not like the way we change section protection when running in a superhost bundle + // disabling this for now + // https://github.com/dotnet/runtime/issues/38184 + return; +#endif + volatile GSCookie * pGSCookiePtr = GetProcessGSCookiePtr(); #ifdef TARGET_UNIX diff --git a/src/coreclr/src/vm/debughelp.cpp b/src/coreclr/src/vm/debughelp.cpp index 02cfbe4cc1feb1..53220fc81af406 100644 --- a/src/coreclr/src/vm/debughelp.cpp +++ b/src/coreclr/src/vm/debughelp.cpp @@ -1016,10 +1016,6 @@ void PrintDomainName(size_t ob) #include "gcdump.h" -#include "../gcdump/i386/gcdumpx86.cpp" - -#include "../gcdump/gcdump.cpp" - /*********************************************************************/ void printfToDbgOut(const char* fmt, ...) { diff --git a/src/coreclr/src/vm/eventing/eventpipe/CMakeLists.txt b/src/coreclr/src/vm/eventing/eventpipe/CMakeLists.txt index 00b3f6f386f240..4e816676b8a755 100644 --- a/src/coreclr/src/vm/eventing/eventpipe/CMakeLists.txt +++ b/src/coreclr/src/vm/eventing/eventpipe/CMakeLists.txt @@ -28,7 +28,7 @@ add_custom_command(OUTPUT ${EVENTPIPE_SOURCES} COMMAND ${GENERATE_COMMAND} DEPENDS ${GENERATE_SCRIPT} ${EVENT_MANIFEST} ${EVENT_EXCLUSIONS}) -add_library_clr(eventpipe STATIC ${EVENTPIPE_SOURCES}) +add_library_clr(eventpipe OBJECT ${EVENTPIPE_SOURCES}) set_target_properties(eventpipe PROPERTIES LINKER_LANGUAGE CXX) add_dependencies(eventpipe eventing_headers) diff --git a/src/coreclr/src/vm/wks/CMakeLists.txt b/src/coreclr/src/vm/wks/CMakeLists.txt index 1e94b575fd6402..bd675204bd78ab 100644 --- a/src/coreclr/src/vm/wks/CMakeLists.txt +++ b/src/coreclr/src/vm/wks/CMakeLists.txt @@ -1,19 +1,22 @@ if (CLR_CMAKE_TARGET_WIN32) + if(CLR_CMAKE_HOST_ARCH_ARM OR CLR_CMAKE_HOST_ARCH_ARM64) - preprocess_compile_asm(ASM_FILES ${VM_SOURCES_WKS_ARCH_ASM} OUTPUT_OBJECTS VM_WKS_ARCH_ASM_OBJECTS) - list(APPEND VM_SOURCES_WKS_ARCH_ASM ${VM_WKS_ARCH_ASM_OBJECTS}) + preprocess_compile_asm(TARGET cee_wks_core ASM_FILES ${VM_SOURCES_WKS_ARCH_ASM} OUTPUT_OBJECTS VM_WKS_ARCH_ASM_OBJECTS) endif() endif (CLR_CMAKE_TARGET_WIN32) -add_library_clr(cee_wks ${VM_SOURCES_WKS} ${VM_SOURCES_WKS_ARCH_ASM}) -target_precompile_header(TARGET cee_wks HEADER common.h) +add_library_clr(cee_wks_core OBJECT ${VM_SOURCES_WKS} ${VM_SOURCES_WKS_ARCH_ASM}) + +target_precompile_header(TARGET cee_wks_core HEADER common.h) + if (MSVC) # mscorlib.cpp does not compile with precompiled header file set_source_files_properties(../mscorlib.cpp PROPERTIES COMPILE_FLAGS "/Y-") endif() -add_dependencies(cee_wks eventing_headers) + +add_dependencies(cee_wks_core eventing_headers) if (CLR_CMAKE_TARGET_WIN32) @@ -45,8 +48,21 @@ if (CLR_CMAKE_TARGET_WIN32) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc ) - add_dependencies(cee_wks asmconstants_inc) + add_dependencies(cee_wks_core asmconstants_inc) endif(NOT CLR_CMAKE_HOST_ARCH_ARM AND NOT CLR_CMAKE_HOST_ARCH_ARM64) endif (CLR_CMAKE_TARGET_WIN32) + +add_library_clr(cee_wks OBJECT ${VM_SOURCES_WKS_SPECIAL} $ ${VM_WKS_ARCH_ASM_OBJECTS}) +add_library_clr(cee_wks_mergeable OBJECT ${VM_SOURCES_WKS_SPECIAL} $ ${VM_WKS_ARCH_ASM_OBJECTS}) + +add_custom_target(preprocessd_asm DEPENDS ${VM_WKS_ARCH_ASM_OBJECTS}) +add_dependencies(cee_wks preprocessd_asm) +add_dependencies(cee_wks_mergeable preprocessd_asm) + +target_precompile_header(TARGET cee_wks HEADER common.h) +target_precompile_header(TARGET cee_wks_mergeable HEADER common.h) + +target_compile_definitions(cee_wks_mergeable PUBLIC FEATURE_MERGE_JIT_AND_ENGINE) +target_compile_definitions(cee_wks_mergeable PUBLIC CORECLR_EMBEDDED) diff --git a/src/installer/corehost/build.cmd b/src/installer/corehost/build.cmd index 54c8f5b3af2f0f..f494516569130e 100644 --- a/src/installer/corehost/build.cmd +++ b/src/installer/corehost/build.cmd @@ -38,6 +38,8 @@ if /i [%1] == [commit] (set __CommitSha=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [incremental-native-build] ( set __IncrementalNativeBuild=1&&shift&goto Arg_Loop) if /i [%1] == [rootDir] ( set __rootDir=%2&&shift&&shift&goto Arg_Loop) +if /i [%1] == [coreclrartifacts] (set __CoreClrArtifacts=%2&&shift&&shift&goto Arg_Loop) + shift goto :Arg_Loop diff --git a/src/installer/corehost/build.proj b/src/installer/corehost/build.proj index 4a475a45589d94..6a3f561209e143 100644 --- a/src/installer/corehost/build.proj +++ b/src/installer/corehost/build.proj @@ -33,6 +33,7 @@ $(BuildArgs) -cross $(BuildArgs) $(Compiler) $(BuildArgs) $(CMakeArgs) + $(BuildArgs) -coreclrartifacts $(CoreCLRArtifactsPath) @@ -27,8 +25,6 @@ - - diff --git a/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt index 1942630a82ef15..ca9ed1fbe159ed 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt @@ -81,7 +81,7 @@ if (GEN_SHARED_LIB) endif() add_library(System.Globalization.Native-Static - STATIC + OBJECT ${NATIVEGLOBALIZATION_SOURCES} )