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

+3366
-3047
lines changed

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
<PlatformManifestFileEntry Include="libmono-component-debugger-stub-static.a" IsNative="true" />
207207
<PlatformManifestFileEntry Include="libmono-component-debugger-static.lib" IsNative="true" />
208208
<PlatformManifestFileEntry Include="libmono-component-debugger-stub-static.lib" IsNative="true" />
209+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.dll" IsNative="true" />
210+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.so" IsNative="true" />
211+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.dylib" IsNative="true" />
212+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-static.a" IsNative="true" />
213+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-stub-static.a" IsNative="true" />
214+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-static.lib" IsNative="true" />
215+
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-stub-static.lib" IsNative="true" />
209216
<!-- Mono WASM-specific files -->
210217
<PlatformManifestFileEntry Include="libmono-ee-interp.a" IsNative="true" />
211218
<PlatformManifestFileEntry Include="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-
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing</RuntimeComponents>
9+
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing;marshal-ilgen</RuntimeComponents>
1010
</PropertyGroup>
1111
<!-- Windows only files -->
1212
<ItemGroup Condition="'$(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
<MonoAOTCMakeArgs Include="-DENABLE_ICALL_SYMBOL_MAP=1" />
734734
<MonoAOTCMakeArgs Include="-DDISABLE_SHARED_LIBS=1" />
735735
<MonoAOTCMakeArgs Include="-DDISABLE_LIBS=1" />
736-
<MonoAOTCMakeArgs Include="-DDISABLE_COMPONENTS=1" />
736+
<!-- Link in only the components neeeded for AOT compilation -->
737+
<MonoAOTCMakeArgs Include="-DAOT_COMPONENTS=1 -DSTATIC_COMPONENTS=1;" />
737738
<MonoAOTCMakeArgs Condition="'$(MonoAotOffsetsFile)' != ''" Include="-DAOT_OFFSETS_FILE=&quot;$(MonoAotOffsetsFile)&quot;" />
738739
<MonoAOTCMakeArgs Condition="'$(MonoAOTEnableLLVM)' == 'true'" Include="-DLLVM_PREFIX=$(MonoAOTLLVMDir.TrimEnd('\/'))" />
739740
<MonoAOTCMakeArgs Include="$(_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 IN LISTS 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 IN LISTS components)
125+
if (AOT_COMPONENTS OR NOT DISABLE_LIBS )
126+
foreach(component IN LISTS components_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 IN LISTS components)
130+
foreach(component IN LISTS stubs_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_base INTERFACE monoapi)
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 AND NOT STATIC_COMPONENTS)
124163
# define a shared library for each component
125-
foreach(component IN LISTS components)
164+
foreach(component IN LISTS components_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 IN LISTS components)
203+
foreach(component IN LISTS components_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+
#ifndef ENABLE_ILGEN
5+
static int
6+
emit_marshal_array_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
7+
MonoMarshalSpec *spec,
8+
int conv_arg, MonoType **conv_arg_type,
9+
MarshalAction action)
10+
{
11+
MonoType *int_type = mono_get_int_type ();
12+
MonoType *object_type = mono_get_object_type ();
13+
switch (action) {
14+
case MARSHAL_ACTION_CONV_IN:
15+
*conv_arg_type = object_type;
16+
break;
17+
case MARSHAL_ACTION_MANAGED_CONV_IN:
18+
*conv_arg_type = int_type;
19+
break;
20+
}
21+
return conv_arg;
22+
}
23+
24+
static int
25+
emit_marshal_ptr_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
26+
MonoMarshalSpec *spec, int conv_arg,
27+
MonoType **conv_arg_type, MarshalAction action)
28+
{
29+
return conv_arg;
30+
}
31+
#endif
32+
33+
#if !defined(ENABLE_ILGEN) || defined(DISABLE_NONBLITTABLE)
34+
static int
35+
emit_marshal_vtype_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
36+
MonoMarshalSpec *spec,
37+
int conv_arg, MonoType **conv_arg_type,
38+
MarshalAction action)
39+
{
40+
return conv_arg;
41+
}
42+
43+
static int
44+
emit_marshal_string_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
45+
MonoMarshalSpec *spec,
46+
int conv_arg, MonoType **conv_arg_type,
47+
MarshalAction action)
48+
{
49+
MonoType *int_type = mono_get_int_type ();
50+
switch (action) {
51+
case MARSHAL_ACTION_CONV_IN:
52+
*conv_arg_type = int_type;
53+
break;
54+
case MARSHAL_ACTION_MANAGED_CONV_IN:
55+
*conv_arg_type = int_type;
56+
break;
57+
}
58+
return conv_arg;
59+
}
60+
61+
static int
62+
emit_marshal_safehandle_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
63+
MonoMarshalSpec *spec, int conv_arg,
64+
MonoType **conv_arg_type, MarshalAction action)
65+
{
66+
MonoType *int_type = mono_get_int_type ();
67+
if (action == MARSHAL_ACTION_CONV_IN)
68+
*conv_arg_type = int_type;
69+
return conv_arg;
70+
}
71+
72+
static int
73+
emit_marshal_handleref_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
74+
MonoMarshalSpec *spec, int conv_arg,
75+
MonoType **conv_arg_type, MarshalAction action)
76+
{
77+
MonoType *int_type = mono_get_int_type ();
78+
if (action == MARSHAL_ACTION_CONV_IN)
79+
*conv_arg_type = int_type;
80+
return conv_arg;
81+
}
82+
83+
static int
84+
emit_marshal_object_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
85+
MonoMarshalSpec *spec,
86+
int conv_arg, MonoType **conv_arg_type,
87+
MarshalAction action)
88+
{
89+
MonoType *int_type = mono_get_int_type ();
90+
if (action == MARSHAL_ACTION_CONV_IN)
91+
*conv_arg_type = int_type;
92+
return conv_arg;
93+
}
94+
95+
static int
96+
emit_marshal_variant_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
97+
MonoMarshalSpec *spec,
98+
int conv_arg, MonoType **conv_arg_type,
99+
MarshalAction action)
100+
{
101+
g_assert_not_reached ();
102+
}
103+
104+
static int
105+
emit_marshal_asany_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
106+
MonoMarshalSpec *spec,
107+
int conv_arg, MonoType **conv_arg_type,
108+
MarshalAction action)
109+
{
110+
return conv_arg;
111+
}
112+
113+
static int
114+
emit_marshal_boolean_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
115+
MonoMarshalSpec *spec,
116+
int conv_arg, MonoType **conv_arg_type,
117+
MarshalAction action)
118+
{
119+
MonoType *int_type = mono_get_int_type ();
120+
switch (action) {
121+
case MARSHAL_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+
case MARSHAL_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+
return conv_arg;
139+
}
140+
141+
static int
142+
emit_marshal_char_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
143+
MonoMarshalSpec *spec, int conv_arg,
144+
MonoType **conv_arg_type, MarshalAction action)
145+
{
146+
return conv_arg;
147+
}
148+
149+
static int
150+
emit_marshal_custom_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
151+
MonoMarshalSpec *spec,
152+
int conv_arg, MonoType **conv_arg_type,
153+
MarshalAction action)
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+
return conv_arg;
159+
}
160+
#endif
161+
162+
#ifndef ENABLE_ILGEN
163+
164+
void
165+
mono_marshal_noilgen_init_heavyweight (void)
166+
{
167+
MonoMarshalILgenCallbacks ilgen_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+
void mono_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+
static bool
7+
marshal_ilgen_available (void)
8+
{
9+
return false;
10+
}
11+
12+
static int
13+
stub_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
14+
MonoMarshalSpec *spec, int conv_arg,
15+
MonoType **conv_arg_type, MarshalAction action, MonoMarshalLightweightCallbacks* lightweigth_cb)
16+
{
17+
return 0;
18+
}
19+
20+
static void
21+
mono_component_marshal_ilgen_stub_init(void)
22+
{
23+
}
24+
25+
static void
26+
stub_mono_marshal_ilgen_install_callbacks_mono (IlgenCallbacksToMono *callbacks)
27+
{
28+
}
29+
30+
static MonoComponentMarshalILgen component_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)