Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[runtime] Add cross helpers that both check offsets and produce headers.
List of original contributors: Rodrigo Kumpera <kumpera@gmail.com> Zoltan Varga <vargaz@gmail.com>
- Loading branch information
Showing
2 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,137 @@ | ||
#include <stdio.h> | ||
|
||
#include "config.h" | ||
#include <mono/metadata/abi-details.h> | ||
|
||
#include <mono/metadata/class-internals.h> | ||
#include <mono/metadata/object-internals.h> | ||
#include <mono/metadata/monitor.h> | ||
#ifdef HAVE_SGEN_GC | ||
#include <mono/sgen/sgen-gc.h> | ||
#endif | ||
|
||
static int | ||
dump_arch (void) | ||
{ | ||
#if defined (TARGET_X86) | ||
g_print ("#ifdef TARGET_X86\n"); | ||
#elif defined (TARGET_AMD64) | ||
g_print ("#ifdef TARGET_AMD64\n"); | ||
#elif defined (TARGET_ARM) | ||
g_print ("#ifdef TARGET_ARM\n"); | ||
#elif defined (TARGET_ARM64) | ||
g_print ("#ifdef TARGET_ARM64\n"); | ||
#else | ||
return 0; | ||
#endif | ||
return 1; | ||
} | ||
|
||
static int | ||
dump_os (void) | ||
{ | ||
#if defined (PLATFORM_WIN32) | ||
g_print ("#ifdef TARGET_WIN32\n"); | ||
#elif defined (PLATFORM_ANDROID) | ||
g_print ("#ifdef TARGET_ANDROID\n"); | ||
#elif defined (PLATFORM_MACOSX) | ||
g_print ("#ifdef TARGET_OSX\n"); | ||
#elif defined (PLATFORM_IOS) | ||
g_print ("#ifdef TARGET_IOS\n"); | ||
#else | ||
return 0; | ||
#endif | ||
return 1; | ||
} | ||
|
||
void | ||
mono_dump_metadata_offsets (void); | ||
|
||
void | ||
mono_dump_metadata_offsets (void) | ||
{ | ||
#ifdef USED_CROSS_COMPILER_OFFSETS | ||
g_print ("not using native offsets\n"); | ||
#else | ||
g_print ("#ifndef USED_CROSS_COMPILER_OFFSETS\n"); | ||
|
||
if (!dump_arch ()) { | ||
g_print ("#error failed to figure out the current arch\n"); | ||
return; | ||
} | ||
|
||
if (!dump_os ()) { | ||
g_print ("#error failed to figure out the current OS\n"); | ||
return; | ||
} | ||
|
||
#ifdef HAVE_SGEN_GC | ||
g_print ("#ifndef HAVE_BOEHM_GC\n"); | ||
#elif HAVE_BOEHM_GC | ||
g_print ("#ifndef HAVE_SGEN_GC\n"); | ||
#else | ||
g_print ("#error no gc conf not supported\n"); | ||
return; | ||
#endif | ||
|
||
g_print ("#define HAS_CROSS_COMPILER_OFFSETS\n"); | ||
g_print ("#if defined (USE_CROSS_COMPILE_OFFSETS) || defined (MONO_CROSS_COMPILE)\n"); | ||
g_print ("#if !defined (DISABLE_METADATA_OFFSETS)\n"); | ||
g_print ("#define USED_CROSS_COMPILER_OFFSETS\n"); | ||
|
||
#define DISABLE_JIT_OFFSETS | ||
#define DECL_OFFSET2(struct,field,offset) this_should_not_happen | ||
#define DECL_ALIGN2(type,size) this_should_not_happen | ||
|
||
#define DECL_OFFSET(struct,field) g_print ("DECL_OFFSET2(%s,%s,%d)\n", #struct, #field, (int)MONO_STRUCT_OFFSET (struct, field)); | ||
#define DECL_ALIGN(type) g_print ("DECL_ALIGN2(%s,%d)\n", #type, (int)MONO_ABI_ALIGNOF (type)); | ||
#define DECL_SIZE(type) g_print ("DECL_SIZE2(%s,%d)\n", #type, (int)MONO_ABI_SIZEOF (type)); | ||
#include <mono/metadata/object-offsets.h> | ||
|
||
g_print ("#endif //disable metadata check\n"); | ||
g_print ("#endif //gc check\n"); | ||
#endif | ||
} | ||
|
||
void | ||
mono_metadata_cross_helpers_run (void); | ||
|
||
void | ||
mono_metadata_cross_helpers_run (void) | ||
{ | ||
#if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE) | ||
gboolean is_broken = FALSE; | ||
|
||
#define DISABLE_JIT_OFFSETS | ||
#define USE_CROSS_COMPILE_OFFSETS | ||
#define DECL_OFFSET(struct,field) this_should_not_happen_for_cross_fields | ||
#define DECL_OFFSET2(struct,field,offset) \ | ||
if ((int)G_STRUCT_OFFSET (struct, field) != offset) { \ | ||
g_print (#struct ":" #field " invalid struct offset %d (expected %d)\n", \ | ||
offset, \ | ||
(int)G_STRUCT_OFFSET (struct, field)); \ | ||
is_broken = TRUE; \ | ||
} | ||
#define DECL_ALIGN(type) this_should_not_happen_for_cross_align | ||
#define DECL_ALIGN2(name,size) \ | ||
if (MONO_ALIGN_ ## name != size) { \ | ||
g_print (#name ": invalid alignment %d (expected %d)\n", \ | ||
size, \ | ||
MONO_ALIGN_ ## name); \ | ||
is_broken = TRUE; \ | ||
} | ||
#define DECL_SIZE(type) this_should_not_happen_for_cross_size | ||
#define DECL_SIZE2(name,size) \ | ||
if (MONO_SIZEOF_ ## name != size) { \ | ||
g_print (#name ": invalid size %d (expected %d)\n", \ | ||
size, \ | ||
MONO_SIZEOF_ ## name); \ | ||
is_broken = TRUE; \ | ||
} | ||
|
||
#include <mono/metadata/object-offsets.h> | ||
|
||
#ifdef ENABLE_EXTENSION_MODULE | ||
#include "../../../mono-extensions/mono/metadata/metadata-cross-helpers.c" | ||
g_assert (!is_broken); | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,93 @@ | ||
#include "config.h" | ||
|
||
#ifdef ENABLE_EXTENSION_MODULE | ||
#include "../../../mono-extensions/mono/mini/mini-cross-helpers.c" | ||
#include <stdio.h> | ||
|
||
#include "config.h" | ||
|
||
#include "mini.h" | ||
#include "tasklets.h" | ||
#include <mono/metadata/abi-details.h> | ||
|
||
void | ||
mono_dump_metadata_offsets (void); | ||
|
||
void | ||
mono_metadata_cross_helpers_run (void); | ||
|
||
|
||
static void | ||
mono_dump_jit_offsets (void) | ||
{ | ||
#ifdef USED_CROSS_COMPILER_OFFSETS | ||
g_print ("#error not using native offsets\n"); | ||
#else | ||
mono_dump_metadata_offsets (); | ||
|
||
g_print ("#ifndef DISABLE_JIT_OFFSETS\n"); | ||
g_print ("#define USED_CROSS_COMPILER_OFFSETS\n"); | ||
#define DISABLE_METADATA_OFFSETS | ||
#define DECL_OFFSET2(struct,field,offset) this_should_not_happen | ||
#define DECL_ALIGN2(type,size) this_should_not_happen | ||
|
||
void mono_cross_helpers_run (void); | ||
#define DECL_OFFSET(struct,field) g_print ("DECL_OFFSET2(%s,%s,%d)\n", #struct, #field, (int)MONO_STRUCT_OFFSET (struct, field)); | ||
#define DECL_ALIGN(type) | ||
#define DECL_SIZE2(type,size) this_should_not_happen | ||
#define DECL_SIZE(type) | ||
#include <mono/metadata/object-offsets.h> | ||
|
||
g_print ("#endif //disable jit check\n"); | ||
g_print ("#endif //cross compiler checks\n"); | ||
g_print ("#endif //gc check\n"); | ||
g_print ("#endif //os check\n"); | ||
g_print ("#endif //arch check\n"); | ||
g_print ("#endif //USED_CROSS_COMPILER_OFFSETS check\n"); | ||
#endif | ||
} | ||
|
||
void | ||
mono_cross_helpers_run (void) | ||
{ | ||
} | ||
#if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE) | ||
gboolean is_broken = FALSE; | ||
#endif | ||
|
||
#ifndef USED_CROSS_COMPILER_OFFSETS | ||
if (g_getenv ("DUMP_CROSS_OFFSETS")) | ||
mono_dump_jit_offsets (); | ||
#endif | ||
|
||
#if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE) | ||
mono_metadata_cross_helpers_run (); | ||
|
||
#define DISABLE_METADATA_OFFSETS | ||
#define USE_CROSS_COMPILE_OFFSETS | ||
#define DECL_OFFSET(struct,field) this_should_not_happen_for_cross_fields | ||
#define DECL_OFFSET2(struct,field,offset) \ | ||
if ((int)G_STRUCT_OFFSET (struct, field) != offset) { \ | ||
g_print (#struct ":" #field " invalid struct offset %d (expected %d)\n", \ | ||
offset, \ | ||
(int)G_STRUCT_OFFSET (struct, field)); \ | ||
is_broken = TRUE; \ | ||
} | ||
#define DECL_ALIGN(name,type) this_should_not_happen_for_cross_align | ||
#define DECL_ALIGN2(name,size) \ | ||
if (MONO_ALIGN_ ## name != size) { \ | ||
g_print (#name ": invalid alignment %d (expected %d)\n", \ | ||
size, \ | ||
MONO_ALIGN_ ## name); \ | ||
is_broken = TRUE; \ | ||
} | ||
#define DECL_SIZE(type) this_should_not_happen_for_cross_size | ||
#define DECL_SIZE2(name,size) \ | ||
if (MONO_SIZEOF_ ## name != size) { \ | ||
g_print (#name ": invalid size %d (expected %d)\n", \ | ||
size, \ | ||
MONO_SIZEOF_ ## name); \ | ||
is_broken = TRUE; \ | ||
} | ||
|
||
#include <mono/metadata/object-offsets.h> | ||
|
||
g_assert (!is_broken); | ||
#endif | ||
} |