Skip to content

Commit de32c44

Browse files
author
Nathan Ricci
authored
[MONO] Move marshal-ilgen into a component (#71203)
* Move marshal-ilgen into a component.
1 parent fa75057 commit de32c44

27 files changed

Lines changed: 3366 additions & 3047 deletions

‎src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@
206206
<PlatformManifestFileEntryInclude="libmono-component-debugger-stub-static.a"IsNative="true" />
207207
<PlatformManifestFileEntryInclude="libmono-component-debugger-static.lib"IsNative="true" />
208208
<PlatformManifestFileEntryInclude="libmono-component-debugger-stub-static.lib"IsNative="true" />
209+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen.dll"IsNative="true" />
210+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen.so"IsNative="true" />
211+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen.dylib"IsNative="true" />
212+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen-static.a"IsNative="true" />
213+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen-stub-static.a"IsNative="true" />
214+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen-static.lib"IsNative="true" />
215+
<PlatformManifestFileEntryInclude="libmono-component-marshal-ilgen-stub-static.lib"IsNative="true" />
209216
<!-- Mono WASM-specific files -->
210217
<PlatformManifestFileEntryInclude="libmono-ee-interp.a"IsNative="true" />
211218
<PlatformManifestFileEntryInclude="libmono-icall-table.a"IsNative="true" />

‎src/libraries/System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
77
</PropertyGroup>
88
<PropertyGroup>
9-
<RuntimeComponentsCondition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing</RuntimeComponents>
9+
<RuntimeComponentsCondition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing;marshal-ilgen</RuntimeComponents>
1010
</PropertyGroup>
1111
<!-- Windows only files -->
1212
<ItemGroupCondition="'$(TargetPlatformIdentifier)' == 'windows'">

‎src/mono/mono.proj‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@
733733
<MonoAOTCMakeArgsInclude="-DENABLE_ICALL_SYMBOL_MAP=1" />
734734
<MonoAOTCMakeArgsInclude="-DDISABLE_SHARED_LIBS=1" />
735735
<MonoAOTCMakeArgsInclude="-DDISABLE_LIBS=1" />
736-
<MonoAOTCMakeArgsInclude="-DDISABLE_COMPONENTS=1" />
736+
<!-- Link in only the components neeeded for AOT compilation -->
737+
<MonoAOTCMakeArgsInclude="-DAOT_COMPONENTS=1 -DSTATIC_COMPONENTS=1;" />
737738
<MonoAOTCMakeArgsCondition="'$(MonoAotOffsetsFile)' != ''"Include="-DAOT_OFFSETS_FILE=&quot;$(MonoAotOffsetsFile)&quot;" />
738739
<MonoAOTCMakeArgsCondition="'$(MonoAOTEnableLLVM)' == 'true'"Include="-DLLVM_PREFIX=$(MonoAOTLLVMDir.TrimEnd('\/'))" />
739740
<MonoAOTCMakeArgsInclude="$(_MonoAOTCFLAGSOption)" />

‎src/mono/mono/component/CMakeLists.txt‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ set(MONO_EVENTPIPE_GEN_INCLUDE_PATH "${CMAKE_CURRENT_BINARY_DIR}/eventpipe")
66
set(MONO_HOT_RELOAD_COMPONENT_NAME "hot_reload")
77
set(MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME "diagnostics_tracing")
88
set(MONO_DEBUGGER_COMPONENT_NAME "debugger")
9+
set(MONO_MARSHAL_ILGEN_COMPONENT_NAME "marshal-ilgen")
910

1011
# a list of every component.
1112
set(components "")
13+
# a list of components needed by the AOT compiler
14+
set(components_for_aot "")
1215

1316
# the sources for each individiable component define a new
1417
# component_name-sources list for each component, and a
@@ -78,17 +81,53 @@ set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-dependencies
7881
${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-gen-sources
7982
)
8083

84+
# marshal-ilgen
85+
list(APPEND components
86+
${MONO_MARSHAL_ILGEN_COMPONENT_NAME}
87+
)
88+
list(APPEND components_for_aot
89+
${MONO_MARSHAL_ILGEN_COMPONENT_NAME}
90+
)
91+
92+
set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-sources
93+
${MONO_COMPONENT_PATH}/marshal-ilgen.c
94+
${MONO_COMPONENT_PATH}/marshal-ilgen.h
95+
${MONO_COMPONENT_PATH}/marshal-ilgen-noilgen.c
96+
${MONO_COMPONENT_PATH}/marshal-ilgen-noilgen.h
97+
)
98+
99+
# For every component not build into the AOT compiler, build the stub instead
100+
set(stubs_for_aot "")
101+
foreach (component INLISTS components)
102+
if (NOT (component IN_LIST components_for_aot))
103+
list(APPEND stubs_for_aot "${component}")
104+
endif()
105+
endforeach()
106+
107+
108+
set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-stub-sources
109+
${MONO_COMPONENT_PATH}/marshal-ilgen-stub.c
110+
)
111+
112+
if (AOT_COMPONENTS)
113+
set(components_to_build ${components_for_aot})
114+
set(stubs_to_build ${stubs_for_aot})
115+
else()
116+
set(components_to_build ${components})
117+
set(stubs_to_build ${components})
118+
endif()
119+
81120
# from here down, all the components are treated in the same way
82121

83122
#define a library for each component and component stub
84123
function(define_component_libs)
85124
# NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets
86-
if (NOT DISABLE_LIBS)
87-
foreach(component INLISTScomponents)
125+
if (AOT_COMPONENTS ORNOT DISABLE_LIBS)
126+
foreach(component INLISTScomponents_to_build)
88127
add_library("mono-component-${component}-static"STATIC $<TARGET_OBJECTS:${component}-objects>)
89128
install(TARGETS"mono-component-${component}-static"LIBRARY)
90129
endforeach()
91-
foreach(component INLISTScomponents)
130+
foreach(component INLISTSstubs_to_build)
92131
add_library("mono-component-${component}-stub-static"STATIC $<TARGET_OBJECTS:${component}-stub-objects>)
93132
install(TARGETS"mono-component-${component}-stub-static"LIBRARY)
94133
endforeach()
@@ -102,7 +141,7 @@ target_sources(component_base INTERFACE
102141
)
103142
target_link_libraries(component_baseINTERFACEmonoapi)
104143

105-
if(DISABLE_COMPONENTS OR DISABLE_LIBS)
144+
if(NOT AOT_COMPONENTS AND (DISABLE_COMPONENTS OR DISABLE_LIBS))
106145
set(DISABLE_COMPONENT_OBJECTS 1)
107146
endif()
108147

@@ -122,7 +161,7 @@ endforeach()
122161

123162
if(NOT DISABLE_COMPONENTS ANDNOT STATIC_COMPONENTS)
124163
# define a shared library for each component
125-
foreach(component INLISTScomponents)
164+
foreach(component INLISTScomponents_to_build)
126165
# NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets
127166
if(HOST_WIN32)
128167
add_library("mono-component-${component}"SHARED"${${component}-sources}")
@@ -154,14 +193,14 @@ if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
154193
#define a library for each component and component stub
155194
define_component_libs()
156195

157-
elseif(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS)
196+
elseif(AOT_COMPONENTS OR (NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS))
158197

159198
#define a library for each component and component stub
160199
define_component_libs()
161200

162201
# define a list of mono-components objects for mini if building a shared libmono with static-linked components
163202
set(mono-components-objects "")
164-
foreach(component INLISTScomponents)
203+
foreach(component INLISTScomponents_to_build)
165204
list(APPEND mono-components-objects $<TARGET_OBJECTS:${component}-objects>)
166205
endforeach()
167206

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#include"mono/component/marshal-ilgen.h"
2+
#include"mono/component/marshal-ilgen-noilgen.h"
3+
4+
#ifndefENABLE_ILGEN
5+
staticint
6+
emit_marshal_array_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
7+
MonoMarshalSpec*spec,
8+
intconv_arg, MonoType**conv_arg_type,
9+
MarshalActionaction)
10+
{
11+
MonoType*int_type=mono_get_int_type ();
12+
MonoType*object_type=mono_get_object_type ();
13+
switch (action) {
14+
caseMARSHAL_ACTION_CONV_IN:
15+
*conv_arg_type=object_type;
16+
break;
17+
caseMARSHAL_ACTION_MANAGED_CONV_IN:
18+
*conv_arg_type=int_type;
19+
break;
20+
}
21+
returnconv_arg;
22+
}
23+
24+
staticint
25+
emit_marshal_ptr_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
26+
MonoMarshalSpec*spec, intconv_arg,
27+
MonoType**conv_arg_type, MarshalActionaction)
28+
{
29+
returnconv_arg;
30+
}
31+
#endif
32+
33+
#if !defined(ENABLE_ILGEN) || defined(DISABLE_NONBLITTABLE)
34+
staticint
35+
emit_marshal_vtype_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
36+
MonoMarshalSpec*spec,
37+
intconv_arg, MonoType**conv_arg_type,
38+
MarshalActionaction)
39+
{
40+
returnconv_arg;
41+
}
42+
43+
staticint
44+
emit_marshal_string_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
45+
MonoMarshalSpec*spec,
46+
intconv_arg, MonoType**conv_arg_type,
47+
MarshalActionaction)
48+
{
49+
MonoType*int_type=mono_get_int_type ();
50+
switch (action) {
51+
caseMARSHAL_ACTION_CONV_IN:
52+
*conv_arg_type=int_type;
53+
break;
54+
caseMARSHAL_ACTION_MANAGED_CONV_IN:
55+
*conv_arg_type=int_type;
56+
break;
57+
}
58+
returnconv_arg;
59+
}
60+
61+
staticint
62+
emit_marshal_safehandle_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
63+
MonoMarshalSpec*spec, intconv_arg,
64+
MonoType**conv_arg_type, MarshalActionaction)
65+
{
66+
MonoType*int_type=mono_get_int_type ();
67+
if (action==MARSHAL_ACTION_CONV_IN)
68+
*conv_arg_type=int_type;
69+
returnconv_arg;
70+
}
71+
72+
staticint
73+
emit_marshal_handleref_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
74+
MonoMarshalSpec*spec, intconv_arg,
75+
MonoType**conv_arg_type, MarshalActionaction)
76+
{
77+
MonoType*int_type=mono_get_int_type ();
78+
if (action==MARSHAL_ACTION_CONV_IN)
79+
*conv_arg_type=int_type;
80+
returnconv_arg;
81+
}
82+
83+
staticint
84+
emit_marshal_object_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
85+
MonoMarshalSpec*spec,
86+
intconv_arg, MonoType**conv_arg_type,
87+
MarshalActionaction)
88+
{
89+
MonoType*int_type=mono_get_int_type ();
90+
if (action==MARSHAL_ACTION_CONV_IN)
91+
*conv_arg_type=int_type;
92+
returnconv_arg;
93+
}
94+
95+
staticint
96+
emit_marshal_variant_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
97+
MonoMarshalSpec*spec,
98+
intconv_arg, MonoType**conv_arg_type,
99+
MarshalActionaction)
100+
{
101+
g_assert_not_reached ();
102+
}
103+
104+
staticint
105+
emit_marshal_asany_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
106+
MonoMarshalSpec*spec,
107+
intconv_arg, MonoType**conv_arg_type,
108+
MarshalActionaction)
109+
{
110+
returnconv_arg;
111+
}
112+
113+
staticint
114+
emit_marshal_boolean_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
115+
MonoMarshalSpec*spec,
116+
intconv_arg, MonoType**conv_arg_type,
117+
MarshalActionaction)
118+
{
119+
MonoType*int_type=mono_get_int_type ();
120+
switch (action) {
121+
caseMARSHAL_ACTION_CONV_IN:
122+
if (m_type_is_byref (t))
123+
*conv_arg_type=int_type;
124+
else
125+
*conv_arg_type=mono_marshal_boolean_conv_in_get_local_type (spec, NULL);
126+
break;
127+
128+
caseMARSHAL_ACTION_MANAGED_CONV_IN: {
129+
MonoClass*conv_arg_class=mono_marshal_boolean_managed_conv_in_get_conv_arg_class (spec, NULL);
130+
if (m_type_is_byref (t))
131+
*conv_arg_type=m_class_get_this_arg (conv_arg_class);
132+
else
133+
*conv_arg_type=m_class_get_byval_arg (conv_arg_class);
134+
break;
135+
}
136+
137+
}
138+
returnconv_arg;
139+
}
140+
141+
staticint
142+
emit_marshal_char_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
143+
MonoMarshalSpec*spec, intconv_arg,
144+
MonoType**conv_arg_type, MarshalActionaction)
145+
{
146+
returnconv_arg;
147+
}
148+
149+
staticint
150+
emit_marshal_custom_noilgen (EmitMarshalContext*m, intargnum, MonoType*t,
151+
MonoMarshalSpec*spec,
152+
intconv_arg, MonoType**conv_arg_type,
153+
MarshalActionaction)
154+
{
155+
MonoType*int_type=mono_get_int_type ();
156+
if (action==MARSHAL_ACTION_CONV_IN&&t->type==MONO_TYPE_VALUETYPE)
157+
*conv_arg_type=int_type;
158+
returnconv_arg;
159+
}
160+
#endif
161+
162+
#ifndefENABLE_ILGEN
163+
164+
void
165+
mono_marshal_noilgen_init_heavyweight (void)
166+
{
167+
MonoMarshalILgenCallbacksilgen_cb;
168+
169+
ilgen_cb.version=MONO_MARSHAL_CALLBACKS_VERSION;
170+
ilgen_cb.emit_marshal_array=emit_marshal_array_noilgen;
171+
ilgen_cb.emit_marshal_vtype=emit_marshal_vtype_noilgen;
172+
ilgen_cb.emit_marshal_string=emit_marshal_string_noilgen;
173+
ilgen_cb.emit_marshal_safehandle=emit_marshal_safehandle_noilgen;
174+
ilgen_cb.emit_marshal_handleref=emit_marshal_handleref_noilgen;
175+
ilgen_cb.emit_marshal_object=emit_marshal_object_noilgen;
176+
ilgen_cb.emit_marshal_variant=emit_marshal_variant_noilgen;
177+
ilgen_cb.emit_marshal_asany=emit_marshal_asany_noilgen;
178+
ilgen_cb.emit_marshal_boolean=emit_marshal_boolean_noilgen;
179+
ilgen_cb.emit_marshal_custom=emit_marshal_custom_noilgen;
180+
ilgen_cb.emit_marshal_ptr=emit_marshal_ptr_noilgen;
181+
182+
ilgen_cb.emit_marshal_char=emit_marshal_char_noilgen;
183+
mono_install_marshal_callbacks_ilgen(&ilgen_cb);
184+
}
185+
186+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* \file
3+
* Copyright 2022 Microsoft
4+
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
5+
*/
6+
#ifndef__MARSHAL_ILGEN_NOILGEN_H__
7+
#define__MARSHAL_ILGEN_NOILGEN_H__
8+
9+
voidmono_marshal_noilgen_init_heavyweight (void);
10+
11+
#endif// __MARSHAL_ILGEN_NOILGEN_H__
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
#include<mono/component/component.h>
3+
#include<mono/component/marshal-ilgen.h>
4+
#include<mono/metadata/marshal.h>
5+
6+
staticbool
7+
marshal_ilgen_available (void)
8+
{
9+
return false;
10+
}
11+
12+
staticint
13+
stub_emit_marshal_ilgen (EmitMarshalContext*m, intargnum, MonoType*t,
14+
MonoMarshalSpec*spec, intconv_arg,
15+
MonoType**conv_arg_type, MarshalActionaction, MonoMarshalLightweightCallbacks*lightweigth_cb)
16+
{
17+
return0;
18+
}
19+
20+
staticvoid
21+
mono_component_marshal_ilgen_stub_init(void)
22+
{
23+
}
24+
25+
staticvoid
26+
stub_mono_marshal_ilgen_install_callbacks_mono (IlgenCallbacksToMono*callbacks)
27+
{
28+
}
29+
30+
staticMonoComponentMarshalILgencomponent_func_table= {
31+
{ MONO_COMPONENT_ITF_VERSION, &marshal_ilgen_available },
32+
mono_component_marshal_ilgen_stub_init,
33+
stub_emit_marshal_ilgen,
34+
stub_mono_marshal_ilgen_install_callbacks_mono
35+
};
36+
37+
MonoComponentMarshalILgen*
38+
mono_component_marshal_ilgen_init (void)
39+
{
40+
return&component_func_table;
41+
}

0 commit comments

Comments
 (0)