Clean up the code which handles prepending _ to global symbol names on MACH by doing...
authorZoltan Varga <vargaz@gmail.com>
Thu, 7 Mar 2013 01:00:42 +0000 (02:00 +0100)
committerZoltan Varga <vargaz@gmail.com>
Thu, 7 Mar 2013 01:00:51 +0000 (02:00 +0100)
mono/mini/aot-compiler.c
mono/mini/aot-runtime.c
mono/mini/image-writer.c

index 22b2e41fa908f62e9c3ae74f7127a1c6d03274e3..c280c905166ef36665b82c63f21fa50f18b8260b 100644 (file)
@@ -353,6 +353,18 @@ emit_pointer (MonoAotCompile *acfg, const char *target)
        img_writer_emit_pointer (acfg->w, target); 
 }
 
+static inline void
+emit_pointer_2 (MonoAotCompile *acfg, const char *prefix, const char *target) 
+{ 
+       if (prefix [0] != '\0') {
+               char *s = g_strdup_printf ("%s%s", prefix, target);
+               img_writer_emit_pointer (acfg->w, s);
+               g_free (s);
+       } else {
+               img_writer_emit_pointer (acfg->w, target);
+       }
+}
+
 static inline void
 emit_int16 (MonoAotCompile *acfg, int value) 
 { 
@@ -939,13 +951,15 @@ arch_emit_specific_trampoline_pages (MonoAotCompile *acfg)
 #define COMMON_TRAMP_SIZE 16
        int count = (mono_pagesize () - COMMON_TRAMP_SIZE) / 8;
        int imm8, rot_amount;
+       char symbol [128];
 
        if (!acfg->aot_opts.use_trampolines_page)
                return;
 
+       sprintf (symbol, "%sspecific_trampolines_page", acfg->user_symbol_prefix);
        emit_alignment (acfg, mono_pagesize ());
-       emit_global (acfg, "specific_trampolines_page", TRUE);
-       emit_label (acfg, "specific_trampolines_page");
+       emit_global (acfg, symbol, TRUE);
+       emit_label (acfg, symbol);
 
        /* emit the generic code first, the trampoline address + 8 is in the lr register */
        code = buf;
@@ -973,8 +987,9 @@ arch_emit_specific_trampoline_pages (MonoAotCompile *acfg)
         * subtracts 4096 to get to the data page and loads the values
         * We again fit the generic trampiline in 16 bytes.
         */
-       emit_global (acfg, "rgctx_trampolines_page", TRUE);
-       emit_label (acfg, "rgctx_trampolines_page");
+       sprintf (symbol, "%srgctx_trampolines_page", acfg->user_symbol_prefix);
+       emit_global (acfg, symbol, TRUE);
+       emit_label (acfg, symbol);
        code = buf;
        imm8 = mono_arm_is_rotated_imm8 (mono_pagesize (), &rot_amount);
        ARM_SUB_REG_IMM (code, ARMREG_IP, ARMREG_IP, imm8, rot_amount);
@@ -998,8 +1013,9 @@ arch_emit_specific_trampoline_pages (MonoAotCompile *acfg)
        /*
         * gsharedvt arg trampolines: see arch_emit_gsharedvt_arg_trampoline ()
         */
-       emit_global (acfg, "gsharedvt_arg_trampolines_page", TRUE);
-       emit_label (acfg, "gsharedvt_arg_trampolines_page");
+       sprintf (symbol, "%sgshatedvt_arg_trampolines_page", acfg->user_symbol_prefix);
+       emit_global (acfg, symbol, TRUE);
+       emit_label (acfg, symbol);
        code = buf;
        ARM_PUSH (code, (1 << ARMREG_R0) | (1 << ARMREG_R1) | (1 << ARMREG_R2) | (1 << ARMREG_R3));
        imm8 = mono_arm_is_rotated_imm8 (mono_pagesize (), &rot_amount);
@@ -1025,8 +1041,9 @@ arch_emit_specific_trampoline_pages (MonoAotCompile *acfg)
         * We again fit the generic trampiline in 16 bytes.
         */
 #define IMT_TRAMP_SIZE 72
-       emit_global (acfg, "imt_trampolines_page", TRUE);
-       emit_label (acfg, "imt_trampolines_page");
+       sprintf (symbol, "%simt_trampolines_page", acfg->user_symbol_prefix);
+       emit_global (acfg, symbol, TRUE);
+       emit_label (acfg, symbol);
        code = buf;
        /* Need at least two free registers, plus a slot for storing the pc */
        ARM_PUSH (code, (1 << ARMREG_R0)|(1 << ARMREG_R1)|(1 << ARMREG_R2));
@@ -5306,7 +5323,7 @@ emit_trampoline_full (MonoAotCompile *acfg, int got_offset, MonoTrampInfo *info,
 
        /* Emit code */
 
-       sprintf (start_symbol, "%s", name);
+       sprintf (start_symbol, "%s%s", acfg->user_symbol_prefix, name);
 
        emit_section_change (acfg, ".text", 0);
        emit_global (acfg, start_symbol, TRUE);
@@ -5345,7 +5362,7 @@ emit_trampoline_full (MonoAotCompile *acfg, int got_offset, MonoTrampInfo *info,
        encode_patch_list (acfg, patches, patches->len, got_offset, p, &p);
        g_assert (p - buf < buf_size);
 
-       sprintf (symbol, "%s_p", name);
+       sprintf (symbol, "%s%s_p", acfg->user_symbol_prefix, name);
 
        info_offset = add_to_blob (acfg, buf, p - buf);
 
@@ -7510,7 +7527,7 @@ emit_file_info (MonoAotCompile *acfg)
        gc_name = mono_gc_get_gc_name ();
        gc_name_offset = add_to_blob (acfg, (guint8*)gc_name, strlen (gc_name) + 1);
 
-       sprintf (symbol, "mono_aot_file_info");
+       sprintf (symbol, "%smono_aot_file_info", acfg->user_symbol_prefix);
        emit_section_change (acfg, ".data", 0);
        emit_alignment (acfg, 8);
        emit_label (acfg, symbol);
@@ -7629,11 +7646,7 @@ emit_file_info (MonoAotCompile *acfg)
                 * mono_aot_register_module (). The symbol points to a pointer to the the file info
                 * structure.
                 */
-#if defined(TARGET_MACH) && !defined(__native_client_codegen__)
-               sprintf (symbol, "_mono_aot_module_%s_info", acfg->image->assembly->aname.name);
-#else
-               sprintf (symbol, "mono_aot_module_%s_info", acfg->image->assembly->aname.name);
-#endif
+               sprintf (symbol, "%smono_aot_module_%s_info", acfg->user_symbol_prefix, acfg->image->assembly->aname.name);
 
                /* Get rid of characters which cannot occur in symbols */
                p = symbol;
@@ -7644,7 +7657,7 @@ emit_file_info (MonoAotCompile *acfg)
                acfg->static_linking_symbol = g_strdup (symbol);
                emit_global_inner (acfg, symbol, FALSE);
                emit_label (acfg, symbol);
-               emit_pointer (acfg, "mono_aot_file_info");
+               emit_pointer_2 (acfg, acfg->user_symbol_prefix, "mono_aot_file_info");
        }
 }
 
index e08d90fbde52d6ff4a8693770d40fe015c52690f..e3228b9dfa44af08723fdb7340db2ff4b3a27fff 100644 (file)
@@ -1341,6 +1341,11 @@ find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *valu
                guint16 *table, *entry;
                guint16 table_size;
                guint32 hash;           
+               char *symbol = (char*)name;
+
+#ifdef TARGET_MACH
+               symbol = g_strdup_printf ("_%s", name);
+#endif
 
                /* The first entry points to the hash */
                table = globals [0];
@@ -1349,7 +1354,7 @@ find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *valu
                table_size = table [0];
                table ++;
 
-               hash = mono_metadata_str_hash (name) % table_size;
+               hash = mono_metadata_str_hash (symbol) % table_size;
 
                entry = &table [hash * 2];
 
@@ -1361,7 +1366,7 @@ find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *valu
 
                        //printf ("X: %s %s\n", (char*)globals [index * 2], name);
 
-                       if (!strcmp (globals [index * 2], name)) {
+                       if (!strcmp (globals [index * 2], symbol)) {
                                global_index = index;
                                break;
                        }
@@ -1377,6 +1382,9 @@ find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *valu
                        *value = globals [global_index * 2 + 1];
                else
                        *value = NULL;
+
+               if (symbol != name)
+                       g_free (symbol);
        } else {
                char *err = mono_dl_symbol (module, name, value);
 
index 42035723694915735bb36a84a8b05aa4bfade622..9554e569c219f18e38606c943ebe00a7cddede60 100644 (file)
@@ -1585,15 +1585,8 @@ static void
 asm_writer_emit_global (MonoImageWriter *acfg, const char *name, gboolean func)
 {
        asm_writer_emit_unset_mode (acfg);
-#if  ((defined(__ppc__) || defined(TARGET_X86) || defined(TARGET_AMD64)) && defined(TARGET_ASM_APPLE)) || (defined(HOST_WIN32) && !defined(MONO_CROSS_COMPILE))
-       if (name[0] != '_')
-               // mach-o always uses a '_' prefix.
-               fprintf (acfg->fp, "\t.globl _%s\n", name);
-       else
-               fprintf (acfg->fp, "\t.globl %s\n", name);
-#else
+
        fprintf (acfg->fp, "\t.globl %s\n", name);
-#endif
 
        asm_writer_emit_symbol_type (acfg, name, func);
 }
@@ -1624,22 +1617,7 @@ static void
 asm_writer_emit_label (MonoImageWriter *acfg, const char *name)
 {
        asm_writer_emit_unset_mode (acfg);
-#if (defined(TARGET_X86) || defined(TARGET_AMD64)) && defined(TARGET_ASM_APPLE)
-        name = get_label(name);
-        fprintf (acfg->fp, "%s:\n", name);
-        if (name[0] != 'L' && name[0] != '_')
-            fprintf (acfg->fp, "_%s:\n", name);
-
-#elif (defined(HOST_WIN32) && (defined(TARGET_X86) || defined(TARGET_AMD64))) || (defined(TARGET_X86) && defined(TARGET_ASM_APPLE))
-       fprintf (acfg->fp, "_%s:\n", name);
-#if defined(HOST_WIN32)
-       /* Emit a normal label too */
-       fprintf (acfg->fp, "%s:\n", name);
-#endif
-#else
        fprintf (acfg->fp, "%s:\n", get_label (name));
-#endif
-
 }
 
 static void