Skip to content

Commit

Permalink
[aot] Emit the weak field indexes table using the MONO_AOT_TABLE code…
Browse files Browse the repository at this point in the history
…, so it works with separate aot data fiels/bitcode. Fixes mono#6948
  • Loading branch information
vargaz committed Feb 13, 2018
1 parent 7a528f6 commit 91e2493
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
22 changes: 13 additions & 9 deletions mono/mini/aot-compiler.c
Expand Up @@ -9890,27 +9890,29 @@ emit_image_table (MonoAotCompile *acfg)
static void
emit_weak_field_indexes (MonoAotCompile *acfg)
{
char symbol [128];
GHashTable *indexes;
GHashTableIter iter;
gpointer key, value;
int buf_size;
guint8 *buf, *p;

/* Emit a table of weak field indexes, since computing these at runtime is expensive */
sprintf (symbol, "weak_field_indexes");
emit_section_change (acfg, ".text", 0);
emit_alignment_code (acfg, 8);
emit_info_symbol (acfg, symbol);

mono_assembly_init_weak_fields (acfg->image);
indexes = acfg->image->weak_field_indexes;
g_assert (indexes);

emit_int32 (acfg, g_hash_table_size (indexes));
buf_size = (g_hash_table_size (indexes) + 1) * 4;
buf = p = (guint8 *)g_malloc0 (buf_size);

encode_int (g_hash_table_size (indexes), p, &p);
g_hash_table_iter_init (&iter, indexes);
while (g_hash_table_iter_next (&iter, &key, &value)) {
guint32 index = GPOINTER_TO_UINT (key);
emit_int32 (acfg, index);
encode_int (index, p, &p);
}
g_assert (p - buf <= buf_size);

emit_aot_data (acfg, MONO_AOT_TABLE_WEAK_FIELD_INDEXES, "weak_field_indexes", buf, p - buf);
}

static void
Expand Down Expand Up @@ -10261,6 +10263,7 @@ emit_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
symbols [sindex ++] = NULL;
symbols [sindex ++] = NULL;
}

if (acfg->data_outfile) {
for (i = 0; i < MONO_AOT_TABLE_NUM; ++i)
symbols [sindex ++] = NULL;
Expand All @@ -10278,7 +10281,9 @@ emit_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
else
symbols [sindex ++] = NULL;
symbols [sindex ++] = "image_table";
symbols [sindex ++] = "weak_field_indexes";
}

symbols [sindex ++] = "mem_end";
symbols [sindex ++] = "assembly_guid";
symbols [sindex ++] = "runtime_version";
Expand Down Expand Up @@ -10311,7 +10316,6 @@ emit_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
symbols [sindex ++] = NULL;
symbols [sindex ++] = NULL;
}
symbols [sindex ++] = "weak_field_indexes";

g_assert (sindex == MONO_AOT_FILE_INFO_NUM_SYMBOLS);

Expand Down
6 changes: 5 additions & 1 deletion mono/mini/aot-runtime.c
Expand Up @@ -114,6 +114,7 @@ typedef struct MonoAotModule {
guint8 *plt;
guint8 *plt_end;
guint8 *blob;
gpointer weak_field_indexes;
/* Maps method indexes to their code */
gpointer *methods;
/* Sorted array of method addresses */
Expand Down Expand Up @@ -2191,6 +2192,7 @@ if (container_assm_name && !container_amodule) {
amodule->extra_method_info_offsets = amodule->tables [MONO_AOT_TABLE_EXTRA_METHOD_INFO_OFFSETS];
amodule->got_info_offsets = amodule->tables [MONO_AOT_TABLE_GOT_INFO_OFFSETS];
amodule->llvm_got_info_offsets = amodule->tables [MONO_AOT_TABLE_LLVM_GOT_INFO_OFFSETS];
amodule->weak_field_indexes = amodule->tables [MONO_AOT_TABLE_WEAK_FIELD_INDEXES];
} else {
amodule->blob = info->blob;
amodule->method_info_offsets = (guint32 *)info->method_info_offsets;
Expand All @@ -2201,6 +2203,8 @@ if (container_assm_name && !container_amodule) {
amodule->extra_method_info_offsets = (guint32 *)info->extra_method_info_offsets;
amodule->got_info_offsets = info->got_info_offsets;
amodule->llvm_got_info_offsets = info->llvm_got_info_offsets;
amodule->llvm_got_info_offsets = info->llvm_got_info_offsets;
amodule->weak_field_indexes = info->weak_field_indexes;
}
amodule->unbox_trampolines = (guint32 *)info->unbox_trampolines;
amodule->unbox_trampolines_end = (guint32 *)info->unbox_trampolines_end;
Expand Down Expand Up @@ -2636,7 +2640,7 @@ mono_aot_get_weak_field_indexes (MonoImage *image)
return NULL;

/* Initialize weak field indexes from the cached copy */
guint32 *indexes = amodule->info.weak_field_indexes;
guint32 *indexes = amodule->weak_field_indexes;
int len = indexes [0];
GHashTable *indexes_hash = g_hash_table_new (NULL, NULL);
for (int i = 0; i < len; ++i)
Expand Down
7 changes: 4 additions & 3 deletions mono/mini/aot-runtime.h
Expand Up @@ -82,6 +82,7 @@ typedef enum {
MONO_AOT_TABLE_LLVM_GOT_INFO_OFFSETS,
MONO_AOT_TABLE_EXTRA_METHOD_INFO_OFFSETS,
MONO_AOT_TABLE_EXTRA_METHOD_TABLE,
MONO_AOT_TABLE_WEAK_FIELD_INDEXES,
MONO_AOT_TABLE_NUM
} MonoAotFileTable;

Expand Down Expand Up @@ -120,6 +121,8 @@ typedef struct MonoAotFileInfo
gpointer got_info_offsets;
gpointer llvm_got_info_offsets;
gpointer image_table;
/* Points to an array of weak field indexes */
gpointer weak_field_indexes;
gpointer mem_end;
/* The GUID of the assembly which the AOT image was generated from */
gpointer assembly_guid;
Expand Down Expand Up @@ -148,9 +151,7 @@ typedef struct MonoAotFileInfo
gpointer unbox_trampolines_end;
/* Points to a table of unbox trampoline addresses/offsets */
gpointer unbox_trampoline_addresses;
/* Points to an array of weak field indexes */
gpointer weak_field_indexes;
#define MONO_AOT_FILE_INFO_LAST_SYMBOL weak_field_indexes
#define MONO_AOT_FILE_INFO_LAST_SYMBOL unbox_trampoline_addresses

/* Scalars */
/* The index of the first GOT slot used by the PLT */
Expand Down

0 comments on commit 91e2493

Please sign in to comment.