Skip to content

Commit

Permalink
Move unbox tramp method address table to data segment, MONO_ARCH_CODE…
Browse files Browse the repository at this point in the history
…_EXEC_ONLY. (dotnet#33969)

unbox tramp method addresses are emitted as a table of calls and read at runtime by get_call_table_entry. This is problematic on platforms that doesn't allow data to be read from instruction stream.

Fix follow same pattern as method address table emitted as function pointers into table in data segment when using MONO_ARCH_CODE_EXEC_ONLY.

Co-authored-by: lateralusX <[email protected]>
  • Loading branch information
monojenkins and lateralusX authored Mar 24, 2020
1 parent c67efd8 commit b159b37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -10318,7 +10318,12 @@ emit_code (MonoAotCompile *acfg)

/* Emit a separate table with the trampoline addresses/offsets */
sprintf (symbol, "unbox_trampoline_addresses");
emit_section_change (acfg, ".text", 0);
if (acfg->flags & MONO_AOT_FILE_FLAG_CODE_EXEC_ONLY) {
/* Emit the unbox trampoline address table as a table of pointers */
emit_section_change (acfg, ".data", 0);
} else {
emit_section_change (acfg, ".text", 0);
}
emit_alignment_code (acfg, 8);
emit_info_symbol (acfg, symbol, TRUE);

Expand All @@ -10335,12 +10340,15 @@ emit_code (MonoAotCompile *acfg)

if (mono_aot_mode_is_full (&acfg->aot_opts) && m_class_is_valuetype (cfg->orig_method->klass)) {
#ifdef MONO_ARCH_AOT_SUPPORTED
int call_size;

const int index = get_method_index (acfg, method);
sprintf (symbol, "ut_%d", index);

arch_emit_direct_call (acfg, symbol, FALSE, acfg->thumb_mixed && cfg->compile_llvm, NULL, &call_size);
if (acfg->flags & MONO_AOT_FILE_FLAG_CODE_EXEC_ONLY) {
emit_pointer (acfg, symbol);
} else {
int call_size;
arch_emit_direct_call (acfg, symbol, FALSE, acfg->thumb_mixed && cfg->compile_llvm, NULL, &call_size);
}
#endif
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -6077,7 +6077,11 @@ mono_aot_get_unbox_trampoline (MonoMethod *method, gpointer addr)
}
}

code = get_call_table_entry (amodule->unbox_trampoline_addresses, entry_index, amodule->info.call_table_entry_size);
if (amodule->info.flags & MONO_AOT_FILE_FLAG_CODE_EXEC_ONLY)
code = ((gpointer*)amodule->unbox_trampoline_addresses) [entry_index];
else
code = get_call_table_entry (amodule->unbox_trampoline_addresses, entry_index, amodule->info.call_table_entry_size);

g_assert (code);

tinfo = mono_tramp_info_create (NULL, (guint8 *)code, 0, NULL, NULL);
Expand Down

0 comments on commit b159b37

Please sign in to comment.