8 #include <mono/metadata/abi-details.h>
10 #include <mono/metadata/class-internals.h>
11 #include <mono/metadata/object-internals.h>
12 #include <mono/metadata/profiler-private.h>
13 #include <mono/metadata/monitor.h>
14 #include <mono/metadata/handle.h>
16 #include <mono/sgen/sgen-gc.h>
18 #ifdef MONO_CLASS_DEF_PRIVATE
19 /* Rationale: MonoClass field offsets are computed here. Need to see the definition.
21 #define REALLY_INCLUDE_CLASS_DEF 1
22 #include <mono/metadata/class-private-definition.h>
23 #undef REALLY_INCLUDE_CLASS_DEF
26 #ifdef MONO_GENERATING_OFFSETS
27 /* The offsets tool uses this structure to compute basic type sizes/alignment */
28 struct basic_types_struct
{
37 typedef struct { gint8 i
; } gint8_struct
;
38 typedef struct { gint16 i
; } gint16_struct
;
39 typedef struct { gint32 i
; } gint32_struct
;
40 typedef struct { gint64 i
; } gint64_struct
;
41 typedef struct { float i
; } float_struct
;
42 typedef struct { double i
; } double_struct
;
43 typedef struct { gpointer i
; } gpointer_struct
;
49 #if defined (TARGET_X86)
50 g_print ("#ifdef TARGET_X86\n");
51 #elif defined (TARGET_AMD64)
52 g_print ("#ifdef TARGET_AMD64\n");
53 #elif defined (TARGET_ARM)
54 g_print ("#ifdef TARGET_ARM\n");
55 #elif defined (TARGET_ARM64)
56 g_print ("#ifdef TARGET_ARM64\n");
57 #elif defined (TARGET_RISCV32)
58 g_print ("#ifdef TARGET_RISCV32\n");
59 #elif defined (TARGET_RISCV64)
60 g_print ("#ifdef TARGET_RISCV64\n");
70 #if defined (HOST_WIN32)
71 g_print ("#ifdef TARGET_WIN32\n");
72 #elif defined (HOST_ANDROID)
73 g_print ("#ifdef TARGET_ANDROID\n");
74 #elif defined (HOST_DARWIN)
75 g_print ("#ifdef TARGET_OSX\n");
76 #elif defined (PLATFORM_IOS)
77 g_print ("#ifdef TARGET_IOS\n");
85 mono_dump_metadata_offsets (void);
88 mono_dump_metadata_offsets (void)
90 #ifdef USED_CROSS_COMPILER_OFFSETS
91 g_print ("not using native offsets\n");
93 g_print ("#ifndef USED_CROSS_COMPILER_OFFSETS\n");
96 g_print ("#error failed to figure out the current arch\n");
101 g_print ("#error failed to figure out the current OS\n");
106 g_print ("#ifndef HAVE_BOEHM_GC\n");
108 g_print ("#ifndef HAVE_SGEN_GC\n");
110 g_print ("#error no gc conf not supported\n");
114 g_print ("#define HAS_CROSS_COMPILER_OFFSETS\n");
115 g_print ("#if defined (USE_CROSS_COMPILE_OFFSETS) || defined (MONO_CROSS_COMPILE)\n");
116 g_print ("#if !defined (DISABLE_METADATA_OFFSETS)\n");
117 g_print ("#define USED_CROSS_COMPILER_OFFSETS\n");
119 #define DISABLE_JIT_OFFSETS
120 #define DECL_OFFSET2(struct,field,offset) this_should_not_happen
121 #define DECL_ALIGN2(type,size) this_should_not_happen
123 #define DECL_OFFSET(struct,field) g_print ("DECL_OFFSET2(%s,%s,%d)\n", #struct, #field, (int)MONO_STRUCT_OFFSET (struct, field));
124 #define DECL_ALIGN(type) g_print ("DECL_ALIGN2(%s,%d)\n", #type, (int)MONO_ABI_ALIGNOF (type));
125 #define DECL_SIZE(type) g_print ("DECL_SIZE2(%s,%d)\n", #type, (int)MONO_ABI_SIZEOF (type));
126 #include <mono/metadata/object-offsets.h>
128 g_print ("#endif //disable metadata check\n");
129 g_print ("#endif //gc check\n");
134 mono_metadata_cross_helpers_run (void);
137 * mono_metadata_cross_helpers_run:
139 * Check that the offsets given by object-offsets.h match the offsets
140 * on the host. This only checks the metadata offsets.
143 mono_metadata_cross_helpers_run (void)
145 #if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE)
146 gboolean is_broken
= FALSE
;
148 #define DISABLE_JIT_OFFSETS
149 #define USE_CROSS_COMPILE_OFFSETS
150 #define DECL_OFFSET(struct,field) this_should_not_happen_for_cross_fields
151 #define DECL_OFFSET2(struct,field,offset) \
152 if ((int)G_STRUCT_OFFSET (struct, field) != offset) { \
153 g_print (#struct ":" #field " invalid struct offset %d (expected %d)\n", \
155 (int)G_STRUCT_OFFSET (struct, field)); \
158 #define DECL_ALIGN(type) this_should_not_happen_for_cross_align
159 #define DECL_ALIGN2(name,size) \
160 if (MONO_ALIGN_ ## name != size) { \
161 g_print (#name ": invalid alignment %d (expected %d)\n", \
163 MONO_ALIGN_ ## name); \
166 #define DECL_SIZE(type) this_should_not_happen_for_cross_size
167 #define DECL_SIZE2(name,size) \
168 if (MONO_SIZEOF_ ## name != size) { \
169 g_print (#name ": invalid size %d (expected %d)\n", \
171 MONO_SIZEOF_ ## name); \
175 #include <mono/metadata/object-offsets.h>
177 g_assert (!is_broken
);