Skip to content

Commit

Permalink
[WIP] LLVM changes
Browse files Browse the repository at this point in the history
<!--
Thank you for your Pull Request!

If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed.

Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number
-->
  • Loading branch information
vargaz committed Mar 24, 2020
1 parent 4464edd commit 1546f8b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 86 deletions.
6 changes: 4 additions & 2 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -11303,6 +11303,7 @@ init_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
info->plt_got_offset_base = acfg->plt_got_offset_base;
info->plt_got_info_offset_base = acfg->plt_got_info_offset_base;
info->got_size = acfg->got_offset * sizeof (target_mgreg_t);
info->llvm_got_size = acfg->llvm_got_offset * sizeof (target_mgreg_t);
info->plt_size = acfg->plt_offset;
info->nmethods = acfg->nmethods;
info->call_table_entry_size = acfg->call_table_entry_size;
Expand Down Expand Up @@ -11356,16 +11357,16 @@ emit_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
sindex = 0;
symbols [sindex ++] = acfg->got_symbol;
if (acfg->llvm) {
symbols [sindex ++] = g_strdup_printf ("%s%s", acfg->user_symbol_prefix, acfg->llvm_got_symbol);
symbols [sindex ++] = acfg->llvm_eh_frame_symbol;
} else {
symbols [sindex ++] = NULL;
symbols [sindex ++] = NULL;
}
/* llvm_get_method */
symbols [sindex ++] = NULL;
/* llvm_get_unbox_tramp */
symbols [sindex ++] = NULL;
/* llvm_init_aotconst */
symbols [sindex ++] = NULL;
if (!acfg->aot_opts.llvm_only) {
symbols [sindex ++] = "jit_code_start";
symbols [sindex ++] = "jit_code_end";
Expand Down Expand Up @@ -11460,6 +11461,7 @@ emit_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
emit_int32 (acfg, info->plt_got_offset_base);
emit_int32 (acfg, info->plt_got_info_offset_base);
emit_int32 (acfg, info->got_size);
emit_int32 (acfg, info->llvm_got_size);
emit_int32 (acfg, info->plt_size);
emit_int32 (acfg, info->nmethods);
emit_int32 (acfg, info->nextra_methods);
Expand Down
17 changes: 14 additions & 3 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2078,9 +2078,12 @@ init_amodule_got (MonoAotModule *amodule, gboolean preinit)
for (i = 0; i < npatches; ++i)
amodule->got [i] = amodule->shared_got [i];
}
if (amodule->llvm_got) {
for (i = 0; i < npatches; ++i)
if (amodule->info.flags & MONO_AOT_FILE_FLAG_WITH_LLVM) {
void (*init_aotconst) (int, gpointer) = (void (*)(int, gpointer))amodule->info.llvm_init_aotconst;
for (i = 0; i < npatches; ++i) {
amodule->llvm_got [i] = amodule->shared_got [i];
init_aotconst (i, amodule->llvm_got [i]);
}
}

mono_mempool_destroy (mp);
Expand Down Expand Up @@ -2299,7 +2302,10 @@ load_aot_module (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, gpointer
memcpy (&amodule->info, info, sizeof (*info));

amodule->got = (void **)amodule->info.jit_got;
amodule->llvm_got = (void **)amodule->info.llvm_got;
/*
* The llvm code keeps its data in separate scalar variables, so this just used by this module.
*/
amodule->llvm_got = g_malloc0 (sizeof (gpointer) * amodule->info.llvm_got_size);
amodule->globals = globals;
amodule->sofile = sofile;
amodule->method_to_code = g_hash_table_new (mono_aligned_addr_hash, NULL);
Expand Down Expand Up @@ -4704,6 +4710,11 @@ init_method (MonoAotModule *amodule, guint32 method_index, MonoMethod *method, M
got [got_slots [pindex]] = addr;
if (ji->type == MONO_PATCH_INFO_METHOD_JUMP)
register_jump_target_got_slot (domain, ji->data.method, &(got [got_slots [pindex]]));

if (llvm) {
void (*init_aotconst) (int, gpointer) = (void (*)(int, gpointer))amodule->info.llvm_init_aotconst;
init_aotconst (got_slots [pindex], addr);
}
}
ji->type = MONO_PATCH_INFO_NONE;
}
Expand Down
8 changes: 5 additions & 3 deletions src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "mini.h"

/* Version number of the AOT file format */
#define MONO_AOT_FILE_VERSION 175
#define MONO_AOT_FILE_VERSION 176

#define MONO_AOT_TRAMP_PAGE_SIZE 16384

Expand Down Expand Up @@ -113,14 +113,14 @@ typedef struct MonoAotFileInfo
#define MONO_AOT_FILE_INFO_FIRST_SYMBOL jit_got
/* Global Offset Table for JITted code */
gpointer jit_got;
/* Global Offset Table for LLVM code */
gpointer llvm_got;
/* Mono EH Frame created by llc when using LLVM */
gpointer mono_eh_frame;
/* Points to the get_method () function in the LLVM image or NULL */
gpointer llvm_get_method;
/* Points to the get_unbox_tramp () function in the LLVM image or NULL */
gpointer llvm_get_unbox_tramp;
/* Points to the init_aotconst () function in the LLVM image or NULL */
gpointer llvm_init_aotconst;
gpointer jit_code_start;
gpointer jit_code_end;
gpointer method_addresses;
Expand Down Expand Up @@ -184,6 +184,8 @@ typedef struct MonoAotFileInfo
guint32 plt_got_info_offset_base;
/* Number of entries in the GOT */
guint32 got_size;
/* Number of entries in the LLVM GOT */
guint32 llvm_got_size;
/* Number of entries in the PLT */
guint32 plt_size;
/* Number of methods */
Expand Down
Loading

0 comments on commit 1546f8b

Please sign in to comment.