Merge pull request #1857 from slluis/fix-assembly-resolver
[mono.git] / mono / mini / mini-x86.c
index aece4a5c1ed1334bd1e4260d3bd962065ed9d622..53e5d6fbbd100281e84f66b44ab3ee564b0ac1b2 100644 (file)
@@ -5025,15 +5025,15 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        break;
                }
                case OP_GC_SAFE_POINT: {
-                       gpointer polling_func = NULL;
+                       const char *polling_func = NULL;
                        int compare_val = 0;
                        guint8 *br [1];
 
 #if defined (USE_COOP_GC)
-                       polling_func = (gpointer)mono_threads_state_poll;
+                       polling_func = "mono_threads_state_poll";
                        compare_val = 1;
 #elif defined(__native_client_codegen__) && defined(__native_client_gc__)
-                       polling_func = (gpointer)mono_nacl_gc;
+                       polling_func = "mono_nacl_gc";
                        compare_val = 0xFFFFFFFF;
 #endif
                        if (!polling_func)
@@ -5041,7 +5041,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
 
                        x86_test_membase_imm (code, ins->sreg1, 0, compare_val);
                        br[0] = code; x86_branch8 (code, X86_CC_EQ, 0, FALSE);
-                       code = emit_call (cfg, code, MONO_PATCH_INFO_ABS, polling_func);
+                       code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, polling_func);
                        x86_patch (br [0], code);
 
                        break;
@@ -5088,94 +5088,74 @@ mono_arch_register_lowlevel_calls (void)
 }
 
 void
-mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
+mono_arch_patch_code_new (MonoCompile *cfg, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gpointer target)
 {
-       MonoJumpInfo *patch_info;
-       gboolean compile_aot = !run_cctors;
-
-       for (patch_info = ji; patch_info; patch_info = patch_info->next) {
-               unsigned char *ip = patch_info->ip.i + code;
-               const unsigned char *target;
+       unsigned char *ip = ji->ip.i + code;
 
-               if (compile_aot) {
-                       switch (patch_info->type) {
-                       case MONO_PATCH_INFO_BB:
-                       case MONO_PATCH_INFO_LABEL:
-                               break;
-                       default:
-                               /* No need to patch these */
-                               continue;
-                       }
+       switch (ji->type) {
+       case MONO_PATCH_INFO_IP:
+               *((gconstpointer *)(ip)) = target;
+               break;
+       case MONO_PATCH_INFO_CLASS_INIT: {
+               guint8 *code = ip;
+               /* Might already been changed to a nop */
+               x86_call_code (code, 0);
+               x86_patch (ip, (unsigned char*)target);
+               break;
+       }
+       case MONO_PATCH_INFO_ABS:
+       case MONO_PATCH_INFO_METHOD:
+       case MONO_PATCH_INFO_METHOD_JUMP:
+       case MONO_PATCH_INFO_INTERNAL_METHOD:
+       case MONO_PATCH_INFO_BB:
+       case MONO_PATCH_INFO_LABEL:
+       case MONO_PATCH_INFO_RGCTX_FETCH:
+       case MONO_PATCH_INFO_MONITOR_ENTER:
+       case MONO_PATCH_INFO_MONITOR_ENTER_V4:
+       case MONO_PATCH_INFO_MONITOR_EXIT:
+       case MONO_PATCH_INFO_JIT_ICALL_ADDR:
+#if defined(__native_client_codegen__) && defined(__native_client__)
+               if (nacl_is_code_address (code)) {
+                       /* For tail calls, code is patched after being installed */
+                       /* but not through the normal "patch callsite" method.   */
+                       unsigned char buf[kNaClAlignment];
+                       unsigned char *aligned_code = (uintptr_t)code & ~kNaClAlignmentMask;
+                       unsigned char *_target = target;
+                       int ret;
+                       /* All patch targets modified in x86_patch */
+                       /* are IP relative.                        */
+                       _target = _target + (uintptr_t)buf - (uintptr_t)aligned_code;
+                       memcpy (buf, aligned_code, kNaClAlignment);
+                       /* Patch a temp buffer of bundle size, */
+                       /* then install to actual location.    */
+                       x86_patch (buf + ((uintptr_t)code - (uintptr_t)aligned_code), _target);
+                       ret = nacl_dyncode_modify (aligned_code, buf, kNaClAlignment);
+                       g_assert (ret == 0);
                }
-
-               target = mono_resolve_patch_target (method, domain, code, patch_info, run_cctors);
-
-               switch (patch_info->type) {
-               case MONO_PATCH_INFO_IP:
-                       *((gconstpointer *)(ip)) = target;
-                       break;
-               case MONO_PATCH_INFO_CLASS_INIT: {
-                       guint8 *code = ip;
-                       /* Might already been changed to a nop */
-                       x86_call_code (code, 0);
-                       x86_patch (ip, target);
-                       break;
+               else {
+                       x86_patch (ip, (unsigned char*)target);
                }
-               case MONO_PATCH_INFO_ABS:
-               case MONO_PATCH_INFO_METHOD:
-               case MONO_PATCH_INFO_METHOD_JUMP:
-               case MONO_PATCH_INFO_INTERNAL_METHOD:
-               case MONO_PATCH_INFO_BB:
-               case MONO_PATCH_INFO_LABEL:
-               case MONO_PATCH_INFO_RGCTX_FETCH:
-               case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
-               case MONO_PATCH_INFO_MONITOR_ENTER:
-               case MONO_PATCH_INFO_MONITOR_ENTER_V4:
-               case MONO_PATCH_INFO_MONITOR_EXIT:
-               case MONO_PATCH_INFO_JIT_ICALL_ADDR:
-#if defined(__native_client_codegen__) && defined(__native_client__)
-                       if (nacl_is_code_address (code)) {
-                               /* For tail calls, code is patched after being installed */
-                               /* but not through the normal "patch callsite" method.   */
-                               unsigned char buf[kNaClAlignment];
-                               unsigned char *aligned_code = (uintptr_t)code & ~kNaClAlignmentMask;
-                               unsigned char *_target = target;
-                               int ret;
-                               /* All patch targets modified in x86_patch */
-                               /* are IP relative.                        */
-                               _target = _target + (uintptr_t)buf - (uintptr_t)aligned_code;
-                               memcpy (buf, aligned_code, kNaClAlignment);
-                               /* Patch a temp buffer of bundle size, */
-                               /* then install to actual location.    */
-                               x86_patch (buf + ((uintptr_t)code - (uintptr_t)aligned_code), _target);
-                               ret = nacl_dyncode_modify (aligned_code, buf, kNaClAlignment);
-                               g_assert (ret == 0);
-                       }
-                       else {
-                               x86_patch (ip, target);
-                       }
 #else
-                       x86_patch (ip, target);
+               x86_patch (ip, (unsigned char*)target);
 #endif
-                       break;
-               case MONO_PATCH_INFO_NONE:
-                       break;
-               case MONO_PATCH_INFO_R4:
-               case MONO_PATCH_INFO_R8: {
-                       guint32 offset = mono_arch_get_patch_offset (ip);
-                       *((gconstpointer *)(ip + offset)) = target;
-                       break;
-               }
-               default: {
-                       guint32 offset = mono_arch_get_patch_offset (ip);
+               break;
+       case MONO_PATCH_INFO_NONE:
+               break;
+       case MONO_PATCH_INFO_R4:
+       case MONO_PATCH_INFO_R8: {
+               guint32 offset = mono_arch_get_patch_offset (ip);
+               *((gconstpointer *)(ip + offset)) = target;
+               break;
+       }
+       default: {
+               guint32 offset = mono_arch_get_patch_offset (ip);
 #if !defined(__native_client__)
-                       *((gconstpointer *)(ip + offset)) = target;
+               *((gconstpointer *)(ip + offset)) = target;
 #else
-                       *((gconstpointer *)(ip + offset)) = nacl_modify_patch_target (target);
+               *((gconstpointer *)(ip + offset)) = nacl_modify_patch_target (target);
 #endif
-                       break;
-               }
-               }
+               break;
+       }
        }
 }