#define USE_ELF_RELA 1
#endif
-#if defined(TARGET_X86) && !defined(TARGET_WIN32) && !defined(__APPLE__)
+#if defined(TARGET_X86) && !defined(HOST_WIN32) && !defined(__APPLE__)
#define USE_ELF_WRITER 1
#endif
#if defined(TARGET_ARM) && !defined(TARGET_MACH) && !defined(HOST_WIN32)
-#define USE_ELF_WRITER 1
+//#define USE_ELF_WRITER 1
#endif
#if defined(__mips__)
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. */
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;
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;
/*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;
}
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;
}
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;
static int
bin_writer_emit_writeout (MonoImageWriter *acfg)
{
- FILE *file;
ElfHeader header;
ElfProgHeader progh [4];
ElfSectHeader secth [SECT_NUM];
ElfSymbol *symtab;
ElfDynamic dynamic [14];
int *hash;
- int i, num_sections, file_offset, virt_offset, size, num_symtab;
+ int i, num_sections, file_offset, virt_offset, size;
int num_local_syms;
- file = acfg->fp;
-
/* Section headers */
memset (§h, 0, sizeof (secth));
memset (&dynamic, 0, sizeof (dynamic));
num_sections = collect_sections (acfg, secth, all_sections, 16);
hash = build_hash (acfg, num_sections, &dyn_str_table);
- num_symtab = hash [1]; /* FIXME */
#if 0
g_print ("num_sections: %d\n", num_sections);
g_print ("dynsym: %d, dynstr size: %d\n", hash [1], (int)dyn_str_table.data->len);
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);
static void
asm_writer_emit_start (MonoImageWriter *acfg)
{
+#if defined(TARGET_ASM_APPLE)
+ fprintf (acfg->fp, ".subsections_via_symbols\n");
+#endif
}
static int
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
{
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
{
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
}
#endif
}
+#ifndef USE_BIN_WRITER
+static void
+asm_writer_emit_alignment_fill (MonoImageWriter *acfg, int size, int fill)
+{
+ asm_writer_emit_unset_mode (acfg);
+#if defined(TARGET_ASM_APPLE)
+ fprintf (acfg->fp, "\t.align %d, 0x%0x\n", ilog2 (size), fill);
+#else
+ asm_writer_emit_alignment (acfg, size);
+#endif
+}
+#endif
+
#ifdef __native_client_codegen__
static void
asm_writer_emit_nacl_call_alignment (MonoImageWriter *acfg) {
/* EMIT FUNCTIONS */
void
-img_writer_emit_start (MonoImageWriter *acfg)
+mono_img_writer_emit_start (MonoImageWriter *acfg)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_section_change (MonoImageWriter *acfg, const char *section_name, int subsection_index)
+mono_img_writer_emit_section_change (MonoImageWriter *acfg, const char *section_name, int subsection_index)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_push_section (MonoImageWriter *acfg, const char *section_name, int subsection)
+mono_img_writer_emit_push_section (MonoImageWriter *acfg, const char *section_name, int subsection)
{
g_assert (acfg->stack_pos < 16 - 1);
acfg->section_stack [acfg->stack_pos] = acfg->current_section;
acfg->subsection_stack [acfg->stack_pos] = acfg->current_subsection;
acfg->stack_pos ++;
- img_writer_emit_section_change (acfg, section_name, subsection);
+ mono_img_writer_emit_section_change (acfg, section_name, subsection);
}
void
-img_writer_emit_pop_section (MonoImageWriter *acfg)
+mono_img_writer_emit_pop_section (MonoImageWriter *acfg)
{
g_assert (acfg->stack_pos > 0);
acfg->stack_pos --;
- img_writer_emit_section_change (acfg, acfg->section_stack [acfg->stack_pos], acfg->subsection_stack [acfg->stack_pos]);
+ mono_img_writer_emit_section_change (acfg, acfg->section_stack [acfg->stack_pos], acfg->subsection_stack [acfg->stack_pos]);
}
void
-img_writer_set_section_addr (MonoImageWriter *acfg, guint64 addr)
+mono_img_writer_set_section_addr (MonoImageWriter *acfg, guint64 addr)
{
#ifdef USE_BIN_WRITER
if (!acfg->use_bin_writer)
}
void
-img_writer_emit_global (MonoImageWriter *acfg, const char *name, gboolean func)
+mono_img_writer_emit_global (MonoImageWriter *acfg, const char *name, gboolean func)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_local_symbol (MonoImageWriter *acfg, const char *name, const char *end_label, gboolean func)
+mono_img_writer_emit_local_symbol (MonoImageWriter *acfg, const char *name, const char *end_label, gboolean func)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_symbol_size (MonoImageWriter *acfg, const char *name, const char *end_label)
+mono_img_writer_emit_symbol_size (MonoImageWriter *acfg, const char *name, const char *end_label)
{
if (!acfg->use_bin_writer)
asm_writer_emit_symbol_size (acfg, name, end_label);
}
void
-img_writer_emit_label (MonoImageWriter *acfg, const char *name)
+mono_img_writer_emit_label (MonoImageWriter *acfg, const char *name)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_bytes (MonoImageWriter *acfg, const guint8* buf, int size)
+mono_img_writer_emit_bytes (MonoImageWriter *acfg, const guint8* buf, int size)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_string (MonoImageWriter *acfg, const char *value)
+mono_img_writer_emit_string (MonoImageWriter *acfg, const char *value)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_line (MonoImageWriter *acfg)
+mono_img_writer_emit_line (MonoImageWriter *acfg)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_alignment (MonoImageWriter *acfg, int size)
+mono_img_writer_emit_alignment (MonoImageWriter *acfg, int size)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
#endif
}
+void
+mono_img_writer_emit_alignment_fill (MonoImageWriter *acfg, int size, int fill)
+{
+#ifdef USE_BIN_WRITER
+ if (acfg->use_bin_writer)
+ bin_writer_emit_alignment (acfg, size);
+ else
+ asm_writer_emit_alignment (acfg, size);
+#else
+ asm_writer_emit_alignment_fill (acfg, size, fill);
+#endif
+}
+
#ifdef __native_client_codegen__
void
-img_writer_emit_nacl_call_alignment (MonoImageWriter *acfg) {
+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);
#endif /* __native_client_codegen__ */
void
-img_writer_emit_pointer_unaligned (MonoImageWriter *acfg, const char *target)
+mono_img_writer_emit_pointer_unaligned (MonoImageWriter *acfg, const char *target)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_pointer (MonoImageWriter *acfg, const char *target)
+mono_img_writer_emit_pointer (MonoImageWriter *acfg, const char *target)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_int16 (MonoImageWriter *acfg, int value)
+mono_img_writer_emit_int16 (MonoImageWriter *acfg, int value)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_int32 (MonoImageWriter *acfg, int value)
+mono_img_writer_emit_int32 (MonoImageWriter *acfg, int value)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_symbol_diff (MonoImageWriter *acfg, const char *end, const char* start, int offset)
+mono_img_writer_emit_symbol_diff (MonoImageWriter *acfg, const char *end, const char* start, int offset)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_zero_bytes (MonoImageWriter *acfg, int num)
+mono_img_writer_emit_zero_bytes (MonoImageWriter *acfg, int num)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
int
-img_writer_emit_writeout (MonoImageWriter *acfg)
+mono_img_writer_emit_writeout (MonoImageWriter *acfg)
{
#ifdef USE_BIN_WRITER
if (acfg->use_bin_writer)
}
void
-img_writer_emit_byte (MonoImageWriter *acfg, guint8 val)
+mono_img_writer_emit_byte (MonoImageWriter *acfg, guint8 val)
{
- img_writer_emit_bytes (acfg, &val, 1);
+ mono_img_writer_emit_bytes (acfg, &val, 1);
}
/*
* Do not advance PC.
*/
void
-img_writer_emit_reloc (MonoImageWriter *acfg, int reloc_type, const char *symbol, int addend)
+mono_img_writer_emit_reloc (MonoImageWriter *acfg, int reloc_type, const char *symbol, int addend)
{
/* This is only supported by the bin writer */
#ifdef USE_BIN_WRITER
}
/*
- * img_writer_emit_unset_mode:
+ * mono_img_writer_emit_unset_mode:
*
* Flush buffered data so it is safe to write to the output file from outside this
* module. This is a nop for the binary writer.
*/
void
-img_writer_emit_unset_mode (MonoImageWriter *acfg)
+mono_img_writer_emit_unset_mode (MonoImageWriter *acfg)
{
if (!acfg->use_bin_writer)
asm_writer_emit_unset_mode (acfg);
}
/*
- * img_writer_get_output:
+ * mono_img_writer_get_output:
*
* Return the output buffer of a binary writer emitting to memory. The returned memory
* is from malloc, and it is owned by the caller.
*/
guint8*
-img_writer_get_output (MonoImageWriter *acfg, guint32 *size)
+mono_img_writer_get_output (MonoImageWriter *acfg, guint32 *size)
{
#ifdef USE_BIN_WRITER
guint8 *buf;
* Return whenever the binary writer is supported on this platform.
*/
gboolean
-bin_writer_supported (void)
+mono_bin_writer_supported (void)
{
#ifdef USE_BIN_WRITER
return TRUE;
}
/*
- * img_writer_create:
+ * mono_img_writer_create:
*
* Create an image writer writing to FP. If USE_BIN_WRITER is TRUE, FP can be NULL,
* in this case the image writer will write to a memory buffer obtainable by calling
- * img_writer_get_output ().
+ * mono_img_writer_get_output ().
*/
MonoImageWriter*
-img_writer_create (FILE *fp, gboolean use_bin_writer)
+mono_img_writer_create (FILE *fp, gboolean use_bin_writer)
{
MonoImageWriter *w = g_new0 (MonoImageWriter, 1);
}
void
-img_writer_destroy (MonoImageWriter *w)
+mono_img_writer_destroy (MonoImageWriter *w)
{
// FIXME: Free all the stuff
mono_mempool_destroy (w->mempool);
}
gboolean
-img_writer_subsections_supported (MonoImageWriter *acfg)
+mono_img_writer_subsections_supported (MonoImageWriter *acfg)
{
#ifdef TARGET_ASM_APPLE
return acfg->use_bin_writer;
}
FILE *
-img_writer_get_fp (MonoImageWriter *acfg)
+mono_img_writer_get_fp (MonoImageWriter *acfg)
{
return acfg->fp;
}
const char *
-img_writer_get_temp_label_prefix (MonoImageWriter *acfg)
+mono_img_writer_get_temp_label_prefix (MonoImageWriter *acfg)
{
return AS_TEMP_LABEL_PREFIX;
}