Implemeneted imprecise.
[mono-project.git] / mono / metadata / metadata-cross-helpers.c
blob566eb2bffbce44fd2d50abdd227bd70d46ab631b
1 /**
2 * \file
3 */
5 #include <stdio.h>
7 #include "config.h"
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>
15 #ifdef HAVE_SGEN_GC
16 #include <mono/sgen/sgen-gc.h>
17 #endif
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
24 #endif
26 #ifdef MONO_GENERATING_OFFSETS
27 /* The offsets tool uses this structure to compute basic type sizes/alignment */
28 struct basic_types_struct {
29 gint8 gint8_f;
30 gint16 gint16_f;
31 gint32 gint32_f;
32 gint64 gint64_f;
33 float float_f;
34 double double_f;
35 gpointer gpointer_f;
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;
44 #endif
46 static int
47 dump_arch (void)
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");
61 #else
62 return 0;
63 #endif
64 return 1;
67 static int
68 dump_os (void)
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");
78 #else
79 return 0;
80 #endif
81 return 1;
84 void
85 mono_dump_metadata_offsets (void);
87 void
88 mono_dump_metadata_offsets (void)
90 #ifdef USED_CROSS_COMPILER_OFFSETS
91 g_print ("not using native offsets\n");
92 #else
93 g_print ("#ifndef USED_CROSS_COMPILER_OFFSETS\n");
95 if (!dump_arch ()) {
96 g_print ("#error failed to figure out the current arch\n");
97 return;
100 if (!dump_os ()) {
101 g_print ("#error failed to figure out the current OS\n");
102 return;
105 #ifdef HAVE_SGEN_GC
106 g_print ("#ifndef HAVE_BOEHM_GC\n");
107 #elif HAVE_BOEHM_GC
108 g_print ("#ifndef HAVE_SGEN_GC\n");
109 #else
110 g_print ("#error no gc conf not supported\n");
111 return;
112 #endif
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");
130 #endif
133 void
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.
142 void
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", \
154 offset, \
155 (int)G_STRUCT_OFFSET (struct, field)); \
156 is_broken = TRUE; \
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", \
162 size, \
163 MONO_ALIGN_ ## name); \
164 is_broken = TRUE; \
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", \
170 size, \
171 MONO_SIZEOF_ ## name); \
172 is_broken = TRUE; \
175 #include <mono/metadata/object-offsets.h>
177 g_assert (!is_broken);
178 #endif