Merge remote-tracking branch 'mfoliveira/ppc64el-v2'
[mono.git] / mono / mini / aot-compiler.c
index 209eb597abbfb60585696f4f1e96a52b478f8e88..bc9c01f401fc9f688c25190250d77ad4a934f8cd 100644 (file)
@@ -52,7 +52,6 @@
 #include <mono/utils/mono-mmap.h>
 
 #include "mini.h"
-#include "seq-points.h"
 #include "image-writer.h"
 #include "dwarfwriter.h"
 #include "mini-gc.h"
 #define TV_GETTIME(tv) tv = mono_100ns_ticks ()
 #define TV_ELAPSED(start,end) (((end) - (start)) / 10)
 
-#ifdef TARGET_WIN32
-#define SHARED_EXT ".dll"
-#elif defined(__ppc__) && defined(TARGET_MACH)
-#define SHARED_EXT ".dylib"
-#elif defined(TARGET_MACH) && defined(TARGET_X86) && !defined(__native_client_codegen__)
-#define SHARED_EXT ".dylib"
-#elif defined(TARGET_MACH) && defined(TARGET_AMD64) && !defined(__native_client_codegen__)
-#define SHARED_EXT ".dylib"
-#else
-#define SHARED_EXT ".so"
-#endif
-
 #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
 #define ALIGN_PTR_TO(ptr,align) (gpointer)((((gssize)(ptr)) + (align - 1)) & (~(align - 1)))
 #define ROUND_DOWN(VALUE,SIZE) ((VALUE) & ~((SIZE) - 1))
@@ -1935,14 +1922,14 @@ arch_emit_imt_thunk (MonoAotCompile *acfg, int offset, int *tramp_size)
        code = buf;
 
        /* Load the mscorlib got address */
-       ppc_ldptr (code, ppc_r11, sizeof (gpointer), ppc_r30);
+       ppc_ldptr (code, ppc_r12, sizeof (gpointer), ppc_r30);
        /* Load the parameter from the GOT */
        ppc_load (code, ppc_r0, offset * sizeof (gpointer));
-       ppc_ldptr_indexed (code, ppc_r11, ppc_r11, ppc_r0);
+       ppc_ldptr_indexed (code, ppc_r12, ppc_r12, ppc_r0);
 
        /* Load and check key */
        labels [1] = code;
-       ppc_ldptr (code, ppc_r0, 0, ppc_r11);
+       ppc_ldptr (code, ppc_r0, 0, ppc_r12);
        ppc_cmp (code, 0, sizeof (gpointer) == 8 ? 1 : 0, ppc_r0, MONO_ARCH_IMT_REG);
        labels [2] = code;
        ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
@@ -1953,18 +1940,18 @@ arch_emit_imt_thunk (MonoAotCompile *acfg, int offset, int *tramp_size)
        ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
 
        /* Loop footer */
-       ppc_addi (code, ppc_r11, ppc_r11, 2 * sizeof (gpointer));
+       ppc_addi (code, ppc_r12, ppc_r12, 2 * sizeof (gpointer));
        labels [4] = code;
        ppc_b (code, 0);
        mono_ppc_patch (labels [4], labels [1]);
 
        /* Match */
        mono_ppc_patch (labels [2], code);
-       ppc_ldptr (code, ppc_r11, sizeof (gpointer), ppc_r11);
-       /* r11 now contains the value of the vtable slot */
+       ppc_ldptr (code, ppc_r12, sizeof (gpointer), ppc_r12);
+       /* r12 now contains the value of the vtable slot */
        /* this is not a function descriptor on ppc64 */
-       ppc_ldptr (code, ppc_r11, 0, ppc_r11);
-       ppc_mtctr (code, ppc_r11);
+       ppc_ldptr (code, ppc_r12, 0, ppc_r12);
+       ppc_mtctr (code, ppc_r12);
        ppc_bcctr (code, PPC_BR_ALWAYS, 0);
 
        /* Fail */
@@ -5335,7 +5322,7 @@ emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
 {
        MonoMethod *method;
        int i, k, buf_size, method_index;
-       guint32 debug_info_size, seq_points_size;
+       guint32 debug_info_size;
        guint8 *code;
        MonoMethodHeader *header;
        guint8 *p, *buf, *debug_info;
@@ -5359,9 +5346,7 @@ emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
 
        seq_points = cfg->seq_point_info;
 
-       seq_points_size = seq_point_info_write_size (seq_points);
-
-       buf_size = header->num_clauses * 256 + debug_info_size + 2048 + seq_points_size + cfg->gc_map_size;
+       buf_size = header->num_clauses * 256 + debug_info_size + 2048 + (seq_points ? (seq_points->len * 128) : 0) + cfg->gc_map_size;
        p = buf = g_malloc (buf_size);
 
        use_unwind_ops = cfg->unwind_ops != NULL;
@@ -5389,6 +5374,15 @@ emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
                encode_value (table->num_holes, p, &p);
        }
 
+       if (jinfo->has_arch_eh_info) {
+               /*
+                * In AOT mode, the code length is calculated from the address of the previous method,
+                * which could include alignment padding, so calculating the start of the epilog as
+                * code_len - epilog_size is correct any more. Save the real code len as a workaround.
+                */
+               encode_value (jinfo->code_size, p, &p);
+       }
+
        /* Exception table */
        if (cfg->compile_llvm) {
                /*
@@ -5558,9 +5552,27 @@ emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
                }
        }
 
-       if (seq_points)
-               p += seq_point_info_write (seq_points, p);
+       if (seq_points) {
+               int il_offset, native_offset, last_il_offset, last_native_offset, j;
+
+               encode_value (seq_points->len, p, &p);
+               last_il_offset = last_native_offset = 0;
+               for (i = 0; i < seq_points->len; ++i) {
+                       SeqPoint *sp = &seq_points->seq_points [i];
+                       il_offset = sp->il_offset;
+                       native_offset = sp->native_offset;
+                       encode_value (il_offset - last_il_offset, p, &p);
+                       encode_value (native_offset - last_native_offset, p, &p);
+                       last_il_offset = il_offset;
+                       last_native_offset = native_offset;
 
+                       encode_value (sp->flags, p, &p);
+                       encode_value (sp->next_len, p, &p);
+                       for (j = 0; j < sp->next_len; ++j)
+                               encode_value (sp->next [j], p, &p);
+               }
+       }
+               
        g_assert (debug_info_size < buf_size);
 
        encode_value (debug_info_size, p, &p);
@@ -8626,7 +8638,7 @@ compile_asm (MonoAotCompile *acfg)
        if (acfg->aot_opts.outfile)
                outfile_name = g_strdup_printf ("%s", acfg->aot_opts.outfile);
        else
-               outfile_name = g_strdup_printf ("%s%s", acfg->image->name, SHARED_EXT);
+               outfile_name = g_strdup_printf ("%s%s", acfg->image->name, MONO_SOLIB_EXT);
 
        tmp_outfile_name = g_strdup_printf ("%s.tmp", outfile_name);
 
@@ -8646,7 +8658,7 @@ compile_asm (MonoAotCompile *acfg)
 
        g_free (command);
 
-       /*com = g_strdup_printf ("strip --strip-unneeded %s%s", acfg->image->name, SHARED_EXT);
+       /*com = g_strdup_printf ("strip --strip-unneeded %s%s", acfg->image->name, MONO_SOLIB_EXT);
        printf ("Stripping the binary: %s\n", com);
        system (com);
        g_free (com);*/
@@ -8843,7 +8855,7 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options)
                MonoDebugOptions *opt = mini_get_debug_options ();
 
                opt->mdb_optimizations = TRUE;
-               opt->gen_seq_points_debug_data = TRUE;
+               opt->gen_seq_points = TRUE;
 
                if (!mono_debug_enabled ()) {
                        aot_printerrf (acfg, "The soft-debug AOT option requires the --debug option.\n");
@@ -8997,7 +9009,7 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options)
                if (acfg->aot_opts.outfile)
                        outfile_name = g_strdup_printf ("%s", acfg->aot_opts.outfile);
                else
-                       outfile_name = g_strdup_printf ("%s%s", acfg->image->name, SHARED_EXT);
+                       outfile_name = g_strdup_printf ("%s%s", acfg->image->name, MONO_SOLIB_EXT);
 
                /* 
                 * Can't use g_file_open_tmp () as it will be deleted at exit, and