Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a thunk for calls from LLVM code to native functions on amd64, si…

…nce the call displacement might exceed 32 bits. Hopefully fixes #8502.
  • Loading branch information...
commit 81688d4189d955e49d77d0a945d3a60a9ee1c62e 1 parent 95f73a7
@vargaz vargaz authored
View
1  mono/mini/mini-amd64.h
@@ -387,6 +387,7 @@ typedef struct MonoCompileArch {
#define MONO_ARCH_GC_MAPS_SUPPORTED 1
#define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG 1
#define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1
+#define MONO_ARCH_HAVE_CREATE_LLVM_NATIVE_THUNK 1
gboolean
mono_amd64_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
View
22 mono/mini/mini-llvm-cpp.cpp
@@ -134,20 +134,16 @@ class MonoJITMemoryManager : public JITMemoryManager
}
virtual void* getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure) {
- if (!strcmp (Name.c_str (), "__bzero")) {
- return (void*)bzero;
- } else {
- void *res;
- char *err;
-
- err = dlsym_cb (Name.c_str (), &res);
- if (err) {
- outs () << "Unable to resolve: " << Name << ": " << err << "\n";
- assert(0);
- return NULL;
- }
- return res;
+ void *res;
+ char *err;
+
+ err = dlsym_cb (Name.c_str (), &res);
+ if (err) {
+ outs () << "Unable to resolve: " << Name << ": " << err << "\n";
+ assert(0);
+ return NULL;
}
+ return res;
}
};
View
16 mono/mini/mini-llvm.c
@@ -4746,11 +4746,21 @@ static char*
dlsym_cb (const char *name, void **symbol)
{
MonoDl *current;
+ char *err;
- current = mono_dl_open (NULL, 0, NULL);
- g_assert (current);
+ err = NULL;
+ if (!strcmp (name, "__bzero")) {
+ *symbol = (void*)bzero;
+ } else {
+ current = mono_dl_open (NULL, 0, NULL);
+ g_assert (current);
- return mono_dl_symbol (current, name, symbol);
+ err = mono_dl_symbol (current, name, symbol);
+ }
+#ifdef MONO_ARCH_HAVE_CREATE_LLVM_NATIVE_THUNK
+ *symbol = (char*)mono_arch_create_llvm_native_thunk (mono_domain_get (), (guint8*)(*symbol));
+#endif
+ return err;
}
static inline void
View
1  mono/mini/mini.h
@@ -2082,6 +2082,7 @@ gpointer mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info,
gpointer mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info) MONO_INTERNAL;
gpointer mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
gpointer mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+guint8 *mono_arch_create_llvm_native_thunk (MonoDomain *domain, guint8* addr) MONO_INTERNAL;
GList *mono_arch_get_allocatable_int_vars (MonoCompile *cfg) MONO_INTERNAL;
GList *mono_arch_get_global_int_regs (MonoCompile *cfg) MONO_INTERNAL;
GList *mono_arch_get_global_fp_regs (MonoCompile *cfg) MONO_INTERNAL;
View
19 mono/mini/tramp-amd64.c
@@ -233,6 +233,25 @@ mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
#endif
}
+guint8*
+mono_arch_create_llvm_native_thunk (MonoDomain *domain, guint8 *addr)
+{
+ /*
+ * The caller is LLVM code and the call displacement might exceed 32 bits. We can't determine the caller address, so
+ * we add a thunk every time.
+ * Since the caller is also allocated using the domain code manager, hopefully the displacement will fit into 32 bits.
+ * FIXME: Avoid this if possible if !MONO_ARCH_NOMAP32BIT and ADDR is 32 bits.
+ */
+ guint8 *thunk_start, *thunk_code;
+
+ thunk_start = thunk_code = mono_domain_code_reserve (mono_domain_get (), 32);
+ amd64_jump_membase (thunk_code, AMD64_RIP, 0);
+ *(guint64*)thunk_code = (guint64)addr;
+ addr = thunk_start;
+ mono_arch_flush_icache (thunk_start, thunk_code - thunk_start);
+ return addr;
+}
+
void
mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
{
Please sign in to comment.
Something went wrong with that request. Please try again.