Skip to content

Commit

Permalink
[aot] Fix a deadlock in init_plt () by calling create_trampoline () o…
Browse files Browse the repository at this point in the history
…utside the lock.

Fixes mono#15330.
  • Loading branch information
vargaz authored and marek-safar committed Jun 24, 2019
1 parent 3b576e5 commit d0294cf
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4263,10 +4263,10 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM
}
}

amodule_lock (amodule);

init_plt (amodule);

amodule_lock (amodule);

mono_atomic_inc_i32 (&mono_jit_stats.methods_aot);

if (method && method->wrapper_type)
Expand Down Expand Up @@ -5155,7 +5155,6 @@ mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code
*
* Initialize the PLT table of the AOT module. Called lazily when the first AOT
* method in the module is loaded to avoid committing memory by writing to it.
* LOCKING: Assumes the AMODULE lock is held.
*/
static void
init_plt (MonoAotModule *amodule)
Expand All @@ -5166,23 +5165,34 @@ init_plt (MonoAotModule *amodule)
if (amodule->plt_inited)
return;

tramp = mono_create_specific_trampoline (amodule, MONO_TRAMPOLINE_AOT_PLT, mono_get_root_domain (), NULL);
tramp = mono_create_ftnptr (mono_domain_get (), tramp);

amodule_lock (amodule);

if (amodule->plt_inited) {
amodule_unlock (amodule);
return;
}

if (amodule->info.plt_size <= 1) {
amodule->plt_inited = TRUE;
amodule_unlock (amodule);
return;
}

tramp = mono_create_specific_trampoline (amodule, MONO_TRAMPOLINE_AOT_PLT, mono_get_root_domain (), NULL);

/*
* Initialize the PLT entries in the GOT to point to the default targets.
*/
for (i = 1; i < amodule->info.plt_size; ++i)
/* All the default entries point to the AOT trampoline */
((gpointer*)amodule->got)[amodule->info.plt_got_offset_base + i] = tramp;

tramp = mono_create_ftnptr (mono_domain_get (), tramp);
for (i = 1; i < amodule->info.plt_size; ++i)
/* All the default entries point to the AOT trampoline */
((gpointer*)amodule->got)[amodule->info.plt_got_offset_base + i] = tramp;
mono_memory_barrier ();

amodule->plt_inited = TRUE;

amodule_unlock (amodule);
}

/*
Expand Down

0 comments on commit d0294cf

Please sign in to comment.