From 7ab68ad32f9153a06ee505d041b8b9cae12fbbc6 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sun, 4 Jan 2015 04:43:06 -0500 Subject: [PATCH] [aot] Get rid of the code offsets code since direct method addresses are used on all supported platforms. --- mono/mini/aot-compiler.c | 91 +++++++++++++----------------------------------- mono/mini/aot-runtime.c | 40 +++++++-------------- mono/mini/mini.h | 4 +-- 3 files changed, 38 insertions(+), 97 deletions(-) diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index 2aa700a336a..881d1651c43 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -220,7 +220,6 @@ typedef struct MonoAotCompile { GHashTable *ginst_hash; GHashTable *dwarf_ln_filenames; gboolean global_symbols; - gboolean direct_method_addresses; int objc_selector_index, objc_selector_index_2; GPtrArray *objc_selectors; GHashTable *objc_selector_to_index; @@ -712,14 +711,12 @@ arch_init (MonoAotCompile *acfg) #if defined(TARGET_X86) g_string_append (acfg->llc_args, " -march=x86 -mattr=sse4.1"); - acfg->direct_method_addresses = TRUE; #endif #if defined(TARGET_AMD64) g_string_append (acfg->llc_args, " -march=x86-64 -mattr=sse4.1"); /* NOP */ acfg->align_pad_value = 0x90; - acfg->direct_method_addresses = TRUE; #endif #ifdef TARGET_ARM @@ -759,7 +756,6 @@ arch_init (MonoAotCompile *acfg) #endif #ifdef MONOTOUCH - acfg->direct_method_addresses = TRUE; acfg->global_symbols = TRUE; #endif } @@ -7302,58 +7298,32 @@ emit_code (MonoAotCompile *acfg) } } - if (acfg->direct_method_addresses) { - acfg->flags |= MONO_AOT_FILE_FLAG_DIRECT_METHOD_ADDRESSES; - - /* - * To work around linker issues, we emit a table of branches, and disassemble them at runtime. - * This is PIE code, and the linker can update it if needed. - */ - sprintf (symbol, "method_addresses"); - emit_section_change (acfg, ".text", 1); - emit_alignment_code (acfg, 8); - emit_label (acfg, symbol); - emit_local_symbol (acfg, symbol, "method_addresses_end", TRUE); - emit_unset_mode (acfg); - if (acfg->need_no_dead_strip) - fprintf (acfg->fp, " .no_dead_strip %s\n", symbol); + /* + * To work around linker issues, we emit a table of branches, and disassemble them at runtime. + * This is PIE code, and the linker can update it if needed. + */ + sprintf (symbol, "method_addresses"); + emit_section_change (acfg, ".text", 1); + emit_alignment_code (acfg, 8); + emit_label (acfg, symbol); + emit_local_symbol (acfg, symbol, "method_addresses_end", TRUE); + emit_unset_mode (acfg); + if (acfg->need_no_dead_strip) + fprintf (acfg->fp, " .no_dead_strip %s\n", symbol); - for (i = 0; i < acfg->nmethods; ++i) { + for (i = 0; i < acfg->nmethods; ++i) { #ifdef MONO_ARCH_AOT_SUPPORTED - int call_size; + int call_size; - if (acfg->cfgs [i]) - arch_emit_direct_call (acfg, acfg->cfgs [i]->asm_symbol, FALSE, acfg->thumb_mixed && acfg->cfgs [i]->compile_llvm, NULL, &call_size); - else - arch_emit_direct_call (acfg, "method_addresses", FALSE, FALSE, NULL, &call_size); + if (acfg->cfgs [i]) + arch_emit_direct_call (acfg, acfg->cfgs [i]->asm_symbol, FALSE, acfg->thumb_mixed && acfg->cfgs [i]->compile_llvm, NULL, &call_size); + else + arch_emit_direct_call (acfg, "method_addresses", FALSE, FALSE, NULL, &call_size); #endif - } - - sprintf (symbol, "method_addresses_end"); - emit_label (acfg, symbol); - - /* Empty */ - sprintf (symbol, "code_offsets"); - emit_section_change (acfg, RODATA_SECT, 1); - emit_alignment (acfg, 8); - emit_label (acfg, symbol); - emit_int32 (acfg, 0); - } else { - sprintf (symbol, "code_offsets"); - emit_section_change (acfg, RODATA_SECT, 1); - emit_alignment (acfg, 8); - emit_label (acfg, symbol); - - acfg->stats.offsets_size += acfg->nmethods * 4; - - for (i = 0; i < acfg->nmethods; ++i) { - if (acfg->cfgs [i]) { - emit_symbol_diff (acfg, acfg->cfgs [i]->asm_symbol, acfg->methods_symbol, 0); - } else { - emit_int32 (acfg, 0xffffffff); - } - } } + + sprintf (symbol, "method_addresses_end"); + emit_label (acfg, symbol); emit_line (acfg); /* Emit a sorted table mapping methods to the index of their unbox trampolines */ @@ -7389,10 +7359,7 @@ emit_code (MonoAotCompile *acfg) /* Emit a separate table with the trampoline addresses/offsets */ sprintf (symbol, "unbox_trampoline_addresses"); - if (acfg->direct_method_addresses) - emit_section_change (acfg, ".text", 0); - else - emit_section_change (acfg, RODATA_SECT, 0); + emit_section_change (acfg, ".text", 0); emit_alignment_code (acfg, 8); emit_label (acfg, symbol); @@ -7410,18 +7377,12 @@ emit_code (MonoAotCompile *acfg) if (acfg->aot_opts.full_aot && cfg->orig_method->klass->valuetype) { #ifdef MONO_ARCH_AOT_SUPPORTED int call_size; -#endif index = get_method_index (acfg, method); sprintf (symbol, "ut_%d", index); - if (acfg->direct_method_addresses) { -#ifdef MONO_ARCH_AOT_SUPPORTED - arch_emit_direct_call (acfg, symbol, FALSE, acfg->thumb_mixed && cfg->compile_llvm, NULL, &call_size); + arch_emit_direct_call (acfg, symbol, FALSE, acfg->thumb_mixed && cfg->compile_llvm, NULL, &call_size); #endif - } else { - emit_symbol_diff (acfg, symbol, acfg->methods_symbol, 0); - } } } } @@ -8268,11 +8229,7 @@ emit_file_info (MonoAotCompile *acfg) emit_pointer (acfg, "class_info_offsets"); emit_pointer (acfg, "method_info_offsets"); emit_pointer (acfg, "ex_info_offsets"); - emit_pointer (acfg, "code_offsets"); - if (acfg->direct_method_addresses) - emit_pointer (acfg, "method_addresses"); - else - emit_pointer (acfg, NULL); + emit_pointer (acfg, "method_addresses"); emit_pointer (acfg, "extra_method_info_offsets"); emit_pointer (acfg, "extra_method_table"); emit_pointer (acfg, "got_info_offsets"); diff --git a/mono/mini/aot-runtime.c b/mono/mini/aot-runtime.c index 69da27bf958..43c11098866 100644 --- a/mono/mini/aot-runtime.c +++ b/mono/mini/aot-runtime.c @@ -1941,7 +1941,6 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data) } } - amodule->code_offsets = info->code_offsets; amodule->method_addresses = info->method_addresses; amodule->code = info->methods; #ifdef TARGET_ARM @@ -1971,20 +1970,18 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data) amodule->trampolines [MONO_AOT_TRAMP_GSHAREDVT_ARG] = info->gsharedvt_arg_trampolines; amodule->thumb_end = info->thumb_end; - if (info->flags & MONO_AOT_FILE_FLAG_DIRECT_METHOD_ADDRESSES) { - /* Compute code_offsets from the method addresses */ - amodule->code_offsets = g_malloc0 (amodule->info.nmethods * sizeof (gint32)); - for (i = 0; i < amodule->info.nmethods; ++i) { - /* method_addresses () contains a table of branches, since the ios linker can update those correctly */ - void *addr; - - addr = get_call_table_entry (amodule->method_addresses, i); - g_assert (addr); - if (addr == amodule->method_addresses) - amodule->code_offsets [i] = 0xffffffff; - else - amodule->code_offsets [i] = (char*)addr - (char*)amodule->code; - } + /* Compute code_offsets from the method addresses */ + amodule->code_offsets = g_malloc0 (amodule->info.nmethods * sizeof (gint32)); + for (i = 0; i < amodule->info.nmethods; ++i) { + /* method_addresses () contains a table of branches, since the ios linker can update those correctly */ + void *addr; + + addr = get_call_table_entry (amodule->method_addresses, i); + g_assert (addr); + if (addr == amodule->method_addresses) + amodule->code_offsets [i] = 0xffffffff; + else + amodule->code_offsets [i] = (char*)addr - (char*)amodule->code; } if (make_unreadable) { @@ -3505,12 +3502,6 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM info = &amodule->blob [mono_aot_get_offset (amodule->method_info_offsets, method_index)]; - if (amodule->thumb_end && code < amodule->thumb_end && ((amodule->info.flags & MONO_AOT_FILE_FLAG_DIRECT_METHOD_ADDRESSES) == 0)) { - /* Convert this into a thumb address */ - g_assert ((amodule->code_offsets [method_index] & 0x1) == 0); - code = &amodule->code [amodule->code_offsets [method_index] + 1]; - } - if (!amodule->methods_loaded) { amodule_lock (amodule); if (!amodule->methods_loaded) { @@ -4787,7 +4778,6 @@ mono_aot_get_unbox_trampoline (MonoMethod *method) gpointer code; guint32 *ut, *ut_end, *entry; int low, high, entry_index; - guint8 *addresses; if (method->is_inflated && !mono_method_is_generic_sharable_full (method, FALSE, FALSE, FALSE)) { method_index = find_extra_method (method, &amodule); @@ -4820,11 +4810,7 @@ mono_aot_get_unbox_trampoline (MonoMethod *method) } } - addresses = (guint8*)amodule->unbox_trampoline_addresses; - if (amodule->info.flags & MONO_AOT_FILE_FLAG_DIRECT_METHOD_ADDRESSES) - code = get_call_table_entry (addresses, entry_index); - else - code = amodule->code + ((guint32*)addresses) [entry_index]; + code = get_call_table_entry (amodule->unbox_trampoline_addresses, entry_index); g_assert (code); /* The caller expects an ftnptr */ diff --git a/mono/mini/mini.h b/mono/mini/mini.h index afec20263da..b2412fb1c0f 100755 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -103,7 +103,7 @@ #endif /* Version number of the AOT file format */ -#define MONO_AOT_FILE_VERSION 105 +#define MONO_AOT_FILE_VERSION 106 //TODO: This is x86/amd64 specific. #define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6)) @@ -164,7 +164,6 @@ typedef enum { MONO_AOT_FILE_FLAG_WITH_LLVM = 1, MONO_AOT_FILE_FLAG_FULL_AOT = 2, MONO_AOT_FILE_FLAG_DEBUG = 4, - MONO_AOT_FILE_FLAG_DIRECT_METHOD_ADDRESSES = 8 } MonoAotFileFlags; /* This structure is stored in the AOT file */ @@ -189,7 +188,6 @@ typedef struct MonoAotFileInfo gpointer class_info_offsets; gpointer method_info_offsets; gpointer ex_info_offsets; - gpointer code_offsets; gpointer method_addresses; gpointer extra_method_info_offsets; gpointer extra_method_table; -- 2.11.4.GIT