Skip to content

Commit f93065f

Browse files
authored
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
1 parent 98b6284 commit f93065f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+622
-276
lines changed

eng/native/functions.cmake

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,46 @@ endfunction(get_include_directories)
6868
function(get_include_directories_asm IncludeDirectories)
6969
get_directory_property(dirs INCLUDE_DIRECTORIES)
7070

71-
if (CLR_CMAKE_HOST_ARCH_ARM AND WIN32)
72-
list(APPEND INC_DIRECTORIES "-I ")
73-
endif()
74-
7571
foreach(dir IN LISTS dirs)
76-
if (CLR_CMAKE_HOST_ARCH_ARM AND WIN32)
77-
list(APPEND INC_DIRECTORIES ${dir};)
78-
else()
79-
list(APPEND INC_DIRECTORIES -I${dir})
80-
endif()
72+
list(APPEND INC_DIRECTORIES -I${dir};)
8173
endforeach()
8274

8375
set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
8476
endfunction(get_include_directories_asm)
8577

78+
# Finds and returns unwind libs
79+
function(find_unwind_libs UnwindLibs)
80+
if(CLR_CMAKE_HOST_ARCH_ARM)
81+
find_library(UNWIND_ARCH NAMES unwind-arm)
82+
endif()
83+
84+
if(CLR_CMAKE_HOST_ARCH_ARM64)
85+
find_library(UNWIND_ARCH NAMES unwind-aarch64)
86+
endif()
87+
88+
if(CLR_CMAKE_HOST_ARCH_AMD64)
89+
find_library(UNWIND_ARCH NAMES unwind-x86_64)
90+
endif()
91+
92+
if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)
93+
set(UNWIND_LIBS ${UNWIND_ARCH})
94+
endif()
95+
96+
find_library(UNWIND_GENERIC NAMES unwind-generic)
97+
98+
if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)
99+
set(UNWIND_LIBS ${UNWIND_LIBS} ${UNWIND_GENERIC})
100+
endif()
101+
102+
find_library(UNWIND NAMES unwind)
103+
104+
if(UNWIND STREQUAL UNWIND-NOTFOUND)
105+
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.")
106+
endif()
107+
108+
set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
109+
endfunction(find_unwind_libs)
110+
86111
# Set the passed in RetSources variable to the list of sources with added current source directory
87112
# to form absolute paths.
88113
# The parameters after the RetSources are the input files.
@@ -118,10 +143,10 @@ function(preprocess_file inputFilename outputFilename)
118143
PROPERTIES GENERATED TRUE)
119144
endfunction()
120145

121-
# preprocess_compile_asm(ASM_FILES file1 [file2 ...] OUTPUT_OBJECTS [variableName])
146+
# preprocess_compile_asm(TARGET target ASM_FILES file1 [file2 ...] OUTPUT_OBJECTS [variableName])
122147
function(preprocess_compile_asm)
123148
set(options "")
124-
set(oneValueArgs OUTPUT_OBJECTS)
149+
set(oneValueArgs TARGET OUTPUT_OBJECTS)
125150
set(multiValueArgs ASM_FILES)
126151
cmake_parse_arguments(PARSE_ARGV 0 COMPILE_ASM "${options}" "${oneValueArgs}" "${multiValueArgs}")
127152

@@ -135,28 +160,21 @@ function(preprocess_compile_asm)
135160
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${name}.asm" ASM_PREPROCESSED_FILE)
136161
preprocess_file(${ASM_FILE} ${ASM_PREPROCESSED_FILE})
137162

138-
# We do not pass any defines since we have already done pre-processing above
139-
set (ASM_CMDLINE "-o ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj ${ASM_PREPROCESSED_FILE}")
140-
141-
# Generate the batch file that will invoke the assembler
142-
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/runasm_${name}.cmd" ASM_SCRIPT_FILE)
143-
144-
file(GENERATE OUTPUT "${ASM_SCRIPT_FILE}"
145-
CONTENT "\"${CMAKE_ASM_MASM_COMPILER}\" -g ${ASM_INCLUDE_DIRECTORIES} ${ASM_CMDLINE}")
146-
147-
message("Generated - ${ASM_SCRIPT_FILE}")
163+
# Produce object file where CMake would store .obj files for an OBJECT library.
164+
# ex: artifacts\obj\coreclr\Windows_NT.arm64.Debug\src\vm\wks\cee_wks.dir\Debug\AsmHelpers.obj
165+
set (OBJ_FILE "${CMAKE_CURRENT_BINARY_DIR}/${COMPILE_ASM_TARGET}.dir/${CMAKE_CFG_INTDIR}/${name}.obj")
148166

149167
# Need to compile asm file using custom command as include directories are not provided to asm compiler
150-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj
151-
COMMAND ${ASM_SCRIPT_FILE}
168+
add_custom_command(OUTPUT ${OBJ_FILE}
169+
COMMAND "${CMAKE_ASM_MASM_COMPILER}" -g ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_PREPROCESSED_FILE}
152170
DEPENDS ${ASM_PREPROCESSED_FILE}
153-
COMMENT "Assembling ${ASM_PREPROCESSED_FILE} - ${ASM_SCRIPT_FILE}")
171+
COMMENT "Assembling ${ASM_PREPROCESSED_FILE} ---> \"${CMAKE_ASM_MASM_COMPILER}\" -g ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_PREPROCESSED_FILE}")
154172

155173
# mark obj as source that does not require compile
156-
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${name}.obj PROPERTIES EXTERNAL_OBJECT TRUE)
174+
set_source_files_properties(${OBJ_FILE} PROPERTIES EXTERNAL_OBJECT TRUE)
157175

158176
# Add the generated OBJ in the dependency list so that it gets consumed during linkage
159-
list(APPEND ASSEMBLED_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj)
177+
list(APPEND ASSEMBLED_OBJECTS ${OBJ_FILE})
160178
endforeach()
161179

162180
set(${COMPILE_ASM_OUTPUT_OBJECTS} ${ASSEMBLED_OBJECTS} PARENT_SCOPE)

src/coreclr/src/binder/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ convert_to_absolute_path(BINDER_SOURCES ${BINDER_SOURCES})
8383
convert_to_absolute_path(BINDER_CROSSGEN_SOURCES ${BINDER_CROSSGEN_SOURCES})
8484

8585
add_library_clr(v3binder
86-
STATIC
86+
OBJECT
8787
${BINDER_SOURCES}
8888
)
8989
add_dependencies(v3binder eventing_headers)

src/coreclr/src/classlibnative/bcltype/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(BCLTYPE_SOURCES
1111
)
1212

1313
add_library_clr(bcltype
14-
STATIC
14+
OBJECT
1515
${BCLTYPE_SOURCES}
1616
)
1717

src/coreclr/src/classlibnative/float/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(FLOAT_SOURCES
88
)
99

1010
add_library_clr(comfloat_wks
11-
STATIC
11+
OBJECT
1212
${FLOAT_SOURCES}
1313
)
1414

src/coreclr/src/debug/debug-pal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ if(CLR_CMAKE_HOST_UNIX)
3434

3535
endif(CLR_CMAKE_HOST_UNIX)
3636

37-
_add_library(debug-pal STATIC ${TWO_WAY_PIPE_SOURCES})
37+
_add_library(debug-pal OBJECT ${TWO_WAY_PIPE_SOURCES})

src/coreclr/src/debug/di/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if(CLR_CMAKE_HOST_WIN32)
5959

6060
if ((CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64) AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
6161
convert_to_absolute_path(CORDBDI_SOURCES_ASM_FILE ${CORDBDI_SOURCES_ASM_FILE})
62-
preprocess_compile_asm(ASM_FILES ${CORDBDI_SOURCES_ASM_FILE} OUTPUT_OBJECTS CORDBDI_SOURCES_ASM_FILE)
62+
preprocess_compile_asm(TARGET cordbdi ASM_FILES ${CORDBDI_SOURCES_ASM_FILE} OUTPUT_OBJECTS CORDBDI_SOURCES_ASM_FILE)
6363
endif()
6464
elseif(CLR_CMAKE_HOST_UNIX)
6565

src/coreclr/src/debug/ee/wks/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ if (CLR_CMAKE_TARGET_WIN32)
99

1010
if(CLR_CMAKE_HOST_ARCH_ARM OR CLR_CMAKE_HOST_ARCH_ARM64)
1111

12-
preprocess_compile_asm(ASM_FILES ${ASM_FILE} OUTPUT_OBJECTS ASM_OBJECTS)
12+
preprocess_compile_asm(TARGET cordbee_wks ASM_FILES ${ASM_FILE} OUTPUT_OBJECTS ASM_OBJECTS)
1313

14-
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ${ASM_OBJECTS})
14+
add_library_clr(cordbee_wks OBJECT ${CORDBEE_SOURCES_WKS} ${ASM_FILE} ${ASM_OBJECTS})
1515

1616
else ()
1717

@@ -23,14 +23,14 @@ if (CLR_CMAKE_TARGET_WIN32)
2323

2424
set_source_files_properties(${ASM_FILE} PROPERTIES COMPILE_OPTIONS "${ASM_OPTIONS}")
2525

26-
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ${ASM_FILE})
26+
add_library_clr(cordbee_wks OBJECT ${CORDBEE_SOURCES_WKS} ${ASM_FILE})
2727

2828
endif()
2929

3030
else ()
3131

3232
if(CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CMAKE_HOST_ARCH_ARM OR CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_I386)
33-
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S)
33+
add_library_clr(cordbee_wks OBJECT ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S)
3434
else()
3535
message(FATAL_ERROR "Unknown platform")
3636
endif()

src/coreclr/src/debug/ildbsymlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ set( ILDBSYMLIB_SOURCES
1010
symwrite.cpp
1111
)
1212

13-
add_library_clr(ildbsymlib ${ILDBSYMLIB_SOURCES})
13+
add_library_clr(ildbsymlib OBJECT ${ILDBSYMLIB_SOURCES})
1414

src/coreclr/src/dlls/mscordac/mscordac_unixexports.src

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ nativeStringResourceTable_mscorrc
3434
#PAL_GetPALDirectoryW
3535
#PAL_get_stdout
3636
#PAL_get_stderr
37+
#PAL_GetApplicationGroupId
38+
#PAL_GetTransportName
3739
#PAL_GetCurrentThread
3840
#PAL_GetCpuLimit
3941
#PAL_GetNativeExceptionHolderHead

src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ if (CLR_CMAKE_TARGET_WIN32)
55
endif (CLR_CMAKE_TARGET_WIN32)
66

77
if (CLR_CMAKE_HOST_WIN32)
8-
preprocess_file(${DEF_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def)
8+
set (DEF_FILE ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def)
9+
preprocess_file(${DEF_SOURCES} ${DEF_FILE})
910

1011
list(APPEND CLR_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def)
1112

@@ -65,8 +66,18 @@ add_library_clr(coreclr
6566
${CLR_SOURCES}
6667
)
6768

69+
add_library_clr(coreclr_static
70+
STATIC
71+
${CLR_SOURCES}
72+
)
73+
6874
add_custom_target(coreclr_exports DEPENDS ${EXPORTS_FILE})
75+
add_custom_target(coreclr_def DEPENDS ${DEF_FILE})
76+
77+
add_dependencies(coreclr coreclr_def)
6978
add_dependencies(coreclr coreclr_exports)
79+
add_dependencies(coreclr_static coreclr_def)
80+
add_dependencies(coreclr_static coreclr_exports)
7081

7182
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION})
7283
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})
@@ -75,10 +86,6 @@ if (CLR_CMAKE_HOST_UNIX)
7586
set(LIB_UNWINDER unwinder_wks)
7687
endif (CLR_CMAKE_HOST_UNIX)
7788

78-
if(FEATURE_MERGE_JIT_AND_ENGINE)
79-
set(CLRJIT_STATIC clrjit_static)
80-
endif(FEATURE_MERGE_JIT_AND_ENGINE)
81-
8289
# IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is
8390
# order dependent and changing the order can result in undefined symbols in the shared
8491
# library.
@@ -88,7 +95,6 @@ set(CORECLR_LIBRARIES
8895
cordbee_wks
8996
debug-pal
9097
${LIB_UNWINDER}
91-
cee_wks
9298
v3binder
9399
${END_LIBRARY_GROUP} # End group of libraries that have circular references
94100
mdcompiler_wks
@@ -97,7 +103,6 @@ set(CORECLR_LIBRARIES
97103
mdhotdata_full
98104
bcltype
99105
ceefgen
100-
${CLRJIT_STATIC}
101106
comfloat_wks
102107
corguids
103108
gcinfo
@@ -159,7 +164,12 @@ if(FEATURE_EVENT_TRACE)
159164
endif(CLR_CMAKE_HOST_UNIX)
160165
endif(FEATURE_EVENT_TRACE)
161166

162-
target_link_libraries(coreclr ${CORECLR_LIBRARIES})
167+
if(FEATURE_MERGE_JIT_AND_ENGINE)
168+
set(CLRJIT_STATIC clrjit_static)
169+
endif(FEATURE_MERGE_JIT_AND_ENGINE)
170+
171+
target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks cee_wks_core)
172+
target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static cee_wks_mergeable cee_wks_core)
163173

164174
# Create the runtime module index header file containing the coreclr build id
165175
# for xplat and the timestamp/size on Windows.
@@ -218,5 +228,8 @@ endif(CLR_CMAKE_TARGET_WIN32)
218228
# add the install targets
219229
install_clr(TARGETS coreclr ADDITIONAL_DESTINATION sharedFramework)
220230

231+
# publish coreclr_static lib
232+
_install(TARGETS coreclr_static DESTINATION lib)
233+
221234
# Enable profile guided optimization
222235
add_pgo(coreclr)

src/coreclr/src/dlls/mscoree/unixinterface.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
// Holder for const wide strings
2626
typedef NewArrayHolder<const WCHAR> ConstWStringHolder;
2727

28+
// Specifies whether coreclr is embedded or standalone
29+
extern bool g_coreclr_embedded;
30+
2831
// Holder for array of wide strings
2932
class ConstWStringArrayHolder : public NewArrayHolder<LPCWSTR>
3033
{
@@ -171,8 +174,21 @@ int coreclr_initialize(
171174
unsigned int* domainId)
172175
{
173176
HRESULT hr;
177+
178+
LPCWSTR* propertyKeysW;
179+
LPCWSTR* propertyValuesW;
180+
BundleProbe* bundleProbe = nullptr;
181+
182+
ConvertConfigPropertiesToUnicode(
183+
propertyKeys,
184+
propertyValues,
185+
propertyCount,
186+
&propertyKeysW,
187+
&propertyValuesW,
188+
&bundleProbe);
189+
174190
#ifdef TARGET_UNIX
175-
DWORD error = PAL_InitializeCoreCLR(exePath);
191+
DWORD error = PAL_InitializeCoreCLR(exePath, g_coreclr_embedded);
176192
hr = HRESULT_FROM_WIN32(error);
177193

178194
// If PAL initialization failed, then we should return right away and avoid
@@ -190,18 +206,6 @@ int coreclr_initialize(
190206

191207
ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName);
192208

193-
LPCWSTR* propertyKeysW;
194-
LPCWSTR* propertyValuesW;
195-
BundleProbe* bundleProbe = nullptr;
196-
197-
ConvertConfigPropertiesToUnicode(
198-
propertyKeys,
199-
propertyValues,
200-
propertyCount,
201-
&propertyKeysW,
202-
&propertyValuesW,
203-
&bundleProbe);
204-
205209
if (bundleProbe != nullptr)
206210
{
207211
static Bundle bundle(StringToUnicode(exePath), bundleProbe);

src/coreclr/src/dlls/mscorrc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if(CLR_CMAKE_HOST_WIN32)
1919
else()
2020
build_resources(${CMAKE_CURRENT_SOURCE_DIR}/include.rc mscorrc TARGET_CPP_FILE)
2121

22-
add_library_clr(mscorrc STATIC
22+
add_library_clr(mscorrc OBJECT
2323
${TARGET_CPP_FILE}
2424
)
2525
endif(CLR_CMAKE_HOST_WIN32)

src/coreclr/src/gcinfo/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ endif(CLR_CMAKE_TARGET_ARCH_I386)
1717
convert_to_absolute_path(GCINFO_SOURCES ${GCINFO_SOURCES})
1818

1919
add_library_clr(gcinfo
20-
STATIC
20+
OBJECT
2121
${GCINFO_SOURCES}
2222
)
2323

src/coreclr/src/inc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if(FEATURE_JIT_PITCHING)
5858
endif(FEATURE_JIT_PITCHING)
5959

6060
# Compile *_i.cpp to lib
61-
_add_library(corguids ${CORGUIDS_SOURCES})
61+
_add_library(corguids OBJECT ${CORGUIDS_SOURCES})
6262

6363
# Binplace the inc files for packaging later.
6464

src/coreclr/src/interop/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ endif(WIN32)
3131
convert_to_absolute_path(INTEROP_SOURCES ${INTEROP_SOURCES})
3232

3333
add_library_clr(interop
34-
STATIC
34+
OBJECT
3535
${INTEROP_SOURCES}
3636
)

0 commit comments

Comments
 (0)