Merge pull request #3142 from henricm/fix-for-win-mono_string_to_utf8
[mono.git] / mono / mini / image-writer.c
index 0a74bfb4ff875eca13a397a825b55ff506582437..ab3bf8094a56e711648810e6ea8e7bfe3ea4c8dd 100644 (file)
@@ -324,7 +324,7 @@ bin_writer_emit_ensure_buffer (BinSection *section, int size)
                guint8 *data;
                while (new_size <= new_offset)
                        new_size *= 2;
-               data = g_malloc0 (new_size);
+               data = (guint8 *)g_malloc0 (new_size);
 #ifdef __native_client_codegen__
                /* for Native Client, fill empty space with HLT instruction */
                /* instead of 00.                                           */
@@ -372,22 +372,6 @@ bin_writer_emit_alignment (MonoImageWriter *acfg, int size)
        }
 }
 
-#ifdef __native_client_codegen__
-static void
-bin_writer_emit_nacl_call_alignment (MonoImageWriter *acfg) {
-  int offset = acfg->cur_section->cur_offset;
-  int padding = kNaClAlignment - (offset & kNaClAlignmentMask) - kNaClLengthOfCallImm;
-  guint8 padc = '\x90';
-
-  if (padding < 0) padding += kNaClAlignment;
-
-  while (padding > 0) {
-    bin_writer_emit_bytes(acfg, &padc, 1);
-    padding -= 1;
-  }
-}
-#endif  /* __native_client_codegen__ */
-
 static void
 bin_writer_emit_pointer_unaligned (MonoImageWriter *acfg, const char *target)
 {
@@ -448,7 +432,7 @@ static BinReloc*
 create_reloc (MonoImageWriter *acfg, const char *end, const char* start, int offset)
 {
        BinReloc *reloc;
-       reloc = mono_mempool_alloc0 (acfg->mempool, sizeof (BinReloc));
+       reloc = (BinReloc *)mono_mempool_alloc0 (acfg->mempool, sizeof (BinReloc));
        reloc->val1 = mono_mempool_strdup (acfg->mempool, end);
        if (strcmp (start, ".") == 0) {
                reloc->val2_section = acfg->cur_section;
@@ -899,7 +883,7 @@ get_label_addr (MonoImageWriter *acfg, const char *name)
        BinSection *section;
        gsize value;
 
-       lab = g_hash_table_lookup (acfg->labels, name);
+       lab = (BinLabel *)g_hash_table_lookup (acfg->labels, name);
        if (!lab)
                g_error ("Undefined label: '%s'.\n", name);
        section = lab->section;
@@ -982,7 +966,7 @@ collect_syms (MonoImageWriter *acfg, int *hash, ElfStrTable *strtab, ElfSectHead
                /*g_print ("sym name %s tabled to %d\n", symbol->name, symbols [i].st_name);*/
                section = symbol->section;
                symbols [i].st_shndx = section->parent? section->parent->shidx: section->shidx;
-               lab = g_hash_table_lookup (acfg->labels, symbol->name);
+               lab = (BinLabel *)g_hash_table_lookup (acfg->labels, symbol->name);
                offset = lab->offset;
                if (section->parent) {
                        symbols [i].st_value = section->parent->virt_offset + section->cur_offset + offset;
@@ -991,7 +975,7 @@ collect_syms (MonoImageWriter *acfg, int *hash, ElfStrTable *strtab, ElfSectHead
                }
 
                if (symbol->end_label) {
-                       BinLabel *elab = g_hash_table_lookup (acfg->labels, symbol->end_label);
+                       BinLabel *elab = (BinLabel *)g_hash_table_lookup (acfg->labels, symbol->end_label);
                        g_assert (elab);
                        symbols [i].st_size = elab->offset - lab->offset;
                }
@@ -1063,7 +1047,7 @@ reloc_symbols (MonoImageWriter *acfg, ElfSymbol *symbols, ElfSectHeader *sheader
                if (dynamic && !symbol->is_global)
                        continue;
                section = symbol->section;
-               lab = g_hash_table_lookup (acfg->labels, symbol->name);
+               lab = (BinLabel *)g_hash_table_lookup (acfg->labels, symbol->name);
                offset = lab->offset;
                if (section->parent) {
                        symbols [i].st_value = sheaders [section->parent->shidx].sh_addr + section->cur_offset + offset;
@@ -1615,7 +1599,7 @@ bin_writer_emit_writeout (MonoImageWriter *acfg)
 
        if (!acfg->fp) {
                acfg->out_buf_size = file_offset + sizeof (secth);
-               acfg->out_buf = g_malloc (acfg->out_buf_size);
+               acfg->out_buf = (guint8 *)g_malloc (acfg->out_buf_size);
        }
 
        bin_writer_fwrite (acfg, &header, sizeof (header), 1);
@@ -1686,6 +1670,9 @@ bin_writer_emit_writeout (MonoImageWriter *acfg)
 static void
 asm_writer_emit_start (MonoImageWriter *acfg)
 {
+#if defined(TARGET_ASM_APPLE)
+       fprintf (acfg->fp, ".subsections_via_symbols\n");
+#endif
 }
 
 static int
@@ -1759,8 +1746,14 @@ asm_writer_emit_symbol_type (MonoImageWriter *acfg, const char *name, gboolean f
                stype = "object";
 
        asm_writer_emit_unset_mode (acfg);
+
 #if defined(TARGET_ASM_APPLE)
 
+#elif defined(TARGET_WIN32)
+       if (func)
+               fprintf (acfg->fp, "\t.def %s; .scl 2; .type 32; .endef\n", name);
+       else
+               fprintf (acfg->fp, "\t.data\n");
 #elif defined(TARGET_ARM)
        fprintf (acfg->fp, "\t.type %s,#%s\n", name, stype);
 #else
@@ -1783,7 +1776,7 @@ asm_writer_emit_local_symbol (MonoImageWriter *acfg, const char *name, const cha
 {
        asm_writer_emit_unset_mode (acfg);
 
-#ifndef TARGET_ASM_APPLE
+#if !defined(TARGET_ASM_APPLE) && !defined(TARGET_WIN32)
        fprintf (acfg->fp, "\t.local %s\n", name);
 #endif
 
@@ -1795,7 +1788,8 @@ asm_writer_emit_symbol_size (MonoImageWriter *acfg, const char *name, const char
 {
        asm_writer_emit_unset_mode (acfg);
 
-#ifndef TARGET_ASM_APPLE
+
+#if !defined(TARGET_ASM_APPLE) && !defined(TARGET_WIN32)
        fprintf (acfg->fp, "\t.size %s,%s-%s\n", name, end_label, name);
 #endif
 }
@@ -1852,20 +1846,6 @@ asm_writer_emit_alignment_fill (MonoImageWriter *acfg, int size, int fill)
 }
 #endif
 
-#ifdef __native_client_codegen__
-static void
-asm_writer_emit_nacl_call_alignment (MonoImageWriter *acfg) {
-  int padding = kNaClAlignment - kNaClLengthOfCallImm;
-  guint8 padc = '\x90';
-
-  fprintf (acfg->fp, "\n\t.align %d", kNaClAlignment);
-  while (padding > 0) {
-    fprintf (acfg->fp, "\n\t.byte %d", padc);
-    padding -= 1;
-  }
-}
-#endif  /* __native_client_codegen__ */
-
 static void
 asm_writer_emit_pointer_unaligned (MonoImageWriter *acfg, const char *target)
 {
@@ -2172,20 +2152,6 @@ mono_img_writer_emit_alignment_fill (MonoImageWriter *acfg, int size, int fill)
 #endif
 }
 
-#ifdef __native_client_codegen__
-void
-mono_img_writer_emit_nacl_call_alignment (MonoImageWriter *acfg) {
-#ifdef USE_BIN_WRITER
-       if (acfg->use_bin_writer)
-               bin_writer_emit_nacl_call_alignment (acfg);
-       else
-               asm_writer_emit_nacl_call_alignment (acfg);
-#else
-       g_assert_not_reached();
-#endif
-}
-#endif  /* __native_client_codegen__ */
-
 void
 mono_img_writer_emit_pointer_unaligned (MonoImageWriter *acfg, const char *target)
 {