2 * aot-runtime.c: mono Ahead of Time compiler
5 * Dietmar Maurer (dietmar@ximian.com)
6 * Zoltan Varga (vargaz@gmail.com)
8 * (C) 2002 Ximian, Inc.
12 #include <sys/types.h>
18 #ifdef HAVE_SYS_MMAN_H
27 #ifdef HAVE_EXECINFO_H
34 #ifdef HAVE_SYS_WAIT_H
35 #include <sys/wait.h> /* for WIFEXITED, WEXITSTATUS */
38 #include <mono/metadata/tabledefs.h>
39 #include <mono/metadata/class.h>
40 #include <mono/metadata/object.h>
41 #include <mono/metadata/tokentype.h>
42 #include <mono/metadata/appdomain.h>
43 #include <mono/metadata/debug-helpers.h>
44 #include <mono/metadata/assembly.h>
45 #include <mono/metadata/metadata-internals.h>
46 #include <mono/metadata/marshal.h>
47 #include <mono/metadata/gc-internal.h>
48 #include <mono/metadata/monitor.h>
49 #include <mono/metadata/threads-types.h>
50 #include <mono/utils/mono-logger.h>
51 #include <mono/utils/mono-mmap.h>
52 #include "mono/utils/mono-compiler.h"
53 #include <mono/utils/mono-counters.h>
61 #define SHARED_EXT ".dll"
62 #elif ((defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__)) || defined(__MACH__)) && !defined(__linux__)
63 #define SHARED_EXT ".dylib"
65 #define SHARED_EXT ".so"
68 #define ALIGN_PTR_TO(ptr,align) (gpointer)((((gssize)(ptr)) + (align - 1)) & (~(align - 1)))
69 #define ROUND_DOWN(VALUE,SIZE) ((VALUE) & ~((SIZE) - 1))
71 typedef struct MonoAotModule
{
73 /* Optimization flags used to compile the module */
75 /* Pointer to the Global Offset Table */
77 GHashTable
*name_cache
;
78 GHashTable
*extra_methods
;
79 /* Maps methods to their code */
80 GHashTable
*method_to_code
;
81 /* Maps pointers into the method info to the methods themselves */
82 GHashTable
*method_ref_to_method
;
83 MonoAssemblyName
*image_names
;
85 MonoAssembly
*assembly
;
86 MonoImage
**image_table
;
87 guint32 image_table_len
;
96 guint32
*code_offsets
;
98 guint32
*method_info_offsets
;
100 guint32
*got_info_offsets
;
102 guint32
*ex_info_offsets
;
103 guint32
*method_order
;
104 guint32
*method_order_end
;
106 guint32
*class_info_offsets
;
107 guint32
*methods_loaded
;
108 guint16
*class_name_table
;
109 guint32
*extra_method_table
;
110 guint32
*extra_method_info_offsets
;
111 guint8
*extra_method_info
;
114 /* Points to the trampolines */
115 guint8
*trampolines
[MONO_AOT_TRAMP_NUM
];
116 /* The first unused trampoline of each kind */
117 guint32 trampoline_index
[MONO_AOT_TRAMP_NUM
];
119 MonoAotFileInfo info
;
125 static GHashTable
*aot_modules
;
126 #define mono_aot_lock() EnterCriticalSection (&aot_mutex)
127 #define mono_aot_unlock() LeaveCriticalSection (&aot_mutex)
128 static CRITICAL_SECTION aot_mutex
;
131 * Maps assembly names to the mono_aot_module_<NAME>_info symbols in the
132 * AOT modules registered by mono_aot_register_module ().
134 static GHashTable
*static_aot_modules
;
137 * Maps MonoJitInfo* to the aot module they belong to, this can be different
138 * from ji->method->klass->image's aot module for generic instances.
140 static GHashTable
*ji_to_amodule
;
143 * Whenever to AOT compile loaded assemblies on demand and store them in
144 * a cache under $HOME/.mono/aot-cache.
146 static gboolean use_aot_cache
= FALSE
;
149 * Whenever to spawn a new process to AOT a file or do it in-process. Only relevant if
150 * use_aot_cache is TRUE.
152 static gboolean spawn_compiler
= TRUE
;
155 static gint32 mono_last_aot_method
= -1;
157 static gboolean make_unreadable
= FALSE
;
158 static guint32 name_table_accesses
= 0;
160 /* Used to speed-up find_aot_module () */
161 static gsize aot_code_low_addr
= (gssize
)-1;
162 static gsize aot_code_high_addr
= 0;
165 init_plt (MonoAotModule
*info
);
167 /*****************************************************/
169 /*****************************************************/
172 load_image (MonoAotModule
*module
, int index
)
174 MonoAssembly
*assembly
;
175 MonoImageOpenStatus status
;
177 g_assert (index
< module
->image_table_len
);
179 if (module
->image_table
[index
])
180 return module
->image_table
[index
];
181 if (module
->out_of_date
)
184 assembly
= mono_assembly_load (&module
->image_names
[index
], NULL
, &status
);
186 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT module %s is unusable because dependency %s is not found.\n", module
->aot_name
, module
->image_names
[index
].name
);
187 module
->out_of_date
= TRUE
;
191 if (strcmp (assembly
->image
->guid
, module
->image_guids
[index
])) {
192 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT module %s is out of date (Older than dependency %s).\n", module
->aot_name
, module
->image_names
[index
].name
);
193 module
->out_of_date
= TRUE
;
197 module
->image_table
[index
] = assembly
->image
;
198 return assembly
->image
;
203 decode_value (guint8
*ptr
, guint8
**rptr
)
208 if ((b
& 0x80) == 0){
211 } else if ((b
& 0x40) == 0){
212 len
= ((b
& 0x3f) << 8 | ptr
[1]);
214 } else if (b
!= 0xff) {
215 len
= ((b
& 0x1f) << 24) |
222 len
= (ptr
[1] << 24) | (ptr
[2] << 16) | (ptr
[3] << 8) | ptr
[4];
228 //printf ("DECODE: %d.\n", len);
233 decode_method_ref_2 (MonoAotModule
*module
, guint8
*buf
, guint8
**endbuf
);
236 decode_klass_ref (MonoAotModule
*module
, guint8
*buf
, guint8
**endbuf
);
238 static MonoGenericInst
*
239 decode_generic_inst (MonoAotModule
*module
, guint8
*buf
, guint8
**endbuf
)
242 MonoType
**type_argv
;
243 MonoGenericInst
*inst
;
246 type_argc
= decode_value (p
, &p
);
247 type_argv
= g_new0 (MonoType
*, type_argc
);
249 for (i
= 0; i
< type_argc
; ++i
) {
250 MonoClass
*pclass
= decode_klass_ref (module
, p
, &p
);
255 type_argv
[i
] = &pclass
->byval_arg
;
258 inst
= mono_metadata_get_generic_inst (type_argc
, type_argv
);
267 decode_generic_context (MonoAotModule
*module
, MonoGenericContext
*ctx
, guint8
*buf
, guint8
**endbuf
)
269 gboolean has_class_inst
, has_method_inst
;
272 has_class_inst
= decode_value (p
, &p
);
273 if (has_class_inst
) {
274 ctx
->class_inst
= decode_generic_inst (module
, p
, &p
);
275 if (!ctx
->class_inst
)
278 has_method_inst
= decode_value (p
, &p
);
279 if (has_method_inst
) {
280 ctx
->method_inst
= decode_generic_inst (module
, p
, &p
);
281 if (!ctx
->method_inst
)
290 decode_klass_ref (MonoAotModule
*module
, guint8
*buf
, guint8
**endbuf
)
293 MonoClass
*klass
, *eklass
;
297 token
= decode_value (p
, &p
);
302 if (mono_metadata_token_table (token
) == 0) {
303 image
= load_image (module
, decode_value (p
, &p
));
306 klass
= mono_class_get (image
, MONO_TOKEN_TYPE_DEF
+ token
);
307 } else if (mono_metadata_token_table (token
) == MONO_TABLE_TYPESPEC
) {
308 if (token
== MONO_TOKEN_TYPE_SPEC
) {
309 MonoTypeEnum type
= decode_value (p
, &p
);
311 if (type
== MONO_TYPE_GENERICINST
) {
313 MonoGenericContext ctx
;
316 gclass
= decode_klass_ref (module
, p
, &p
);
317 g_assert (gclass
->generic_container
);
319 memset (&ctx
, 0, sizeof (ctx
));
320 ctx
.class_inst
= decode_generic_inst (module
, p
, &p
);
323 type
= mono_class_inflate_generic_type (&gclass
->byval_arg
, &ctx
);
324 klass
= mono_class_from_mono_type (type
);
325 mono_metadata_free_type (type
);
326 } else if ((type
== MONO_TYPE_VAR
) || (type
== MONO_TYPE_MVAR
)) {
328 MonoGenericContainer
*container
;
330 int num
= decode_value (p
, &p
);
331 gboolean is_method
= decode_value (p
, &p
);
334 MonoMethod
*method_def
;
335 g_assert (type
== MONO_TYPE_MVAR
);
336 method_def
= decode_method_ref_2 (module
, p
, &p
);
340 container
= mono_method_get_generic_container (method_def
);
342 MonoClass
*class_def
;
343 g_assert (type
== MONO_TYPE_VAR
);
344 class_def
= decode_klass_ref (module
, p
, &p
);
348 container
= class_def
->generic_container
;
351 g_assert (container
);
353 // FIXME: Memory management
354 t
= g_new0 (MonoType
, 1);
356 t
->data
.generic_param
= mono_generic_container_get_param (container
, num
);
358 // FIXME: Maybe use types directly to avoid
359 // the overhead of creating MonoClass-es
360 klass
= mono_class_from_mono_type (t
);
364 g_assert_not_reached ();
367 image
= load_image (module
, decode_value (p
, &p
));
370 klass
= mono_class_get (image
, token
);
372 } else if (token
== MONO_TOKEN_TYPE_DEF
) {
374 image
= load_image (module
, decode_value (p
, &p
));
377 rank
= decode_value (p
, &p
);
378 eklass
= decode_klass_ref (module
, p
, &p
);
379 klass
= mono_array_class_get (eklass
, rank
);
381 g_assert_not_reached ();
384 mono_class_init (klass
);
390 static MonoClassField
*
391 decode_field_info (MonoAotModule
*module
, guint8
*buf
, guint8
**endbuf
)
393 MonoClass
*klass
= decode_klass_ref (module
, buf
, &buf
);
400 token
= MONO_TOKEN_FIELD_DEF
+ decode_value (p
, &p
);
404 return mono_class_get_field (klass
, token
);
408 * can_method_ref_match_method:
410 * Determine if calling decode_method_ref_2 on P could return the same method as
411 * METHOD. This is an optimization to avoid calling decode_method_ref_2 () which
412 * would create MonoMethods which are not needed etc.
415 can_method_ref_match_method (MonoAotModule
*module
, guint8
*buf
, MonoMethod
*method
)
418 guint32 image_index
, value
;
420 /* Keep this in sync with decode_method_ref () */
421 value
= decode_value (p
, &p
);
422 image_index
= value
>> 24;
424 if (image_index
== MONO_AOT_METHODREF_WRAPPER
) {
425 guint32 wrapper_type
;
427 if (!method
->wrapper_type
)
430 wrapper_type
= decode_value (p
, &p
);
432 if (method
->wrapper_type
!= wrapper_type
)
434 } else if (image_index
== MONO_AOT_METHODREF_WRAPPER_NAME
) {
436 } else if (image_index
< MONO_AOT_METHODREF_MIN
|| image_index
== MONO_AOT_METHODREF_METHODSPEC
|| image_index
== MONO_AOT_METHODREF_GINST
) {
437 if (method
->wrapper_type
)
447 * Decode a method reference, and return its image and token. This avoids loading
448 * metadata for the method if the caller does not need it. If the method has no token,
449 * then it is loaded from metadata and METHOD is set to the method instance.
452 decode_method_ref (MonoAotModule
*module
, guint32
*token
, MonoMethod
**method
, gboolean
*no_aot_trampoline
, guint8
*buf
, guint8
**endbuf
)
454 guint32 image_index
, value
;
455 MonoImage
*image
= NULL
;
460 if (no_aot_trampoline
)
461 *no_aot_trampoline
= FALSE
;
463 value
= decode_value (p
, &p
);
464 image_index
= value
>> 24;
466 if (image_index
== MONO_AOT_METHODREF_NO_AOT_TRAMPOLINE
) {
467 if (no_aot_trampoline
)
468 *no_aot_trampoline
= TRUE
;
469 value
= decode_value (p
, &p
);
470 image_index
= value
>> 24;
473 if (image_index
== MONO_AOT_METHODREF_WRAPPER
) {
474 guint32 wrapper_type
;
476 wrapper_type
= decode_value (p
, &p
);
479 image
= mono_defaults
.corlib
;
481 switch (wrapper_type
) {
482 case MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK
: {
483 MonoMethod
*m
= decode_method_ref_2 (module
, p
, &p
);
487 mono_class_init (m
->klass
);
488 *method
= mono_marshal_get_remoting_invoke_with_check (m
);
491 case MONO_WRAPPER_PROXY_ISINST
: {
492 MonoClass
*klass
= decode_klass_ref (module
, p
, &p
);
495 *method
= mono_marshal_get_proxy_cancast (klass
);
498 case MONO_WRAPPER_LDFLD
:
499 case MONO_WRAPPER_LDFLDA
:
500 case MONO_WRAPPER_STFLD
:
501 case MONO_WRAPPER_ISINST
: {
502 MonoClass
*klass
= decode_klass_ref (module
, p
, &p
);
505 if (wrapper_type
== MONO_WRAPPER_LDFLD
)
506 *method
= mono_marshal_get_ldfld_wrapper (&klass
->byval_arg
);
507 else if (wrapper_type
== MONO_WRAPPER_LDFLDA
)
508 *method
= mono_marshal_get_ldflda_wrapper (&klass
->byval_arg
);
509 else if (wrapper_type
== MONO_WRAPPER_STFLD
)
510 *method
= mono_marshal_get_stfld_wrapper (&klass
->byval_arg
);
511 else if (wrapper_type
== MONO_WRAPPER_ISINST
)
512 *method
= mono_marshal_get_isinst (klass
);
514 g_assert_not_reached ();
517 case MONO_WRAPPER_LDFLD_REMOTE
:
518 *method
= mono_marshal_get_ldfld_remote_wrapper (NULL
);
520 case MONO_WRAPPER_STFLD_REMOTE
:
521 *method
= mono_marshal_get_stfld_remote_wrapper (NULL
);
523 case MONO_WRAPPER_ALLOC
: {
524 int atype
= decode_value (p
, &p
);
526 *method
= mono_gc_get_managed_allocator_by_type (atype
);
529 case MONO_WRAPPER_STELEMREF
:
530 *method
= mono_marshal_get_stelemref ();
532 case MONO_WRAPPER_SYNCHRONIZED
: {
533 MonoMethod
*m
= decode_method_ref_2 (module
, p
, &p
);
537 *method
= mono_marshal_get_synchronized_wrapper (m
);
540 case MONO_WRAPPER_UNKNOWN
: {
541 MonoMethodDesc
*desc
;
542 MonoMethod
*orig_method
;
543 int subtype
= decode_value (p
, &p
);
545 if (subtype
== MONO_AOT_WRAPPER_MONO_ENTER
)
546 desc
= mono_method_desc_new ("Monitor:Enter", FALSE
);
547 else if (subtype
== MONO_AOT_WRAPPER_MONO_EXIT
)
548 desc
= mono_method_desc_new ("Monitor:Exit", FALSE
);
550 g_assert_not_reached ();
551 orig_method
= mono_method_desc_search_in_class (desc
, mono_defaults
.monitor_class
);
552 g_assert (orig_method
);
553 mono_method_desc_free (desc
);
554 *method
= mono_monitor_get_fast_path (orig_method
);
557 case MONO_WRAPPER_RUNTIME_INVOKE
: {
559 MonoMethod
*m
= decode_method_ref_2 (module
, p
, &p
);
563 *method
= mono_marshal_get_runtime_invoke (m
, FALSE
);
567 g_assert_not_reached ();
569 } else if (image_index
== MONO_AOT_METHODREF_WRAPPER_NAME
) {
570 /* Can't decode these */
571 g_assert_not_reached ();
572 } else if (image_index
== MONO_AOT_METHODREF_METHODSPEC
) {
573 image_index
= decode_value (p
, &p
);
574 *token
= decode_value (p
, &p
);
576 image
= load_image (module
, image_index
);
579 } else if (image_index
== MONO_AOT_METHODREF_GINST
) {
581 MonoGenericContext ctx
;
584 * These methods do not have a token which resolves them, so we
585 * resolve them immediately.
587 klass
= decode_klass_ref (module
, p
, &p
);
591 image_index
= decode_value (p
, &p
);
592 *token
= decode_value (p
, &p
);
594 image
= load_image (module
, image_index
);
598 *method
= mono_get_method_full (image
, *token
, NULL
, NULL
);
602 memset (&ctx
, 0, sizeof (ctx
));
604 if (FALSE
&& klass
->generic_class
) {
605 ctx
.class_inst
= klass
->generic_class
->context
.class_inst
;
606 ctx
.method_inst
= NULL
;
608 *method
= mono_class_inflate_generic_method_full (*method
, klass
, &ctx
);
611 memset (&ctx
, 0, sizeof (ctx
));
613 if (!decode_generic_context (module
, &ctx
, p
, &p
))
616 *method
= mono_class_inflate_generic_method_full (*method
, klass
, &ctx
);
617 } else if (image_index
== MONO_AOT_METHODREF_ARRAY
) {
621 klass
= decode_klass_ref (module
, p
, &p
);
624 method_type
= decode_value (p
, &p
);
626 switch (method_type
) {
628 *method
= mono_class_get_method_from_name (klass
, ".ctor", klass
->rank
);
631 *method
= mono_class_get_method_from_name (klass
, ".ctor", klass
->rank
* 2);
634 *method
= mono_class_get_method_from_name (klass
, "Get", -1);
637 *method
= mono_class_get_method_from_name (klass
, "Address", -1);
640 *method
= mono_class_get_method_from_name (klass
, "Set", -1);
643 g_assert_not_reached ();
646 g_assert (image_index
< MONO_AOT_METHODREF_MIN
);
647 *token
= MONO_TOKEN_METHOD_DEF
| (value
& 0xffffff);
649 image
= load_image (module
, image_index
);
660 * decode_method_ref_2:
662 * Similar to decode_method_ref, but resolve and return the method itself.
665 decode_method_ref_2 (MonoAotModule
*module
, guint8
*buf
, guint8
**endbuf
)
669 MonoImage
*image
= decode_method_ref (module
, &token
, &method
, NULL
, buf
, endbuf
);
675 method
= mono_get_method (image
, token
, NULL
);
681 make_writable (guint8
* addr
, guint32 len
)
687 g_error ("Attempt to make AOT memory writable while running in aot-only mode.\n");
689 page_start
= (guint8
*) (((gssize
) (addr
)) & ~ (mono_pagesize () - 1));
690 pages
= (addr
+ len
- page_start
+ mono_pagesize () - 1) / mono_pagesize ();
692 err
= mono_mprotect (page_start
, pages
* mono_pagesize (), MONO_MMAP_READ
| MONO_MMAP_WRITE
| MONO_MMAP_EXEC
);
697 create_cache_structure (void)
703 home
= g_get_home_dir ();
707 tmp
= g_build_filename (home
, ".mono", NULL
);
708 if (!g_file_test (tmp
, G_FILE_TEST_IS_DIR
)) {
709 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT creating directory %s", tmp
);
710 #ifdef PLATFORM_WIN32
713 err
= mkdir (tmp
, 0777);
716 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT failed: %s", g_strerror (errno
));
722 tmp
= g_build_filename (home
, ".mono", "aot-cache", NULL
);
723 if (!g_file_test (tmp
, G_FILE_TEST_IS_DIR
)) {
724 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT creating directory %s", tmp
);
725 #ifdef PLATFORM_WIN32
728 err
= mkdir (tmp
, 0777);
731 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT failed: %s", g_strerror (errno
));
740 * load_aot_module_from_cache:
742 * Experimental code to AOT compile loaded assemblies on demand.
745 * - Add environment variable MONO_AOT_CACHE_OPTIONS
746 * - Add options for controlling the cache size
747 * - Handle full cache by deleting old assemblies lru style
748 * - Add options for excluding assemblies during development
749 * - Maybe add a threshold after an assembly is AOT compiled
750 * - invoking a new mono process is a security risk
751 * - recompile the AOT module if one of its dependencies changes
754 load_aot_module_from_cache (MonoAssembly
*assembly
, char **aot_name
)
756 char *fname
, *cmd
, *tmp2
, *aot_options
;
765 if (assembly
->image
->dynamic
)
768 create_cache_structure ();
770 home
= g_get_home_dir ();
772 tmp2
= g_strdup_printf ("%s-%s%s", assembly
->image
->assembly_name
, assembly
->image
->guid
, SHARED_EXT
);
773 fname
= g_build_filename (home
, ".mono", "aot-cache", tmp2
, NULL
);
777 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT trying to load from cache: '%s'.", fname
);
778 module
= mono_dl_open (fname
, MONO_DL_LAZY
, NULL
);
781 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT not found.");
783 mono_trace (G_LOG_LEVEL_MESSAGE
, MONO_TRACE_AOT
, "AOT precompiling assembly '%s'... ", assembly
->image
->name
);
785 aot_options
= g_strdup_printf ("outfile=%s", fname
);
787 if (spawn_compiler
) {
788 /* FIXME: security */
789 /* FIXME: Has to pass the assembly loading path to the child process */
790 cmd
= g_strdup_printf ("mono -O=all --aot=%s %s", aot_options
, assembly
->image
->name
);
792 res
= g_spawn_command_line_sync (cmd
, &out
, &err
, &exit_status
, NULL
);
794 #if !defined(PLATFORM_WIN32) && !defined(__ppc__) && !defined(__ppc64__) && !defined(__powerpc__)
796 if (!WIFEXITED (exit_status
) && (WEXITSTATUS (exit_status
) == 0))
797 mono_trace (G_LOG_LEVEL_MESSAGE
, MONO_TRACE_AOT
, "AOT failed: %s.", err
);
799 mono_trace (G_LOG_LEVEL_MESSAGE
, MONO_TRACE_AOT
, "AOT succeeded.");
806 res
= mono_compile_assembly (assembly
, mono_parse_default_optimizations (NULL
), aot_options
);
808 mono_trace (G_LOG_LEVEL_MESSAGE
, MONO_TRACE_AOT
, "AOT failed.");
810 mono_trace (G_LOG_LEVEL_MESSAGE
, MONO_TRACE_AOT
, "AOT succeeded.");
814 module
= mono_dl_open (fname
, MONO_DL_LAZY
, NULL
);
816 g_free (aot_options
);
823 find_symbol (MonoDl
*module
, gpointer
*globals
, const char *name
, gpointer
*value
)
829 for (i
= 0; globals
[i
]; i
+= 2) {
830 if (strcmp (globals
[i
], name
) == 0) {
831 *value
= globals
[i
+ 1];
836 mono_dl_symbol (module
, name
, value
);
841 load_aot_module (MonoAssembly
*assembly
, gpointer user_data
)
844 MonoAotModule
*amodule
;
846 gboolean usable
= TRUE
;
847 char *saved_guid
= NULL
;
848 char *aot_version
= NULL
;
849 char *runtime_version
, *build_info
;
850 char *opt_flags
= NULL
;
852 gboolean full_aot
= FALSE
;
853 MonoAotFileInfo
*file_info
= NULL
;
857 if (mono_compile_aot
)
860 if (assembly
->image
->aot_module
)
862 * Already loaded. This can happen because the assembly loading code might invoke
863 * the assembly load hooks multiple times for the same assembly.
867 if (assembly
->image
->dynamic
)
870 if (mono_security_get_mode () == MONO_SECURITY_MODE_CAS
)
874 if (static_aot_modules
)
875 globals
= g_hash_table_lookup (static_aot_modules
, assembly
->aname
.name
);
881 /* Statically linked AOT module */
883 aot_name
= g_strdup_printf ("%s", assembly
->aname
.name
);
884 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "Found statically linked AOT module '%s'.\n", aot_name
);
887 sofile
= load_aot_module_from_cache (assembly
, &aot_name
);
890 aot_name
= g_strdup_printf ("%s%s", assembly
->image
->name
, SHARED_EXT
);
892 sofile
= mono_dl_open (aot_name
, MONO_DL_LAZY
, &err
);
895 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT failed to load AOT module %s: %s\n", aot_name
, err
);
901 if (!sofile
&& !globals
) {
903 fprintf (stderr
, "Failed to load AOT module '%s' in aot-only mode.\n", aot_name
);
910 find_symbol (sofile
, globals
, "mono_assembly_guid", (gpointer
*) &saved_guid
);
911 find_symbol (sofile
, globals
, "mono_aot_version", (gpointer
*) &aot_version
);
912 find_symbol (sofile
, globals
, "mono_aot_opt_flags", (gpointer
*)&opt_flags
);
913 find_symbol (sofile
, globals
, "mono_runtime_version", (gpointer
*)&runtime_version
);
914 find_symbol (sofile
, globals
, "mono_aot_got_addr", (gpointer
*)&got_addr
);
916 if (!aot_version
|| strcmp (aot_version
, MONO_AOT_FILE_VERSION
)) {
917 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT module %s has wrong file format version (expected %s got %s)\n", aot_name
, MONO_AOT_FILE_VERSION
, aot_version
);
921 if (!saved_guid
|| strcmp (assembly
->image
->guid
, saved_guid
)) {
922 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT module %s is out of date.\n", aot_name
);
927 build_info
= mono_get_runtime_build_info ();
928 if (!runtime_version
|| ((strlen (runtime_version
) > 0 && strcmp (runtime_version
, build_info
)))) {
929 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT module %s is compiled against runtime version '%s' while this runtime has version '%s'.\n", aot_name
, runtime_version
, build_info
);
937 find_symbol (sofile
, globals
, "mono_aot_full_aot", (gpointer
*)&full_aot_str
);
939 if (full_aot_str
&& !strcmp (full_aot_str
, "TRUE"))
943 if (mono_aot_only
&& !full_aot
) {
944 fprintf (stderr
, "Can't use AOT image '%s' in aot-only mode because it is not compiled with --aot=full.\n", aot_name
);
947 if (!mono_aot_only
&& full_aot
) {
948 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT module %s is compiled with --aot=full.\n", aot_name
);
954 fprintf (stderr
, "Failed to load AOT module '%s' while running in aot-only mode.\n", aot_name
);
959 mono_dl_close (sofile
);
960 assembly
->image
->aot_module
= NULL
;
964 find_symbol (sofile
, globals
, "mono_aot_file_info", (gpointer
*)&file_info
);
965 g_assert (file_info
);
967 amodule
= g_new0 (MonoAotModule
, 1);
968 amodule
->aot_name
= aot_name
;
969 amodule
->assembly
= assembly
;
971 memcpy (&amodule
->info
, file_info
, sizeof (*file_info
));
973 amodule
->got
= *got_addr
;
974 amodule
->got
[0] = assembly
->image
;
975 amodule
->globals
= globals
;
976 amodule
->sofile
= sofile
;
977 amodule
->method_to_code
= g_hash_table_new (mono_aligned_addr_hash
, NULL
);
979 sscanf (opt_flags
, "%d", &amodule
->opts
);
981 /* Read image table */
983 guint32 table_len
, i
;
986 find_symbol (sofile
, globals
, "mono_image_table", (gpointer
*)&table
);
989 table_len
= *(guint32
*)table
;
990 table
+= sizeof (guint32
);
991 amodule
->image_table
= g_new0 (MonoImage
*, table_len
);
992 amodule
->image_names
= g_new0 (MonoAssemblyName
, table_len
);
993 amodule
->image_guids
= g_new0 (char*, table_len
);
994 amodule
->image_table_len
= table_len
;
995 for (i
= 0; i
< table_len
; ++i
) {
996 MonoAssemblyName
*aname
= &(amodule
->image_names
[i
]);
998 aname
->name
= g_strdup (table
);
999 table
+= strlen (table
) + 1;
1000 amodule
->image_guids
[i
] = g_strdup (table
);
1001 table
+= strlen (table
) + 1;
1003 aname
->culture
= g_strdup (table
);
1004 table
+= strlen (table
) + 1;
1005 memcpy (aname
->public_key_token
, table
, strlen (table
) + 1);
1006 table
+= strlen (table
) + 1;
1008 table
= ALIGN_PTR_TO (table
, 8);
1009 aname
->flags
= *(guint32
*)table
;
1011 aname
->major
= *(guint32
*)table
;
1013 aname
->minor
= *(guint32
*)table
;
1015 aname
->build
= *(guint32
*)table
;
1017 aname
->revision
= *(guint32
*)table
;
1022 /* Read method and method_info tables */
1023 find_symbol (sofile
, globals
, "method_offsets", (gpointer
*)&amodule
->code_offsets
);
1024 find_symbol (sofile
, globals
, "methods", (gpointer
*)&amodule
->code
);
1025 find_symbol (sofile
, globals
, "methods_end", (gpointer
*)&amodule
->code_end
);
1026 find_symbol (sofile
, globals
, "method_info_offsets", (gpointer
*)&amodule
->method_info_offsets
);
1027 find_symbol (sofile
, globals
, "method_info", (gpointer
*)&amodule
->method_info
);
1028 find_symbol (sofile
, globals
, "ex_info_offsets", (gpointer
*)&amodule
->ex_info_offsets
);
1029 find_symbol (sofile
, globals
, "ex_info", (gpointer
*)&amodule
->ex_info
);
1030 find_symbol (sofile
, globals
, "method_order", (gpointer
*)&amodule
->method_order
);
1031 find_symbol (sofile
, globals
, "method_order_end", (gpointer
*)&amodule
->method_order_end
);
1032 find_symbol (sofile
, globals
, "class_info", (gpointer
*)&amodule
->class_info
);
1033 find_symbol (sofile
, globals
, "class_info_offsets", (gpointer
*)&amodule
->class_info_offsets
);
1034 find_symbol (sofile
, globals
, "class_name_table", (gpointer
*)&amodule
->class_name_table
);
1035 find_symbol (sofile
, globals
, "extra_method_table", (gpointer
*)&amodule
->extra_method_table
);
1036 find_symbol (sofile
, globals
, "extra_method_info", (gpointer
*)&amodule
->extra_method_info
);
1037 find_symbol (sofile
, globals
, "extra_method_info_offsets", (gpointer
*)&amodule
->extra_method_info_offsets
);
1038 find_symbol (sofile
, globals
, "got_info", (gpointer
*)&amodule
->got_info
);
1039 find_symbol (sofile
, globals
, "got_info_offsets", (gpointer
*)&amodule
->got_info_offsets
);
1040 find_symbol (sofile
, globals
, "specific_trampolines", (gpointer
*)&(amodule
->trampolines
[MONO_AOT_TRAMP_SPECIFIC
]));
1041 find_symbol (sofile
, globals
, "static_rgctx_trampolines", (gpointer
*)&(amodule
->trampolines
[MONO_AOT_TRAMP_STATIC_RGCTX
]));
1042 find_symbol (sofile
, globals
, "imt_thunks", (gpointer
*)&(amodule
->trampolines
[MONO_AOT_TRAMP_IMT_THUNK
]));
1043 find_symbol (sofile
, globals
, "unwind_info", (gpointer
)&amodule
->unwind_info
);
1044 find_symbol (sofile
, globals
, "mem_end", (gpointer
*)&amodule
->mem_end
);
1046 amodule
->mem_begin
= amodule
->code
;
1048 find_symbol (sofile
, globals
, "plt", (gpointer
*)&amodule
->plt
);
1049 find_symbol (sofile
, globals
, "plt_end", (gpointer
*)&amodule
->plt_end
);
1051 if (make_unreadable
) {
1052 #ifndef PLATFORM_WIN32
1055 int pages
, err
, len
;
1057 addr
= amodule
->mem_begin
;
1058 len
= amodule
->mem_end
- amodule
->mem_begin
;
1060 /* Round down in both directions to avoid modifying data which is not ours */
1061 page_start
= (guint8
*) (((gssize
) (addr
)) & ~ (mono_pagesize () - 1)) + mono_pagesize ();
1062 pages
= ((addr
+ len
- page_start
+ mono_pagesize () - 1) / mono_pagesize ()) - 1;
1063 err
= mono_mprotect (page_start
, pages
* mono_pagesize (), MONO_MMAP_NONE
);
1064 g_assert (err
== 0);
1070 aot_code_low_addr
= MIN (aot_code_low_addr
, (gsize
)amodule
->code
);
1071 aot_code_high_addr
= MAX (aot_code_high_addr
, (gsize
)amodule
->code_end
);
1073 g_hash_table_insert (aot_modules
, assembly
, amodule
);
1076 mono_jit_info_add_aot_module (assembly
->image
, amodule
->code
, amodule
->code_end
);
1078 assembly
->image
->aot_module
= amodule
;
1080 if (mono_aot_only
) {
1081 if (mono_defaults
.corlib
) {
1082 /* The second got slot contains the mscorlib got addr */
1083 MonoAotModule
*mscorlib_amodule
= mono_defaults
.corlib
->aot_module
;
1085 amodule
->got
[1] = mscorlib_amodule
->got
;
1087 amodule
->got
[1] = amodule
->got
;
1092 * Since we store methoddef and classdef tokens when referring to methods/classes in
1093 * referenced assemblies, we depend on the exact versions of the referenced assemblies.
1094 * MS calls this 'hard binding'. This means we have to load all referenced assemblies
1095 * non-lazily, since we can't handle out-of-date errors later.
1097 for (i
= 0; i
< amodule
->image_table_len
; ++i
)
1098 load_image (amodule
, i
);
1100 if (amodule
->out_of_date
) {
1101 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT Module %s is unusable because a dependency is out-of-date.\n", assembly
->image
->name
);
1102 if (mono_aot_only
) {
1103 fprintf (stderr
, "Failed to load AOT module '%s' while running in aot-only mode because a dependency cannot be found or it is out of date.\n", aot_name
);
1108 mono_trace (G_LOG_LEVEL_INFO
, MONO_TRACE_AOT
, "AOT loaded AOT Module for %s.\n", assembly
->image
->name
);
1112 * mono_aot_register_globals:
1114 * This is called by the ctor function in AOT images compiled with the
1115 * 'no-dlsym' option.
1118 mono_aot_register_globals (gpointer
*globals
)
1120 g_assert_not_reached ();
1124 * mono_aot_register_module:
1126 * This should be called by embedding code to register AOT modules statically linked
1127 * into the executable. AOT_INFO should be the value of the
1128 * 'mono_aot_module_<ASSEMBLY_NAME>_info' global symbol from the AOT module.
1131 mono_aot_register_module (gpointer
*aot_info
)
1139 /* Determine the assembly name */
1140 find_symbol (NULL
, globals
, "mono_aot_assembly_name", (gpointer
*)&aname
);
1143 /* This could be called before startup */
1147 if (!static_aot_modules
)
1148 static_aot_modules
= g_hash_table_new (g_str_hash
, g_str_equal
);
1150 g_hash_table_insert (static_aot_modules
, aname
, globals
);
1157 mono_aot_init (void)
1159 InitializeCriticalSection (&aot_mutex
);
1160 aot_modules
= g_hash_table_new (NULL
, NULL
);
1162 mono_install_assembly_load_hook (load_aot_module
, NULL
);
1164 if (g_getenv ("MONO_LASTAOT"))
1165 mono_last_aot_method
= atoi (g_getenv ("MONO_LASTAOT"));
1166 if (g_getenv ("MONO_AOT_CACHE"))
1167 use_aot_cache
= TRUE
;
1171 decode_cached_class_info (MonoAotModule
*module
, MonoCachedClassInfo
*info
, guint8
*buf
, guint8
**endbuf
)
1175 info
->vtable_size
= decode_value (buf
, &buf
);
1176 if (info
->vtable_size
== -1)
1179 flags
= decode_value (buf
, &buf
);
1180 info
->ghcimpl
= (flags
>> 0) & 0x1;
1181 info
->has_finalize
= (flags
>> 1) & 0x1;
1182 info
->has_cctor
= (flags
>> 2) & 0x1;
1183 info
->has_nested_classes
= (flags
>> 3) & 0x1;
1184 info
->blittable
= (flags
>> 4) & 0x1;
1185 info
->has_references
= (flags
>> 5) & 0x1;
1186 info
->has_static_refs
= (flags
>> 6) & 0x1;
1187 info
->no_special_static_fields
= (flags
>> 7) & 0x1;
1189 if (info
->has_cctor
) {
1190 MonoImage
*cctor_image
= decode_method_ref (module
, &info
->cctor_token
, NULL
, NULL
, buf
, &buf
);
1194 if (info
->has_finalize
) {
1195 info
->finalize_image
= decode_method_ref (module
, &info
->finalize_token
, NULL
, NULL
, buf
, &buf
);
1196 if (!info
->finalize_image
)
1200 info
->instance_size
= decode_value (buf
, &buf
);
1201 info
->class_size
= decode_value (buf
, &buf
);
1202 info
->packing_size
= decode_value (buf
, &buf
);
1203 info
->min_align
= decode_value (buf
, &buf
);
1211 mono_aot_get_method_from_vt_slot (MonoDomain
*domain
, MonoVTable
*vtable
, int slot
)
1214 MonoClass
*klass
= vtable
->klass
;
1215 MonoAotModule
*aot_module
= klass
->image
->aot_module
;
1217 MonoCachedClassInfo class_info
;
1221 gboolean no_aot_trampoline
;
1223 if (MONO_CLASS_IS_INTERFACE (klass
) || klass
->rank
|| !aot_module
)
1226 info
= &aot_module
->class_info
[aot_module
->class_info_offsets
[mono_metadata_token_index (klass
->type_token
) - 1]];
1229 err
= decode_cached_class_info (aot_module
, &class_info
, p
, &p
);
1233 for (i
= 0; i
< slot
; ++i
)
1234 decode_method_ref (aot_module
, &token
, NULL
, NULL
, p
, &p
);
1236 image
= decode_method_ref (aot_module
, &token
, NULL
, &no_aot_trampoline
, p
, &p
);
1239 if (no_aot_trampoline
)
1242 if (mono_metadata_token_index (token
) == 0)
1245 return mono_aot_get_method_from_token (domain
, image
, token
);
1249 mono_aot_get_cached_class_info (MonoClass
*klass
, MonoCachedClassInfo
*res
)
1251 MonoAotModule
*aot_module
= klass
->image
->aot_module
;
1255 if (klass
->rank
|| !aot_module
)
1258 p
= (guint8
*)&aot_module
->class_info
[aot_module
->class_info_offsets
[mono_metadata_token_index (klass
->type_token
) - 1]];
1260 err
= decode_cached_class_info (aot_module
, res
, p
, &p
);
1268 * mono_aot_get_class_from_name:
1270 * Obtains a MonoClass with a given namespace and a given name which is located in IMAGE,
1271 * using a cache stored in the AOT file.
1272 * Stores the resulting class in *KLASS if found, stores NULL otherwise.
1274 * Returns: TRUE if the klass was found/not found in the cache, FALSE if no aot file was
1278 mono_aot_get_class_from_name (MonoImage
*image
, const char *name_space
, const char *name
, MonoClass
**klass
)
1280 MonoAotModule
*aot_module
= image
->aot_module
;
1281 guint16
*table
, *entry
;
1284 char full_name_buf
[1024];
1286 const char *name2
, *name_space2
;
1288 guint32 cols
[MONO_TYPEDEF_SIZE
];
1289 GHashTable
*nspace_table
;
1291 if (!aot_module
|| !aot_module
->class_name_table
)
1298 /* First look in the cache */
1299 if (!aot_module
->name_cache
)
1300 aot_module
->name_cache
= g_hash_table_new (g_str_hash
, g_str_equal
);
1301 nspace_table
= g_hash_table_lookup (aot_module
->name_cache
, name_space
);
1303 *klass
= g_hash_table_lookup (nspace_table
, name
);
1310 table_size
= aot_module
->class_name_table
[0];
1311 table
= aot_module
->class_name_table
+ 1;
1313 if (name_space
[0] == '\0')
1314 full_name
= g_strdup_printf ("%s", name
);
1316 if (strlen (name_space
) + strlen (name
) < 1000) {
1317 sprintf (full_name_buf
, "%s.%s", name_space
, name
);
1318 full_name
= full_name_buf
;
1320 full_name
= g_strdup_printf ("%s.%s", name_space
, name
);
1323 hash
= mono_aot_str_hash (full_name
) % table_size
;
1324 if (full_name
!= full_name_buf
)
1327 entry
= &table
[hash
* 2];
1329 if (entry
[0] != 0) {
1330 t
= &image
->tables
[MONO_TABLE_TYPEDEF
];
1333 guint32 index
= entry
[0];
1334 guint32 next
= entry
[1];
1335 guint32 token
= mono_metadata_make_token (MONO_TABLE_TYPEDEF
, index
);
1337 name_table_accesses
++;
1339 mono_metadata_decode_row (t
, index
- 1, cols
, MONO_TYPEDEF_SIZE
);
1341 name2
= mono_metadata_string_heap (image
, cols
[MONO_TYPEDEF_NAME
]);
1342 name_space2
= mono_metadata_string_heap (image
, cols
[MONO_TYPEDEF_NAMESPACE
]);
1344 if (!strcmp (name
, name2
) && !strcmp (name_space
, name_space2
)) {
1346 *klass
= mono_class_get (image
, token
);
1351 nspace_table
= g_hash_table_lookup (aot_module
->name_cache
, name_space
);
1352 if (!nspace_table
) {
1353 nspace_table
= g_hash_table_new (g_str_hash
, g_str_equal
);
1354 g_hash_table_insert (aot_module
->name_cache
, (char*)name_space2
, nspace_table
);
1356 g_hash_table_insert (nspace_table
, (char*)name2
, *klass
);
1363 entry
= &table
[next
* 2];
1376 * LOCKING: Acquires the domain lock.
1379 decode_exception_debug_info (MonoAotModule
*amodule
, MonoDomain
*domain
,
1380 MonoMethod
*method
, guint8
* ex_info
, guint8
*code
)
1384 guint code_len
, used_int_regs
, flags
;
1385 gboolean has_generic_jit_info
, has_dwarf_unwind_info
, has_clauses
, has_seq_points
;
1387 int generic_info_size
;
1389 /* Load the method info from the AOT file */
1392 code_len
= decode_value (p
, &p
);
1393 flags
= decode_value (p
, &p
);
1394 has_generic_jit_info
= (flags
& 1) != 0;
1395 has_dwarf_unwind_info
= (flags
& 2) != 0;
1396 has_clauses
= (flags
& 4) != 0;
1397 has_seq_points
= (flags
& 8) != 0;
1398 if (has_dwarf_unwind_info
) {
1401 offset
= decode_value (p
, &p
);
1402 g_assert (offset
< (1 << 30));
1403 used_int_regs
= offset
;
1405 used_int_regs
= decode_value (p
, &p
);
1407 if (has_generic_jit_info
)
1408 generic_info_size
= sizeof (MonoGenericJitInfo
);
1410 generic_info_size
= 0;
1412 /* Exception table */
1414 int num_clauses
= decode_value (p
, &p
);
1417 mono_domain_alloc0 (domain
, MONO_SIZEOF_JIT_INFO
+ (sizeof (MonoJitExceptionInfo
) * num_clauses
) + generic_info_size
);
1418 jinfo
->num_clauses
= num_clauses
;
1420 for (i
= 0; i
< num_clauses
; ++i
) {
1421 MonoJitExceptionInfo
*ei
= &jinfo
->clauses
[i
];
1423 ei
->flags
= decode_value (p
, &p
);
1424 ei
->exvar_offset
= decode_value (p
, &p
);
1426 if (ei
->flags
== MONO_EXCEPTION_CLAUSE_FILTER
)
1427 ei
->data
.filter
= code
+ decode_value (p
, &p
);
1429 if (decode_value (p
, &p
))
1430 ei
->data
.catch_class
= decode_klass_ref (amodule
, p
, &p
);
1433 ei
->try_start
= code
+ decode_value (p
, &p
);
1434 ei
->try_end
= code
+ decode_value (p
, &p
);
1435 ei
->handler_start
= code
+ decode_value (p
, &p
);
1439 jinfo
= mono_domain_alloc0 (domain
, MONO_SIZEOF_JIT_INFO
+ generic_info_size
);
1442 jinfo
->code_size
= code_len
;
1443 jinfo
->used_regs
= used_int_regs
;
1444 jinfo
->method
= method
;
1445 jinfo
->code_start
= code
;
1446 jinfo
->domain_neutral
= 0;
1447 jinfo
->from_aot
= 1;
1449 if (has_generic_jit_info
) {
1450 MonoGenericJitInfo
*gi
;
1452 jinfo
->has_generic_jit_info
= 1;
1454 gi
= mono_jit_info_get_generic_jit_info (jinfo
);
1457 gi
->has_this
= decode_value (p
, &p
);
1458 gi
->this_reg
= decode_value (p
, &p
);
1459 gi
->this_offset
= decode_value (p
, &p
);
1461 /* This currently contains no data */
1462 gi
->generic_sharing_context
= g_new0 (MonoGenericSharingContext
, 1);
1464 jinfo
->method
= decode_method_ref_2 (amodule
, p
, &p
);
1467 if (has_seq_points
) {
1468 GPtrArray
*seq_points
;
1469 int il_offset
, native_offset
, last_il_offset
, last_native_offset
;
1471 int len
= decode_value (p
, &p
);
1473 seq_points
= g_ptr_array_new ();
1474 last_il_offset
= last_native_offset
= 0;
1475 for (i
= 0; i
< len
; i
+= 2) {
1476 il_offset
= last_il_offset
+ decode_value (p
, &p
);
1477 native_offset
= last_native_offset
+ decode_value (p
, &p
);
1479 g_ptr_array_add (seq_points
, GINT_TO_POINTER (il_offset
));
1480 g_ptr_array_add (seq_points
, GINT_TO_POINTER (native_offset
));
1482 last_il_offset
= il_offset
;
1483 last_native_offset
= native_offset
;
1486 mono_domain_lock (domain
);
1487 g_hash_table_insert (domain_jit_info (domain
)->seq_points
, method
, seq_points
);
1488 mono_domain_unlock (domain
);
1491 /* Load debug info */
1492 buf_len
= decode_value (p
, &p
);
1493 mono_debug_add_aot_method (domain
, method
, code
, p
, buf_len
);
1495 if (amodule
!= jinfo
->method
->klass
->image
->aot_module
) {
1498 ji_to_amodule
= g_hash_table_new (NULL
, NULL
);
1499 g_hash_table_insert (ji_to_amodule
, jinfo
, amodule
);
1507 * mono_aot_get_unwind_info:
1509 * Return a pointer to the DWARF unwind info belonging to JI.
1512 mono_aot_get_unwind_info (MonoJitInfo
*ji
, guint32
*unwind_info_len
)
1514 MonoAotModule
*amodule
= ji
->method
->klass
->image
->aot_module
;
1516 guint8
*code
= ji
->code_start
;
1519 g_assert (ji
->from_aot
);
1521 if (!(code
>= amodule
->code
&& code
<= amodule
->code_end
)) {
1522 /* ji belongs to a different aot module than amodule */
1524 g_assert (ji_to_amodule
);
1525 amodule
= g_hash_table_lookup (ji_to_amodule
, ji
);
1527 g_assert (code
>= amodule
->code
&& code
<= amodule
->code_end
);
1530 p
= amodule
->unwind_info
+ ji
->used_regs
;
1531 *unwind_info_len
= decode_value (p
, &p
);
1536 mono_aot_find_jit_info (MonoDomain
*domain
, MonoImage
*image
, gpointer addr
)
1538 int pos
, left
, right
, offset
, offset1
, offset2
, last_offset
, new_offset
;
1539 int page_index
, method_index
, table_len
, is_wrapper
;
1541 MonoAotModule
*amodule
= image
->aot_module
;
1544 guint8
*code
, *ex_info
, *p
;
1545 guint32
*table
, *ptr
;
1551 if (domain
!= mono_get_root_domain ())
1555 offset
= (guint8
*)addr
- amodule
->code
;
1557 /* First search through the index */
1558 ptr
= amodule
->method_order
;
1563 if (*ptr
== 0xffffff)
1567 while (*ptr
!= 0xffffff) {
1568 guint32 method_index
= ptr
[0];
1569 new_offset
= amodule
->code_offsets
[method_index
];
1571 if (offset
>= last_offset
&& offset
< new_offset
) {
1577 last_offset
= new_offset
;
1581 /* Skip rest of index */
1582 while (*ptr
!= 0xffffff)
1587 table_len
= amodule
->method_order_end
- table
;
1589 g_assert (table
<= amodule
->method_order_end
);
1592 left
= (page_index
* 1024);
1593 right
= left
+ 1024;
1595 if (right
> table_len
)
1598 offset1
= amodule
->code_offsets
[table
[left
]];
1599 g_assert (offset1
<= offset
);
1601 //printf ("Found in index: 0x%x 0x%x 0x%x\n", offset, last_offset, new_offset);
1604 //printf ("Not found in index: 0x%x\n", offset);
1609 /* Binary search inside the method_order table to find the method */
1611 pos
= (left
+ right
) / 2;
1613 g_assert (table
+ pos
<= amodule
->method_order_end
);
1615 //printf ("Pos: %5d < %5d < %5d Offset: 0x%05x < 0x%05x < 0x%05x\n", left, pos, right, amodule->code_offsets [table [left]], offset, amodule->code_offsets [table [right]]);
1617 offset1
= amodule
->code_offsets
[table
[pos
]];
1618 if (table
+ pos
+ 1 >= amodule
->method_order_end
)
1619 offset2
= amodule
->code_end
- amodule
->code
;
1621 offset2
= amodule
->code_offsets
[table
[pos
+ 1]];
1623 if (offset
< offset1
)
1625 else if (offset
>= offset2
)
1631 method_index
= table
[pos
];
1633 /* Might be a wrapper/extra method */
1634 if (amodule
->extra_methods
) {
1636 method
= g_hash_table_lookup (amodule
->extra_methods
, GUINT_TO_POINTER (method_index
));
1643 if (method_index
>= image
->tables
[MONO_TABLE_METHOD
].rows
) {
1645 * This is hit for extra methods which are called directly, so they are
1646 * not in amodule->extra_methods.
1648 table_len
= amodule
->extra_method_info_offsets
[0];
1649 table
= amodule
->extra_method_info_offsets
+ 1;
1656 pos
= ((left
+ right
) / 2);
1658 g_assert (pos
< table_len
);
1660 if (table
[pos
* 2] < method_index
)
1662 else if (table
[pos
* 2] > method_index
)
1668 p
= amodule
->extra_method_info
+ table
[(pos
* 2) + 1];
1669 is_wrapper
= decode_value (p
, &p
);
1670 g_assert (!is_wrapper
);
1671 method
= decode_method_ref_2 (amodule
, p
, &p
);
1674 token
= mono_metadata_make_token (MONO_TABLE_METHOD
, method_index
+ 1);
1675 method
= mono_get_method (image
, token
, NULL
);
1682 //printf ("F: %s\n", mono_method_full_name (method, TRUE));
1684 code
= &amodule
->code
[amodule
->code_offsets
[method_index
]];
1685 ex_info
= &amodule
->ex_info
[amodule
->ex_info_offsets
[method_index
]];
1687 jinfo
= decode_exception_debug_info (amodule
, domain
, method
, ex_info
, code
);
1689 g_assert ((guint8
*)addr
>= (guint8
*)jinfo
->code_start
);
1690 g_assert ((guint8
*)addr
< (guint8
*)jinfo
->code_start
+ jinfo
->code_size
);
1692 /* Add it to the normal JitInfo tables */
1693 mono_jit_info_table_add (domain
, jinfo
);
1699 decode_patch (MonoAotModule
*aot_module
, MonoMemPool
*mp
, MonoJumpInfo
*ji
, guint8
*buf
, guint8
**endbuf
)
1707 case MONO_PATCH_INFO_METHOD
:
1708 case MONO_PATCH_INFO_METHOD_JUMP
:
1709 case MONO_PATCH_INFO_ICALL_ADDR
:
1710 case MONO_PATCH_INFO_METHOD_RGCTX
: {
1713 gboolean no_aot_trampoline
;
1715 image
= decode_method_ref (aot_module
, &token
, &method
, &no_aot_trampoline
, p
, &p
);
1719 if (!method
&& !mono_aot_only
&& !no_aot_trampoline
&& (ji
->type
== MONO_PATCH_INFO_METHOD
) && (mono_metadata_token_table (token
) == MONO_TABLE_METHOD
)) {
1720 ji
->data
.target
= mono_create_ftnptr (mono_domain_get (), mono_create_jit_trampoline_from_token (image
, token
));
1721 ji
->type
= MONO_PATCH_INFO_ABS
;
1725 ji
->data
.method
= method
;
1727 ji
->data
.method
= mono_get_method (image
, token
, NULL
);
1728 g_assert (ji
->data
.method
);
1729 mono_class_init (ji
->data
.method
->klass
);
1733 case MONO_PATCH_INFO_INTERNAL_METHOD
:
1734 case MONO_PATCH_INFO_JIT_ICALL_ADDR
: {
1735 guint32 len
= decode_value (p
, &p
);
1737 ji
->data
.name
= (char*)p
;
1741 case MONO_PATCH_INFO_METHODCONST
:
1743 ji
->data
.method
= decode_method_ref_2 (aot_module
, p
, &p
);
1744 if (!ji
->data
.method
)
1747 case MONO_PATCH_INFO_VTABLE
:
1748 case MONO_PATCH_INFO_CLASS
:
1749 case MONO_PATCH_INFO_IID
:
1750 case MONO_PATCH_INFO_ADJUSTED_IID
:
1752 ji
->data
.klass
= decode_klass_ref (aot_module
, p
, &p
);
1753 if (!ji
->data
.klass
)
1756 case MONO_PATCH_INFO_CLASS_INIT
:
1757 case MONO_PATCH_INFO_DELEGATE_TRAMPOLINE
:
1758 ji
->data
.klass
= decode_klass_ref (aot_module
, p
, &p
);
1759 if (!ji
->data
.klass
)
1762 case MONO_PATCH_INFO_IMAGE
:
1763 ji
->data
.image
= load_image (aot_module
, decode_value (p
, &p
));
1764 if (!ji
->data
.image
)
1767 case MONO_PATCH_INFO_FIELD
:
1768 case MONO_PATCH_INFO_SFLDA
:
1770 ji
->data
.field
= decode_field_info (aot_module
, p
, &p
);
1771 if (!ji
->data
.field
)
1774 case MONO_PATCH_INFO_SWITCH
:
1775 ji
->data
.table
= mono_mempool_alloc0 (mp
, sizeof (MonoJumpInfoBBTable
));
1776 ji
->data
.table
->table_size
= decode_value (p
, &p
);
1777 table
= g_new (gpointer
, ji
->data
.table
->table_size
);
1778 ji
->data
.table
->table
= (MonoBasicBlock
**)table
;
1779 for (i
= 0; i
< ji
->data
.table
->table_size
; i
++)
1780 table
[i
] = (gpointer
)(gssize
)decode_value (p
, &p
);
1782 case MONO_PATCH_INFO_R4
: {
1785 ji
->data
.target
= mono_domain_alloc0 (mono_domain_get (), sizeof (float));
1786 val
= decode_value (p
, &p
);
1787 *(float*)ji
->data
.target
= *(float*)&val
;
1790 case MONO_PATCH_INFO_R8
: {
1794 ji
->data
.target
= mono_domain_alloc0 (mono_domain_get (), sizeof (double));
1796 val
[0] = decode_value (p
, &p
);
1797 val
[1] = decode_value (p
, &p
);
1798 // FIXME: Is this correct ?
1799 v
= ((guint64
)val
[1] << 32) | ((guint64
)val
[0]);
1800 *(double*)ji
->data
.target
= *(double*)&v
;
1803 case MONO_PATCH_INFO_LDSTR
:
1804 image
= load_image (aot_module
, decode_value (p
, &p
));
1807 ji
->data
.token
= mono_jump_info_token_new (mp
, image
, MONO_TOKEN_STRING
+ decode_value (p
, &p
));
1809 case MONO_PATCH_INFO_RVA
:
1810 case MONO_PATCH_INFO_DECLSEC
:
1811 case MONO_PATCH_INFO_LDTOKEN
:
1812 case MONO_PATCH_INFO_TYPE_FROM_HANDLE
:
1814 image
= load_image (aot_module
, decode_value (p
, &p
));
1817 ji
->data
.token
= mono_jump_info_token_new (mp
, image
, decode_value (p
, &p
));
1819 ji
->data
.token
->has_context
= decode_value (p
, &p
);
1820 if (ji
->data
.token
->has_context
) {
1821 gboolean res
= decode_generic_context (aot_module
, &ji
->data
.token
->context
, p
, &p
);
1826 case MONO_PATCH_INFO_EXC_NAME
:
1827 ji
->data
.klass
= decode_klass_ref (aot_module
, p
, &p
);
1828 if (!ji
->data
.klass
)
1830 ji
->data
.name
= ji
->data
.klass
->name
;
1832 case MONO_PATCH_INFO_METHOD_REL
:
1833 ji
->data
.offset
= decode_value (p
, &p
);
1835 case MONO_PATCH_INFO_INTERRUPTION_REQUEST_FLAG
:
1836 case MONO_PATCH_INFO_GENERIC_CLASS_INIT
:
1837 case MONO_PATCH_INFO_MONITOR_ENTER
:
1838 case MONO_PATCH_INFO_MONITOR_EXIT
:
1840 case MONO_PATCH_INFO_RGCTX_FETCH
: {
1842 MonoJumpInfoRgctxEntry
*entry
;
1844 entry
= mono_mempool_alloc0 (mp
, sizeof (MonoJumpInfoRgctxEntry
));
1845 entry
->method
= decode_method_ref_2 (aot_module
, p
, &p
);
1846 entry
->in_mrgctx
= decode_value (p
, &p
);
1847 entry
->info_type
= decode_value (p
, &p
);
1848 entry
->data
= mono_mempool_alloc0 (mp
, sizeof (MonoJumpInfo
));
1849 entry
->data
->type
= decode_value (p
, &p
);
1851 res
= decode_patch (aot_module
, mp
, entry
->data
, p
, &p
);
1854 ji
->data
.rgctx_entry
= entry
;
1857 case MONO_PATCH_INFO_SEQ_POINT_INFO
:
1860 g_warning ("unhandled type %d", ji
->type
);
1861 g_assert_not_reached ();
1872 static MonoJumpInfo
*
1873 load_patch_info (MonoAotModule
*aot_module
, MonoMemPool
*mp
, int n_patches
,
1874 guint32
**got_slots
,
1875 guint8
*buf
, guint8
**endbuf
)
1877 MonoJumpInfo
*patches
;
1883 patches
= mono_mempool_alloc0 (mp
, sizeof (MonoJumpInfo
) * n_patches
);
1885 *got_slots
= g_malloc (sizeof (guint32
) * n_patches
);
1887 for (pindex
= 0; pindex
< n_patches
; ++pindex
) {
1888 MonoJumpInfo
*ji
= &patches
[pindex
];
1893 got_offset
= decode_value (p
, &p
);
1895 if (aot_module
->got
[got_offset
]) {
1896 /* Already loaded */
1897 //printf ("HIT!\n");
1899 shared_p
= aot_module
->got_info
+ aot_module
->got_info_offsets
[got_offset
];
1901 ji
->type
= decode_value (shared_p
, &shared_p
);
1903 res
= decode_patch (aot_module
, mp
, ji
, shared_p
, &shared_p
);
1908 (*got_slots
) [pindex
] = got_offset
;
1915 g_free (*got_slots
);
1922 register_jump_target_got_slot (MonoDomain
*domain
, MonoMethod
*method
, gpointer
*got_slot
)
1925 * Jump addresses cannot be patched by the trampoline code since it
1926 * does not have access to the caller's address. Instead, we collect
1927 * the addresses of the GOT slots pointing to a method, and patch
1928 * them after the method has been compiled.
1930 MonoJitDomainInfo
*info
= domain_jit_info (domain
);
1933 mono_domain_lock (domain
);
1934 if (!info
->jump_target_got_slot_hash
)
1935 info
->jump_target_got_slot_hash
= g_hash_table_new (NULL
, NULL
);
1936 list
= g_hash_table_lookup (info
->jump_target_got_slot_hash
, method
);
1937 list
= g_slist_prepend (list
, got_slot
);
1938 g_hash_table_insert (info
->jump_target_got_slot_hash
, method
, list
);
1939 mono_domain_unlock (domain
);
1945 * Load the method identified by METHOD_INDEX from the AOT image. Return a
1946 * pointer to the native code of the method, or NULL if not found.
1947 * METHOD might not be set if the caller only has the image/token info.
1950 load_method (MonoDomain
*domain
, MonoAotModule
*amodule
, MonoImage
*image
, MonoMethod
*method
, guint32 token
, int method_index
)
1953 gboolean from_plt
= method
== NULL
;
1955 int i
, pindex
, n_patches
, used_strings
;
1956 gboolean keep_patches
= TRUE
;
1957 guint8
*p
, *ex_info
;
1958 MonoJitInfo
*jinfo
= NULL
;
1959 guint8
*code
, *info
;
1961 if (mono_profiler_get_events () & MONO_PROFILE_ENTER_LEAVE
)
1964 if ((domain
!= mono_get_root_domain ()) && (!(amodule
->opts
& MONO_OPT_SHARED
)))
1965 /* Non shared AOT code can't be used in other appdomains */
1968 if (amodule
->out_of_date
)
1971 if (amodule
->code_offsets
[method_index
] == 0xffffffff) {
1972 if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
)) {
1976 method
= mono_get_method (image
, token
, NULL
);
1977 full_name
= mono_method_full_name (method
, TRUE
);
1978 mono_trace (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
, "AOT NOT FOUND: %s.\n", full_name
);
1984 code
= &amodule
->code
[amodule
->code_offsets
[method_index
]];
1985 info
= &amodule
->method_info
[amodule
->method_info_offsets
[method_index
]];
1988 if (!amodule
->methods_loaded
)
1989 amodule
->methods_loaded
= g_new0 (guint32
, amodule
->info
.nmethods
+ 1);
1992 if ((amodule
->methods_loaded
[method_index
/ 32] >> (method_index
% 32)) & 0x1)
1995 if (mono_last_aot_method
!= -1) {
1996 if (mono_jit_stats
.methods_aot
>= mono_last_aot_method
)
1998 else if (mono_jit_stats
.methods_aot
== mono_last_aot_method
- 1) {
2000 printf ("LAST AOT METHOD: %s%s%s.%s.\n", method
->klass
->name_space
, method
->klass
->name_space
[0] ? "." : "", method
->klass
->name
, method
->name
);
2002 printf ("LAST AOT METHOD: %p %d\n", code
, method_index
);
2009 klass
= method
->klass
;
2010 decode_klass_ref (amodule
, p
, &p
);
2012 klass
= decode_klass_ref (amodule
, p
, &p
);
2015 if (amodule
->opts
& MONO_OPT_SHARED
)
2016 used_strings
= decode_value (p
, &p
);
2020 for (i
= 0; i
< used_strings
; i
++) {
2021 guint token
= decode_value (p
, &p
);
2022 mono_ldstr (mono_get_root_domain (), image
, mono_metadata_token_index (token
));
2025 if (amodule
->opts
& MONO_OPT_SHARED
)
2026 keep_patches
= FALSE
;
2028 n_patches
= decode_value (p
, &p
);
2030 keep_patches
= FALSE
;
2033 MonoJumpInfo
*patches
;
2039 mp
= mono_mempool_new ();
2041 patches
= load_patch_info (amodule
, mp
, n_patches
, &got_slots
, p
, &p
);
2042 if (patches
== NULL
)
2045 for (pindex
= 0; pindex
< n_patches
; ++pindex
) {
2046 MonoJumpInfo
*ji
= &patches
[pindex
];
2048 if (!amodule
->got
[got_slots
[pindex
]]) {
2049 amodule
->got
[got_slots
[pindex
]] = mono_resolve_patch_target (method
, domain
, code
, ji
, TRUE
);
2050 if (ji
->type
== MONO_PATCH_INFO_METHOD_JUMP
)
2051 amodule
->got
[got_slots
[pindex
]] = mono_create_ftnptr (domain
, amodule
->got
[got_slots
[pindex
]]);
2052 if (ji
->type
== MONO_PATCH_INFO_METHOD_JUMP
)
2053 register_jump_target_got_slot (domain
, ji
->data
.method
, &(amodule
->got
[got_slots
[pindex
]]));
2055 ji
->type
= MONO_PATCH_INFO_NONE
;
2061 mono_mempool_destroy (mp
);
2064 if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
)) {
2068 method
= mono_get_method (image
, token
, NULL
);
2070 full_name
= mono_method_full_name (method
, TRUE
);
2073 ex_info
= &amodule
->ex_info
[amodule
->ex_info_offsets
[method_index
]];
2074 jinfo
= decode_exception_debug_info (amodule
, domain
, method
, ex_info
, code
);
2077 mono_trace (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
, "AOT FOUND AOT compiled code for %s %p - %p %p\n", full_name
, code
, code
+ jinfo
->code_size
, info
);
2083 mono_jit_stats
.methods_aot
++;
2085 amodule
->methods_loaded
[method_index
/ 32] |= 1 << (method_index
% 32);
2089 if (method
&& method
->wrapper_type
)
2090 g_hash_table_insert (amodule
->method_to_code
, method
, code
);
2094 if (mono_profiler_get_events () & MONO_PROFILE_JIT_COMPILATION
) {
2098 method
= mono_get_method (image
, token
, NULL
);
2101 mono_profiler_method_jit (method
);
2102 jinfo
= mono_jit_info_table_find (domain
, (char*)code
);
2104 mono_profiler_method_end_jit (method
, jinfo
, MONO_PROFILE_OK
);
2107 if (from_plt
&& klass
&& !klass
->generic_container
)
2108 mono_runtime_class_init (mono_class_vtable (domain
, klass
));
2113 /* FIXME: The space in domain->mp is wasted */
2114 if (amodule
->opts
& MONO_OPT_SHARED
)
2115 /* No need to cache patches */
2116 mono_mempool_destroy (mp
);
2125 find_extra_method_in_amodule (MonoAotModule
*amodule
, MonoMethod
*method
)
2127 guint32 table_size
, entry_size
, hash
;
2128 guint32
*table
, *entry
;
2131 static guint32 n_extra_decodes
;
2136 table_size
= amodule
->extra_method_table
[0];
2137 table
= amodule
->extra_method_table
+ 1;
2140 if (method
->wrapper_type
) {
2141 name
= mono_aot_wrapper_name (method
);
2144 hash
= mono_aot_method_hash (method
) % table_size
;
2146 entry
= &table
[hash
* entry_size
];
2153 guint32 key
= entry
[0];
2154 guint32 value
= entry
[1];
2155 guint32 next
= entry
[entry_size
- 1];
2158 int is_wrapper_name
;
2160 p
= amodule
->extra_method_info
+ key
;
2161 is_wrapper_name
= decode_value (p
, &p
);
2162 if (is_wrapper_name
) {
2163 int wrapper_type
= decode_value (p
, &p
);
2164 if (wrapper_type
== method
->wrapper_type
&& !strcmp (name
, (char*)p
)) {
2168 } else if (can_method_ref_match_method (amodule
, p
, method
)) {
2170 if (!amodule
->method_ref_to_method
)
2171 amodule
->method_ref_to_method
= g_hash_table_new (NULL
, NULL
);
2172 m
= g_hash_table_lookup (amodule
->method_ref_to_method
, p
);
2176 m
= decode_method_ref_2 (amodule
, p
, &p
);
2179 g_hash_table_insert (amodule
->method_ref_to_method
, orig_p
, m
);
2188 /* Special case: wrappers of shared generic methods */
2189 if (m
&& method
->wrapper_type
&& m
->wrapper_type
== m
->wrapper_type
&&
2190 method
->wrapper_type
== MONO_WRAPPER_SYNCHRONIZED
) {
2191 MonoMethod
*w1
= mono_marshal_method_from_wrapper (method
);
2192 MonoMethod
*w2
= mono_marshal_method_from_wrapper (m
);
2194 if (w1
->is_inflated
&& ((MonoMethodInflated
*)w1
)->declaring
== w2
) {
2200 /* Methods decoded needlessly */
2203 printf ("%d %s %s\n", n_extra_decodes, mono_method_full_name (method, TRUE), mono_method_full_name (m, TRUE));
2209 entry
= &table
[next
* entry_size
];
2219 add_module_cb (gpointer key
, gpointer value
, gpointer user_data
)
2221 g_ptr_array_add ((GPtrArray
*)user_data
, value
);
2225 * find_extra_method:
2227 * Try finding METHOD in the extra_method table in all AOT images.
2228 * Return its method index, or 0xffffff if not found. Set OUT_AMODULE to the AOT
2229 * module where the method was found.
2232 find_extra_method (MonoMethod
*method
, MonoAotModule
**out_amodule
)
2238 /* Try the method's module first */
2239 *out_amodule
= method
->klass
->image
->aot_module
;
2240 index
= find_extra_method_in_amodule (method
->klass
->image
->aot_module
, method
);
2241 if (index
!= 0xffffff)
2245 * Try all other modules.
2246 * This is needed because generic instances klass->image points to the image
2247 * containing the generic definition, but the native code is generated to the
2248 * AOT image which contains the reference.
2251 /* Make a copy to avoid doing the search inside the aot lock */
2252 modules
= g_ptr_array_new ();
2254 g_hash_table_foreach (aot_modules
, add_module_cb
, modules
);
2258 for (i
= 0; i
< modules
->len
; ++i
) {
2259 MonoAotModule
*amodule
= g_ptr_array_index (modules
, i
);
2261 if (amodule
!= method
->klass
->image
->aot_module
)
2262 index
= find_extra_method_in_amodule (amodule
, method
);
2263 if (index
!= 0xffffff) {
2264 *out_amodule
= amodule
;
2269 g_ptr_array_free (modules
, TRUE
);
2275 * mono_aot_get_method:
2277 * Return a pointer to the AOTed native code for METHOD if it can be found,
2279 * On platforms with function pointers, this doesn't return a function pointer.
2282 mono_aot_get_method (MonoDomain
*domain
, MonoMethod
*method
)
2284 MonoClass
*klass
= method
->klass
;
2285 guint32 method_index
;
2286 MonoAotModule
*amodule
= klass
->image
->aot_module
;
2292 if (amodule
->out_of_date
)
2295 if ((method
->iflags
& METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
) ||
2296 (method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
) ||
2297 (method
->iflags
& METHOD_IMPL_ATTRIBUTE_RUNTIME
) ||
2298 (method
->flags
& METHOD_ATTRIBUTE_ABSTRACT
))
2302 * Use the original method instead of its invoke-with-check wrapper.
2303 * This is not a problem when using full-aot, since it doesn't support
2306 if (mono_aot_only
&& method
->wrapper_type
== MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK
)
2307 return mono_aot_get_method (domain
, mono_marshal_method_from_wrapper (method
));
2309 g_assert (klass
->inited
);
2311 /* Find method index */
2312 if (method
->is_inflated
&& mono_method_is_generic_sharable_impl (method
, FALSE
)) {
2313 method
= mono_method_get_declaring_generic_method (method
);
2314 method_index
= mono_metadata_token_index (method
->token
) - 1;
2315 } else if (method
->is_inflated
|| !method
->token
) {
2316 /* This hash table is used to avoid the slower search in the extra_method_table in the AOT image */
2318 code
= g_hash_table_lookup (amodule
->method_to_code
, method
);
2323 method_index
= find_extra_method (method
, &amodule
);
2325 * Special case the ICollection<T> wrappers for arrays, as they cannot
2326 * be statically enumerated, and each wrapper ends up calling the same
2329 if (method_index
== 0xffffff && method
->wrapper_type
== MONO_WRAPPER_MANAGED_TO_MANAGED
&& method
->klass
->rank
&& strstr (method
->name
, "System.Collections.Generic")) {
2330 MonoMethod
*m
= mono_aot_get_array_helper_from_wrapper (method
);
2332 code
= mono_aot_get_method (domain
, m
);
2334 if (mono_method_needs_static_rgctx_invoke (m
, FALSE
))
2335 code
= mono_create_static_rgctx_trampoline (m
, code
);
2342 * Special case Array.GetGenericValueImpl which is a generic icall.
2343 * Generic sharing currently can't handle it, but the icall returns data using
2344 * an out parameter, so the managed-to-native wrappers can share the same code.
2346 if (method_index
== 0xffffff && method
->wrapper_type
== MONO_WRAPPER_MANAGED_TO_NATIVE
&& method
->klass
== mono_defaults
.array_class
&& !strcmp (method
->name
, "GetGenericValueImpl")) {
2348 MonoGenericContext ctx
;
2349 MonoType
*args
[16];
2351 if (mono_method_signature (method
)->params
[1]->type
== MONO_TYPE_OBJECT
)
2352 /* Avoid recursion */
2355 m
= mono_class_get_method_from_name (mono_defaults
.array_class
, "GetGenericValueImpl", 2);
2358 memset (&ctx
, 0, sizeof (ctx
));
2359 args
[0] = &mono_defaults
.object_class
->byval_arg
;
2360 ctx
.method_inst
= mono_metadata_get_generic_inst (1, args
);
2362 m
= mono_marshal_get_native_wrapper (mono_class_inflate_generic_method (m
, &ctx
), TRUE
, TRUE
);
2365 * Get the code for the <object> instantiation which should be emitted into
2366 * the mscorlib aot image by the AOT compiler.
2368 code
= mono_aot_get_method (domain
, m
);
2373 if (method_index
== 0xffffff) {
2374 if (mono_aot_only
&& mono_trace_is_traced (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
)) {
2377 full_name
= mono_method_full_name (method
, TRUE
);
2378 mono_trace (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
, "AOT NOT FOUND: %s.\n", full_name
);
2384 if (method_index
== 0xffffff)
2387 /* Needed by find_jit_info */
2389 if (!amodule
->extra_methods
)
2390 amodule
->extra_methods
= g_hash_table_new (NULL
, NULL
);
2391 g_hash_table_insert (amodule
->extra_methods
, GUINT_TO_POINTER (method_index
), method
);
2395 method_index
= mono_metadata_token_index (method
->token
) - 1;
2398 return load_method (domain
, amodule
, klass
->image
, method
, method
->token
, method_index
);
2402 * Same as mono_aot_get_method, but we try to avoid loading any metadata from the
2406 mono_aot_get_method_from_token (MonoDomain
*domain
, MonoImage
*image
, guint32 token
)
2408 MonoAotModule
*aot_module
= image
->aot_module
;
2414 method_index
= mono_metadata_token_index (token
) - 1;
2416 return load_method (domain
, aot_module
, image
, NULL
, token
, method_index
);
2422 } IsGotEntryUserData
;
2425 check_is_got_entry (gpointer key
, gpointer value
, gpointer user_data
)
2427 IsGotEntryUserData
*data
= (IsGotEntryUserData
*)user_data
;
2428 MonoAotModule
*aot_module
= (MonoAotModule
*)value
;
2430 if (aot_module
->got
&& (data
->addr
>= (guint8
*)(aot_module
->got
)) && (data
->addr
< (guint8
*)(aot_module
->got
+ aot_module
->info
.got_size
)))
2435 mono_aot_is_got_entry (guint8
*code
, guint8
*addr
)
2437 IsGotEntryUserData user_data
;
2442 user_data
.addr
= addr
;
2443 user_data
.res
= FALSE
;
2445 g_hash_table_foreach (aot_modules
, check_is_got_entry
, &user_data
);
2448 return user_data
.res
;
2453 MonoAotModule
*module
;
2454 } FindAotModuleUserData
;
2457 find_aot_module_cb (gpointer key
, gpointer value
, gpointer user_data
)
2459 FindAotModuleUserData
*data
= (FindAotModuleUserData
*)user_data
;
2460 MonoAotModule
*aot_module
= (MonoAotModule
*)value
;
2462 if ((data
->addr
>= (guint8
*)(aot_module
->code
)) && (data
->addr
< (guint8
*)(aot_module
->code_end
)))
2463 data
->module
= aot_module
;
2466 static inline MonoAotModule
*
2467 find_aot_module (guint8
*code
)
2469 FindAotModuleUserData user_data
;
2474 /* Reading these need no locking */
2475 if (((gsize
)code
< aot_code_low_addr
) || ((gsize
)code
> aot_code_high_addr
))
2478 user_data
.addr
= code
;
2479 user_data
.module
= NULL
;
2482 g_hash_table_foreach (aot_modules
, find_aot_module_cb
, &user_data
);
2485 return user_data
.module
;
2489 * mono_aot_plt_resolve:
2491 * This function is called by the entries in the PLT to resolve the actual method that
2492 * needs to be called. It returns a trampoline to the method and patches the PLT entry.
2495 mono_aot_plt_resolve (gpointer aot_module
, guint32 plt_info_offset
, guint8
*code
)
2497 #ifdef MONO_ARCH_AOT_SUPPORTED
2498 guint8
*p
, *target
, *plt_entry
;
2500 MonoAotModule
*module
= (MonoAotModule
*)aot_module
;
2501 gboolean res
, no_ftnptr
= FALSE
;
2504 //printf ("DYN: %p %d\n", aot_module, plt_info_offset);
2506 p
= &module
->got_info
[plt_info_offset
];
2508 ji
.type
= decode_value (p
, &p
);
2510 mp
= mono_mempool_new_size (512);
2511 res
= decode_patch (module
, mp
, &ji
, p
, &p
);
2512 // FIXME: Error handling (how ?)
2516 * Avoid calling resolve_patch_target in the full-aot case if possible, since
2517 * it would create a trampoline, and we don't need that.
2518 * We could do this only if the method does not need the special handling
2519 * in mono_magic_trampoline ().
2521 if (mono_aot_only
&& ji
.type
== MONO_PATCH_INFO_METHOD
&& !ji
.data
.method
->is_generic
&& !mono_method_check_context_used (ji
.data
.method
) && !(ji
.data
.method
->iflags
& METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED
) &&
2522 !mono_method_needs_static_rgctx_invoke (ji
.data
.method
, FALSE
)) {
2523 target
= mono_jit_compile_method (ji
.data
.method
);
2526 target
= mono_resolve_patch_target (NULL
, mono_domain_get (), NULL
, &ji
, TRUE
);
2529 // FIXME: Clean this up, but how ?
2530 if (ji
.type
!= MONO_PATCH_INFO_ABS
&& ji
.type
!= MONO_PATCH_INFO_INTERNAL_METHOD
&& ji
.type
!= MONO_PATCH_INFO_CLASS_INIT
&& ji
.type
!= MONO_PATCH_INFO_GENERIC_CLASS_INIT
&& ji
.type
!= MONO_PATCH_INFO_ICALL_ADDR
&& ji
.type
!= MONO_PATCH_INFO_JIT_ICALL_ADDR
&& !no_ftnptr
) {
2531 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
2532 g_assert (((gpointer
*)target
) [2] != 0);
2534 target
= mono_create_ftnptr (mono_domain_get (), target
);
2537 mono_mempool_destroy (mp
);
2539 /* Patch the PLT entry with target which might be the actual method not a trampoline */
2540 plt_entry
= mono_aot_get_plt_entry (code
);
2541 g_assert (plt_entry
);
2542 mono_arch_patch_plt_entry (plt_entry
, module
->got
, NULL
, target
);
2546 g_assert_not_reached ();
2554 * Initialize the PLT table of the AOT module. Called lazily when the first AOT
2555 * method in the module is loaded to avoid committing memory by writing to it.
2556 * LOCKING: Assumes the AOT lock is held.
2559 init_plt (MonoAotModule
*amodule
)
2561 #ifndef MONO_CROSS_COMPILE
2563 #ifdef MONO_ARCH_AOT_SUPPORTED
2565 guint8
*buf
= amodule
->plt
;
2566 #elif defined(__x86_64__) || defined(__arm__) || defined(__mono_ppc__)
2572 if (amodule
->plt_inited
)
2575 tramp
= mono_create_specific_trampoline (amodule
, MONO_TRAMPOLINE_AOT_PLT
, mono_get_root_domain (), NULL
);
2578 /* Initialize the first PLT entry */
2579 make_writable (amodule
->plt
, amodule
->plt_end
- amodule
->plt
);
2580 x86_jump_code (buf
, tramp
);
2581 #elif defined(__x86_64__) || defined(__arm__) || defined(__mono_ppc__)
2583 * Initialize the PLT entries in the GOT to point to the default targets.
2586 tramp
= mono_create_ftnptr (mono_domain_get (), tramp
);
2587 plt_0
= mono_create_ftnptr (mono_domain_get (), amodule
->plt
);
2588 /* The first entry points to the AOT trampoline */
2589 ((gpointer
*)amodule
->got
)[amodule
->info
.plt_got_offset_base
] = tramp
;
2590 for (i
= 1; i
< amodule
->info
.plt_size
; ++i
)
2591 /* All the default entries point to the first entry */
2592 ((gpointer
*)amodule
->got
)[amodule
->info
.plt_got_offset_base
+ i
] = plt_0
;
2594 g_assert_not_reached ();
2597 amodule
->plt_inited
= TRUE
;
2600 #endif /* MONO_CROSS_COMPILE */
2604 * mono_aot_get_plt_entry:
2606 * Return the address of the PLT entry called by the code at CODE if exists.
2609 mono_aot_get_plt_entry (guint8
*code
)
2611 MonoAotModule
*aot_module
= find_aot_module (code
);
2612 #if defined(__arm__) || defined(__mono_ppc__)
2619 #if defined(__i386__) || defined(__x86_64__)
2620 if (code
[-5] == 0xe8) {
2621 guint32 disp
= *(guint32
*)(code
- 4);
2622 guint8
*target
= code
+ disp
;
2624 if ((target
>= (guint8
*)(aot_module
->plt
)) && (target
< (guint8
*)(aot_module
->plt_end
)))
2627 #elif defined(__arm__)
2628 ins
= ((guint32
*)(gpointer
)code
) [-1];
2630 /* Should be a 'bl' */
2631 if ((((ins
>> 25) & 0x7) == 0x5) && (((ins
>> 24) & 0x1) == 0x1)) {
2632 gint32 disp
= ((gint32
)ins
) & 0xffffff;
2633 guint8
*target
= code
- 4 + 8 + (disp
* 4);
2635 if ((target
>= (guint8
*)(aot_module
->plt
)) && (target
< (guint8
*)(aot_module
->plt_end
)))
2638 #elif defined(__mono_ppc__)
2639 /* Should be a bl */
2640 ins
= ((guint32
*)(gpointer
)code
) [-1];
2642 if ((ins
>> 26 == 18) && ((ins
& 1) == 1) && ((ins
& 2) == 0)) {
2643 gint32 disp
= (((gint32
)ins
) >> 2) & 0xffffff;
2644 guint8
*target
= code
- 4 + (disp
* 4);
2646 if ((target
>= (guint8
*)(aot_module
->plt
)) && (target
< (guint8
*)(aot_module
->plt_end
)))
2650 g_assert_not_reached ();
2657 * mono_aot_get_plt_info_offset:
2659 * Return the PLT info offset belonging to the plt entry called by CODE.
2662 mono_aot_get_plt_info_offset (mgreg_t
*regs
, guint8
*code
)
2664 guint8
*plt_entry
= mono_aot_get_plt_entry (code
);
2666 g_assert (plt_entry
);
2668 /* The offset is embedded inside the code after the plt entry */
2669 #if defined(__i386__)
2670 return *(guint32
*)(plt_entry
+ 5);
2671 #elif defined(__x86_64__)
2672 return *(guint32
*)(plt_entry
+ 6);
2673 #elif defined(__arm__)
2674 /* The offset is stored as the 4th word of the plt entry */
2675 return ((guint32
*)plt_entry
) [3];
2676 #elif defined(__mono_ppc__)
2677 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
2678 return ((guint32
*)plt_entry
) [8];
2680 return ((guint32
*)plt_entry
) [6];
2683 g_assert_not_reached ();
2689 mono_create_ftnptr_malloc (guint8
*code
)
2691 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
2692 MonoPPCFunctionDescriptor
*ftnptr
= g_malloc0 (sizeof (MonoPPCFunctionDescriptor
));
2694 ftnptr
->code
= code
;
2707 * Load the function named NAME from the aot image.
2710 load_function (MonoAotModule
*amodule
, const char *name
)
2714 int n_patches
, pindex
;
2720 symbol
= g_strdup_printf ("%s", name
);
2721 find_symbol (amodule
->sofile
, amodule
->globals
, symbol
, (gpointer
*)&code
);
2724 g_error ("Symbol '%s' not found in AOT file '%s'.\n", name
, amodule
->aot_name
);
2726 mono_trace (G_LOG_LEVEL_DEBUG
, MONO_TRACE_AOT
, "AOT FOUND function '%s' in AOT file '%s'.\n", name
, amodule
->aot_name
);
2730 symbol
= g_strdup_printf ("%s_p", name
);
2731 find_symbol (amodule
->sofile
, amodule
->globals
, symbol
, (gpointer
*)&p
);
2734 /* Nothing to patch */
2737 /* Similar to mono_aot_load_method () */
2739 n_patches
= decode_value (p
, &p
);
2742 MonoJumpInfo
*patches
;
2745 mp
= mono_mempool_new ();
2747 patches
= load_patch_info (amodule
, mp
, n_patches
, &got_slots
, p
, &p
);
2750 for (pindex
= 0; pindex
< n_patches
; ++pindex
) {
2751 MonoJumpInfo
*ji
= &patches
[pindex
];
2754 if (amodule
->got
[got_slots
[pindex
]])
2758 * When this code is executed, the runtime may not be initalized yet, so
2759 * resolve the patch info by hand.
2761 if (ji
->type
== MONO_PATCH_INFO_JIT_ICALL_ADDR
) {
2762 if (!strcmp (ji
->data
.name
, "mono_get_lmf_addr")) {
2763 target
= mono_get_lmf_addr
;
2764 } else if (!strcmp (ji
->data
.name
, "mono_thread_force_interruption_checkpoint")) {
2765 target
= mono_thread_force_interruption_checkpoint
;
2766 } else if (!strcmp (ji
->data
.name
, "mono_exception_from_token")) {
2767 target
= mono_exception_from_token
;
2768 } else if (!strcmp (ji
->data
.name
, "mono_throw_exception")) {
2769 target
= mono_get_throw_exception ();
2771 } else if (!strcmp (ji
->data
.name
, "mono_amd64_throw_exception")) {
2772 target
= mono_amd64_throw_exception
;
2775 } else if (!strcmp (ji
->data
.name
, "mono_amd64_get_original_ip")) {
2776 target
= mono_amd64_get_original_ip
;
2779 } else if (!strcmp (ji
->data
.name
, "mono_arm_throw_exception")) {
2780 target
= mono_arm_throw_exception
;
2781 } else if (!strcmp (ji
->data
.name
, "mono_arm_throw_exception_by_token")) {
2782 target
= mono_arm_throw_exception_by_token
;
2785 } else if (!strcmp (ji
->data
.name
, "mono_ppc_throw_exception")) {
2786 target
= mono_ppc_throw_exception
;
2788 } else if (strstr (ji
->data
.name
, "trampoline_func_") == ji
->data
.name
) {
2789 int tramp_type2
= atoi (ji
->data
.name
+ strlen ("trampoline_func_"));
2790 target
= (gpointer
)mono_get_trampoline_func (tramp_type2
);
2791 } else if (strstr (ji
->data
.name
, "specific_trampoline_lazy_fetch_") == ji
->data
.name
) {
2792 /* atoll is needed because the the offset is unsigned */
2796 res
= sscanf (ji
->data
.name
, "specific_trampoline_lazy_fetch_%u", &slot
);
2797 g_assert (res
== 1);
2798 target
= mono_create_specific_trampoline (GUINT_TO_POINTER (slot
), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH
, mono_get_root_domain (), NULL
);
2799 target
= mono_create_ftnptr_malloc (target
);
2800 } else if (!strcmp (ji
->data
.name
, "specific_trampoline_monitor_enter")) {
2801 target
= mono_create_specific_trampoline (NULL
, MONO_TRAMPOLINE_MONITOR_ENTER
, mono_get_root_domain (), NULL
);
2802 target
= mono_create_ftnptr_malloc (target
);
2803 } else if (!strcmp (ji
->data
.name
, "specific_trampoline_monitor_exit")) {
2804 target
= mono_create_specific_trampoline (NULL
, MONO_TRAMPOLINE_MONITOR_EXIT
, mono_get_root_domain (), NULL
);
2805 target
= mono_create_ftnptr_malloc (target
);
2806 } else if (!strcmp (ji
->data
.name
, "specific_trampoline_generic_class_init")) {
2807 target
= mono_create_specific_trampoline (NULL
, MONO_TRAMPOLINE_GENERIC_CLASS_INIT
, mono_get_root_domain (), NULL
);
2808 target
= mono_create_ftnptr_malloc (target
);
2809 } else if (!strcmp (ji
->data
.name
, "mono_thread_get_and_clear_pending_exception")) {
2810 target
= mono_thread_get_and_clear_pending_exception
;
2812 fprintf (stderr
, "Unknown relocation '%s'\n", ji
->data
.name
);
2813 g_assert_not_reached ();
2817 /* Hopefully the code doesn't have patches which need method or
2820 target
= mono_resolve_patch_target (NULL
, NULL
, code
, ji
, FALSE
);
2824 amodule
->got
[got_slots
[pindex
]] = target
;
2829 mono_mempool_destroy (mp
);
2836 * Return the piece of code identified by NAME from the mscorlib AOT file.
2837 * On ppc64, this returns a function descriptor.
2840 mono_aot_get_named_code (const char *name
)
2843 MonoAotModule
*amodule
;
2845 image
= mono_defaults
.corlib
;
2848 amodule
= image
->aot_module
;
2851 return mono_create_ftnptr_malloc (load_function (amodule
, name
));
2854 /* Return a given kind of trampoline */
2856 get_numerous_trampoline (MonoAotTrampoline tramp_type
, int n_got_slots
, MonoAotModule
**out_amodule
, guint32
*got_offset
, guint32
*out_tramp_size
)
2858 MonoAotModule
*amodule
;
2859 int index
, tramp_size
;
2862 /* Currently, we keep all trampolines in the mscorlib AOT image */
2863 image
= mono_defaults
.corlib
;
2868 amodule
= image
->aot_module
;
2871 *out_amodule
= amodule
;
2873 if (amodule
->trampoline_index
[tramp_type
] == amodule
->info
.num_trampolines
[tramp_type
])
2874 g_error ("Ran out of trampolines of type %d in '%s' (%d)\n", tramp_type
, image
->name
, amodule
->info
.num_trampolines
[tramp_type
]);
2876 index
= amodule
->trampoline_index
[tramp_type
] ++;
2880 *got_offset
= amodule
->info
.trampoline_got_offset_base
[tramp_type
] + (index
* n_got_slots
);
2882 tramp_size
= amodule
->info
.trampoline_size
[tramp_type
];
2885 *out_tramp_size
= tramp_size
;
2887 return amodule
->trampolines
[tramp_type
] + (index
* tramp_size
);
2891 * Return a specific trampoline from the AOT file.
2894 mono_aot_create_specific_trampoline (MonoImage
*image
, gpointer arg1
, MonoTrampolineType tramp_type
, MonoDomain
*domain
, guint32
*code_len
)
2896 MonoAotModule
*amodule
;
2897 guint32 got_offset
, tramp_size
;
2898 guint8
*code
, *tramp
;
2899 static gpointer generic_trampolines
[MONO_TRAMPOLINE_NUM
];
2900 static gboolean inited
;
2901 static guint32 num_trampolines
;
2907 mono_counters_register ("Specific trampolines", MONO_COUNTER_JIT
| MONO_COUNTER_INT
, &num_trampolines
);
2916 if (!generic_trampolines
[tramp_type
]) {
2919 symbol
= g_strdup_printf ("generic_trampoline_%d", tramp_type
);
2920 generic_trampolines
[tramp_type
] = mono_aot_get_named_code (symbol
);
2924 tramp
= generic_trampolines
[tramp_type
];
2927 code
= get_numerous_trampoline (MONO_AOT_TRAMP_SPECIFIC
, 2, &amodule
, &got_offset
, &tramp_size
);
2929 amodule
->got
[got_offset
] = tramp
;
2930 amodule
->got
[got_offset
+ 1] = arg1
;
2933 *code_len
= tramp_size
;
2939 mono_aot_get_static_rgctx_trampoline (gpointer ctx
, gpointer addr
)
2941 MonoAotModule
*amodule
;
2945 code
= get_numerous_trampoline (MONO_AOT_TRAMP_STATIC_RGCTX
, 2, &amodule
, &got_offset
, NULL
);
2947 amodule
->got
[got_offset
] = ctx
;
2948 amodule
->got
[got_offset
+ 1] = addr
;
2950 /* The caller expects an ftnptr */
2951 return mono_create_ftnptr (mono_domain_get (), code
);
2955 mono_aot_get_unbox_trampoline (MonoMethod
*method
)
2957 guint32 method_index
= mono_metadata_token_index (method
->token
) - 1;
2958 MonoAotModule
*amodule
;
2962 if (method
->is_inflated
&& !mono_method_is_generic_sharable_impl (method
, FALSE
)) {
2963 guint32 index
= find_extra_method (method
, &amodule
);
2964 g_assert (index
!= 0xffffff);
2966 symbol
= g_strdup_printf ("ut_e_%d", index
);
2968 amodule
= method
->klass
->image
->aot_module
;
2971 symbol
= g_strdup_printf ("ut_%d", method_index
);
2973 code
= load_function (amodule
, symbol
);
2976 /* The caller expects an ftnptr */
2977 return mono_create_ftnptr (mono_domain_get (), code
);
2981 mono_aot_get_lazy_fetch_trampoline (guint32 slot
)
2986 symbol
= g_strdup_printf ("rgctx_fetch_trampoline_%u", slot
);
2987 code
= load_function (mono_defaults
.corlib
->aot_module
, symbol
);
2993 mono_aot_get_imt_thunk (MonoVTable
*vtable
, MonoDomain
*domain
, MonoIMTCheckItem
**imt_entries
, int count
, gpointer fail_tramp
)
2999 MonoAotModule
*amodule
;
3001 code
= get_numerous_trampoline (MONO_AOT_TRAMP_IMT_THUNK
, 1, &amodule
, &got_offset
, NULL
);
3003 /* Save the entries into an array */
3004 buf
= mono_domain_alloc (domain
, (count
+ 1) * 2 * sizeof (gpointer
));
3005 for (i
= 0; i
< count
; ++i
) {
3006 MonoIMTCheckItem
*item
= imt_entries
[i
];
3008 g_assert (item
->key
);
3010 g_assert (!item
->has_target_code
);
3012 buf
[(i
* 2)] = item
->key
;
3013 buf
[(i
* 2) + 1] = &(vtable
->vtable
[item
->value
.vtable_slot
]);
3015 buf
[(count
* 2)] = NULL
;
3016 buf
[(count
* 2) + 1] = fail_tramp
;
3018 amodule
->got
[got_offset
] = buf
;
3027 mono_aot_init (void)
3032 mono_aot_get_method (MonoDomain
*domain
, MonoMethod
*method
)
3038 mono_aot_is_got_entry (guint8
*code
, guint8
*addr
)
3044 mono_aot_get_cached_class_info (MonoClass
*klass
, MonoCachedClassInfo
*res
)
3050 mono_aot_get_class_from_name (MonoImage
*image
, const char *name_space
, const char *name
, MonoClass
**klass
)
3056 mono_aot_find_jit_info (MonoDomain
*domain
, MonoImage
*image
, gpointer addr
)
3062 mono_aot_get_method_from_token (MonoDomain
*domain
, MonoImage
*image
, guint32 token
)
3068 mono_aot_get_plt_entry (guint8
*code
)
3074 mono_aot_plt_resolve (gpointer aot_module
, guint32 plt_info_offset
, guint8
*code
)
3080 mono_aot_get_method_from_vt_slot (MonoDomain
*domain
, MonoVTable
*vtable
, int slot
)
3086 mono_aot_get_plt_info_offset (mgreg_t
*regs
, guint8
*code
)
3088 g_assert_not_reached ();
3094 mono_aot_create_specific_trampoline (MonoImage
*image
, gpointer arg1
, MonoTrampolineType tramp_type
, MonoDomain
*domain
, guint32
*code_len
)
3096 g_assert_not_reached ();
3101 mono_aot_get_static_rgctx_trampoline (gpointer ctx
, gpointer addr
)
3103 g_assert_not_reached ();
3108 mono_aot_get_named_code (const char *name
)
3110 g_assert_not_reached ();
3115 mono_aot_get_unbox_trampoline (MonoMethod
*method
)
3117 g_assert_not_reached ();
3122 mono_aot_get_lazy_fetch_trampoline (guint32 slot
)
3124 g_assert_not_reached ();
3129 mono_aot_get_imt_thunk (MonoVTable
*vtable
, MonoDomain
*domain
, MonoIMTCheckItem
**imt_entries
, int count
, gpointer fail_tramp
)
3131 g_assert_not_reached ();
3136 mono_aot_get_unwind_info (MonoJitInfo
*ji
, guint32
*unwind_info_len
)
3138 g_assert_not_reached ();