Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MONO] Move Marshal-ilgen into a component #75542

Merged
merged 17 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,16 @@
<PlatformManifestFileEntry Include="libmono-component-debugger-stub-static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-debugger-static.lib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-debugger-stub-static.lib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.dll" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.so" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-stub-static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-static.lib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-stub-static.lib" IsNative="true" />
<!-- Mono WASM-specific files -->
<PlatformManifestFileEntry Include="libmono-ee-interp.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-icall-table.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-ilgen.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-profiler-aot.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-profiler-browser.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-wasm-eh-js.a" IsNative="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
</PropertyGroup>
<PropertyGroup>
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing</RuntimeComponents>
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing;marshal-ilgen</RuntimeComponents>
</PropertyGroup>
<!-- Windows only files -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
Expand Down
6 changes: 3 additions & 3 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ set(CMAKE_CXX_FLAGS_CHECKED "")
set(CMAKE_EXE_LINKER_FLAGS_CHECKED "")
set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "")

# This is always enabled now, and we should go through the code to remove the case here it is not defined
set(ENABLE_ILGEN 1)
naricc marked this conversation as resolved.
Show resolved Hide resolved

if(NOT MONO_LIB_NAME)
set(MONO_LIB_NAME "monosgen-2.0")
endif()
Expand Down Expand Up @@ -75,9 +78,6 @@ set(DISABLE_COM 1)
if(ENABLE_INTERP_LIB)
set(DISABLE_INTERPRETER 1)
endif()
if(NOT DISABLE_INTERPRETER OR NOT DISABLE_JIT)
set(ENABLE_ILGEN 1)
endif()
if(NOT DISABLE_EVENTPIPE)
set(ENABLE_PERFTRACING 1)
endif()
Expand Down
7 changes: 3 additions & 4 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@
<MonoAOTCMakeArgs Include="-DENABLE_ICALL_SYMBOL_MAP=1" />
<MonoAOTCMakeArgs Include="-DDISABLE_SHARED_LIBS=1" />
<MonoAOTCMakeArgs Include="-DDISABLE_LIBS=1" />
<MonoAOTCMakeArgs Include="-DDISABLE_COMPONENTS=1" />
<!-- Link in only the components neeeded for AOT compilation -->
<MonoAOTCMakeArgs Include="-DAOT_COMPONENTS=1 -DSTATIC_COMPONENTS=1;" />
<MonoAOTCMakeArgs Condition="'$(MonoAotOffsetsFile)' != ''" Include="-DAOT_OFFSETS_FILE=&quot;$(MonoAotOffsetsFile)&quot;" />
<MonoAOTCMakeArgs Condition="'$(MonoAOTEnableLLVM)' == 'true'" Include="-DLLVM_PREFIX=$(MonoAOTLLVMDir.TrimEnd('\/'))" />
<MonoAOTCMakeArgs Include="$(_MonoAOTCFLAGSOption)" />
Expand Down Expand Up @@ -899,9 +900,7 @@
<_MonoRuntimeArtifacts Condition="'$(_MonoIncludeInterpStaticFiles)' == 'true'" Include="$(MonoObjDir)out\lib\libmono-icall-table.a">
<Destination>$(RuntimeBinDir)libmono-icall-table.a</Destination>
</_MonoRuntimeArtifacts>
<_MonoRuntimeArtifacts Condition="'$(_MonoIncludeInterpStaticFiles)' == 'true'" Include="$(MonoObjDir)out\lib\libmono-ilgen.a">
<Destination>$(RuntimeBinDir)libmono-ilgen.a</Destination>
</_MonoRuntimeArtifacts>

<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-aot.a">
<Destination>$(RuntimeBinDir)libmono-profiler-aot.a</Destination>
</_MonoRuntimeArtifacts>
Expand Down
53 changes: 46 additions & 7 deletions src/mono/mono/component/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ set(MONO_EVENTPIPE_GEN_INCLUDE_PATH "${CMAKE_CURRENT_BINARY_DIR}/eventpipe")
set(MONO_HOT_RELOAD_COMPONENT_NAME "hot_reload")
set(MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME "diagnostics_tracing")
set(MONO_DEBUGGER_COMPONENT_NAME "debugger")
set(MONO_MARSHAL_ILGEN_COMPONENT_NAME "marshal-ilgen")

# a list of every component.
set(components "")
# a list of components needed by the AOT compiler
set(components_for_aot "")

# the sources for each individiable component define a new
# component_name-sources list for each component, and a
Expand Down Expand Up @@ -79,17 +82,53 @@ set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-dependencies
${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-gen-sources
)

# marshal-ilgen
list(APPEND components
${MONO_MARSHAL_ILGEN_COMPONENT_NAME}
)
list(APPEND components_for_aot
${MONO_MARSHAL_ILGEN_COMPONENT_NAME}
)

set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-sources
${MONO_COMPONENT_PATH}/marshal-ilgen.c
${MONO_COMPONENT_PATH}/marshal-ilgen.h
${MONO_COMPONENT_PATH}/marshal-ilgen-noilgen.c
${MONO_COMPONENT_PATH}/marshal-ilgen-noilgen.h
naricc marked this conversation as resolved.
Show resolved Hide resolved
)

# For every component not build into the AOT compiler, build the stub instead
set(stubs_for_aot "")
foreach (component IN LISTS components)
if (NOT (component IN_LIST components_for_aot))
list(APPEND stubs_for_aot "${component}")
endif()
endforeach()


set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-stub-sources
${MONO_COMPONENT_PATH}/marshal-ilgen-stub.c
)

if (AOT_COMPONENTS)
set(components_to_build ${components_for_aot})
set(stubs_to_build ${stubs_for_aot})
else()
set(components_to_build ${components})
set(stubs_to_build ${components})
endif()

# from here down, all the components are treated in the same way

#define a library for each component and component stub
function(define_component_libs)
# NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets
if (NOT DISABLE_LIBS)
foreach(component IN LISTS components)
if (AOT_COMPONENTS OR NOT DISABLE_LIBS )
foreach(component IN LISTS components_to_build)
add_library("mono-component-${component}-static" STATIC $<TARGET_OBJECTS:${component}-objects>)
install(TARGETS "mono-component-${component}-static" LIBRARY)
endforeach()
foreach(component IN LISTS components)
foreach(component IN LISTS stubs_to_build)
add_library("mono-component-${component}-stub-static" STATIC $<TARGET_OBJECTS:${component}-stub-objects>)
install(TARGETS "mono-component-${component}-stub-static" LIBRARY)
endforeach()
Expand All @@ -103,7 +142,7 @@ target_sources(component_base INTERFACE
)
target_link_libraries(component_base INTERFACE monoapi)

if(DISABLE_COMPONENTS OR DISABLE_LIBS)
if(NOT AOT_COMPONENTS AND (DISABLE_COMPONENTS OR DISABLE_LIBS))
set(DISABLE_COMPONENT_OBJECTS 1)
endif()

Expand All @@ -123,7 +162,7 @@ endforeach()

if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
# define a shared library for each component
foreach(component IN LISTS components)
foreach(component IN LISTS components_to_build)
# NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets
if(HOST_WIN32)
add_library("mono-component-${component}" SHARED "${${component}-sources}")
Expand Down Expand Up @@ -155,14 +194,14 @@ if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
#define a library for each component and component stub
define_component_libs()

elseif(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS)
elseif(AOT_COMPONENTS OR (NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS))

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

# define a list of mono-components objects for mini if building a shared libmono with static-linked components
set(mono-components-objects "")
foreach(component IN LISTS components)
foreach(component IN LISTS components_to_build)
list(APPEND mono-components-objects $<TARGET_OBJECTS:${component}-objects>)
endforeach()

Expand Down
9 changes: 9 additions & 0 deletions src/mono/mono/component/marshal-ilgen-internals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __MARSHAL_ILGEN_INTERNALS_H__
#define __MARSHAL_ILGEN_INTERNALS_H__

#include "mono/component/marshal-ilgen.h"

void
mono_install_marshal_callbacks_ilgen (MonoMarshalILgenCallbacks *cb);

#endif // __MARSHAL_ILGEN_INTERNALS_H__
187 changes: 187 additions & 0 deletions src/mono/mono/component/marshal-ilgen-noilgen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#include "mono/component/marshal-ilgen.h"
#include "mono/component/marshal-ilgen-internals.h"
#include "mono/component/marshal-ilgen-noilgen.h"

#ifndef ENABLE_ILGEN
static int
emit_marshal_array_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
MonoType *object_type = mono_get_object_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
*conv_arg_type = object_type;
break;
case MARSHAL_ACTION_MANAGED_CONV_IN:
*conv_arg_type = int_type;
break;
}
return conv_arg;
}

static int
emit_marshal_ptr_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
return conv_arg;
}
#endif

#if !defined(ENABLE_ILGEN) || defined(DISABLE_NONBLITTABLE)
static int
emit_marshal_vtype_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
return conv_arg;
}

static int
emit_marshal_string_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
*conv_arg_type = int_type;
break;
case MARSHAL_ACTION_MANAGED_CONV_IN:
*conv_arg_type = int_type;
break;
}
return conv_arg;
}

static int
emit_marshal_safehandle_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}

static int
emit_marshal_handleref_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}

static int
emit_marshal_object_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}

static int
emit_marshal_variant_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
g_assert_not_reached ();
}

static int
emit_marshal_asany_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
return conv_arg;
}

static int
emit_marshal_boolean_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
if (m_type_is_byref (t))
*conv_arg_type = int_type;
else
*conv_arg_type = mono_marshal_boolean_conv_in_get_local_type (spec, NULL);
break;

case MARSHAL_ACTION_MANAGED_CONV_IN: {
MonoClass* conv_arg_class = mono_marshal_boolean_managed_conv_in_get_conv_arg_class (spec, NULL);
if (m_type_is_byref (t))
*conv_arg_type = m_class_get_this_arg (conv_arg_class);
else
*conv_arg_type = m_class_get_byval_arg (conv_arg_class);
break;
}

}
return conv_arg;
}

static int
emit_marshal_char_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
return conv_arg;
}

static int
emit_marshal_custom_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN && t->type == MONO_TYPE_VALUETYPE)
*conv_arg_type = int_type;
return conv_arg;
}
#endif

#ifndef ENABLE_ILGEN

void
mono_marshal_noilgen_init_heavyweight (void)
{
MonoMarshalILgenCallbacks ilgen_cb;

ilgen_cb.version = MONO_MARSHAL_CALLBACKS_VERSION;
ilgen_cb.emit_marshal_array = emit_marshal_array_noilgen;
ilgen_cb.emit_marshal_vtype = emit_marshal_vtype_noilgen;
ilgen_cb.emit_marshal_string = emit_marshal_string_noilgen;
ilgen_cb.emit_marshal_safehandle = emit_marshal_safehandle_noilgen;
ilgen_cb.emit_marshal_handleref = emit_marshal_handleref_noilgen;
ilgen_cb.emit_marshal_object = emit_marshal_object_noilgen;
ilgen_cb.emit_marshal_variant = emit_marshal_variant_noilgen;
ilgen_cb.emit_marshal_asany = emit_marshal_asany_noilgen;
ilgen_cb.emit_marshal_boolean = emit_marshal_boolean_noilgen;
ilgen_cb.emit_marshal_custom = emit_marshal_custom_noilgen;
ilgen_cb.emit_marshal_ptr = emit_marshal_ptr_noilgen;

ilgen_cb.emit_marshal_char = emit_marshal_char_noilgen;
mono_install_marshal_callbacks_ilgen(&ilgen_cb);
}

#endif
11 changes: 11 additions & 0 deletions src/mono/mono/component/marshal-ilgen-noilgen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* \file
* Copyright 2022 Microsoft
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#ifndef __MARSHAL_ILGEN_NOILGEN_H__
#define __MARSHAL_ILGEN_NOILGEN_H__

void mono_marshal_noilgen_init_heavyweight (void);

#endif // __MARSHAL_ILGEN_NOILGEN_H__
Loading