* image-writer.c: Improve support for the osx assembler.
* dwarfwriter.c: Avoid the usage of subsections if the assembler doesn't
support them.
svn path=/trunk/mono/; revision=135624
+2009-06-08 Zoltan Varga <vargaz@gmail.com>
+
+ * image-writer.c: Improve support for the osx assembler.
+
+ * dwarfwriter.c: Avoid the usage of subsections if the assembler doesn't
+ support them.
+
2009-06-07 Zoltan Varga <vargaz@gmail.com>
* image-writer.c (append_subsection): Don't align subsections of the
FILE *il_file;
int il_file_line_index, loclist_index;
GSList *cie_program;
+ FILE *fp;
+ const char *temp_prefix;
+ gboolean emit_line;
};
/*
w->w = writer;
w->il_file = il_file;
+ w->fp = img_writer_get_fp (w->w);
+ w->temp_prefix = img_writer_get_temp_label_prefix (w->w);
+
return w;
}
emit_label (w, ".Ldebug_line_end");
}
+/*
+ * Some assemblers like apple's do not support subsections, so we can't place
+ * .Ldebug_info_end at the end of the section using subsections. Instead, we
+ * define it every time something gets added to the .debug_info section.
+ * The apple assember seems to use the last definition.
+ */
+static void
+emit_debug_info_end (MonoDwarfWriter *w)
+{
+ if (!img_writer_subsections_supported (w->w))
+ fprintf (w->fp, "\n.set %sdebug_info_end,.\n", w->temp_prefix);
+}
+
void
mono_dwarf_writer_emit_base_info (MonoDwarfWriter *w, GSList *base_unwind_program)
{
char *s, *build_info;
int i;
+ if (!img_writer_subsections_supported (w->w))
+ /* Can't emit line number info without subsections */
+ w->emit_line = FALSE;
+ else
+ w->emit_line = TRUE;
+
w->cie_program = base_unwind_program;
emit_section_change (w, ".debug_abbrev", 0);
emit_int32 (w, 0); /* .debug_abbrev offset */
emit_byte (w, sizeof (gpointer)); /* address size */
- /* Emit this into a separate section so it gets placed at the end */
- emit_section_change (w, ".debug_info", 1);
- emit_int32 (w, 0); /* close everything */
- emit_label (w, ".Ldebug_info_end");
- emit_section_change (w, ".debug_info", 0);
+ if (img_writer_subsections_supported (w->w)) {
+ /* Emit this into a separate section so it gets placed at the end */
+ emit_section_change (w, ".debug_info", 1);
+ emit_int32 (w, 0); /* close everything */
+ emit_label (w, ".Ldebug_info_end");
+ emit_section_change (w, ".debug_info", 0);
+ }
/* Compilation unit */
emit_uleb128 (w, ABBREV_COMPILE_UNIT);
emit_pointer_value (w, 0);
emit_pointer_value (w, 0);
/* offset into .debug_line section */
- emit_symbol_diff (w, ".Ldebug_line_start", ".Ldebug_line_section_start", 0);
+ if (w->emit_line)
+ emit_symbol_diff (w, ".Ldebug_line_start", ".Ldebug_line_section_start", 0);
+ else
+ emit_int32 (w, 0);
/* Base types */
for (i = 0; i < G_N_ELEMENTS (basic_types); ++i) {
emit_string (w, basic_types [i].name);
}
+ emit_debug_info_end (w);
+
/* debug_loc section */
emit_section_change (w, ".debug_loc", 0);
emit_label (w, ".Ldebug_loc_start");
/* debug_line section */
- emit_line_number_info_begin (w);
+ if (w->emit_line)
+ emit_line_number_info_begin (w);
emit_cie (w);
}
GArray *ln_array;
int *native_to_il_offset = NULL;
+ if (!w->emit_line)
+ return;
+
minfo = mono_debug_lookup_method (method);
/* Compute the native->IL offset mapping */
emit_line (w);
+ emit_debug_info_end (w);
+
/* Emit unwind info */
if (unwind_info) {
emit_fde (w, w->fde_index, start_symbol, end_symbol, code, code_size, unwind_info, TRUE);
/* Subprogram end */
emit_uleb128 (w, 0x0);
+ emit_debug_info_end (w);
+
/* Emit unwind info */
emit_fde (w, w->fde_index, start_symbol, end_symbol, code, code_size, unwind_info, FALSE);
w->fde_index ++;
char *tmpfname;
int mode; /* emit mode */
int col_count; /* bytes emitted per .byte line */
+ int label_gen;
};
static G_GNUC_UNUSED int
#elif defined(TARGET_ASM_APPLE)
if (strcmp(section_name, ".bss") == 0)
fprintf (acfg->fp, "%s\n", ".data");
- else
+ else if (strstr (section_name, ".debug") == section_name) {
+ //g_assert (subsection_index == 0);
+ fprintf (acfg->fp, ".section __DWARF, __%s,regular,debug\n", section_name + 1);
+ } else
fprintf (acfg->fp, "%s\n", section_name);
#elif defined(TARGET_ARM) || defined(TARGET_POWERPC)
/* ARM gas doesn't seem to like subsections of .bss */
#endif
}
+static inline
+const char *get_label (const char *s)
+{
+#ifdef TARGET_ASM_APPLE
+ if (s [0] == '.' && s [1] == 'L')
+ /* apple uses "L" instead of ".L" to mark temporary labels */
+ s ++;
+#endif
+ return s;
+}
+
static void
asm_writer_emit_symbol_type (MonoImageWriter *acfg, const char *name, gboolean func)
{
asm_writer_emit_label (MonoImageWriter *acfg, const char *name)
{
asm_writer_emit_unset_mode (acfg);
-#if (defined(__ppc__) && defined(TARGET_ASM_APPLE)) || defined(PLATFORM_WIN32)
- // mach-o always uses a '_' prefix.
+#if defined(PLATFORM_WIN32)
fprintf (acfg->fp, "_%s:\n", name);
#else
- fprintf (acfg->fp, "%s:\n", name);
+ fprintf (acfg->fp, "%s:\n", get_label (name));
#endif
#if defined(PLATFORM_WIN32)
static void
asm_writer_emit_symbol_diff (MonoImageWriter *acfg, const char *end, const char* start, int offset)
{
+#ifdef TARGET_ASM_APPLE
+ char symbol [128];
+#endif
+
if (acfg->mode != EMIT_LONG) {
acfg->mode = EMIT_LONG;
acfg->col_count = 0;
}
+
+#ifdef TARGET_ASM_APPLE
+ /* The apple assembler needs a separate symbol to be able to handle complex expressions */
+ sprintf (symbol, "LTMP_SYM%d", acfg->label_gen);
+ start = get_label (start);
+ end = get_label (end);
+ acfg->label_gen ++;
+ if (offset > 0)
+ fprintf (acfg->fp, "\n%s=%s - %s + %d", symbol, end, start, offset);
+ else if (offset < 0)
+ fprintf (acfg->fp, "\n%s=%s - %s %d", symbol, end, start, offset);
+ else
+ fprintf (acfg->fp, "\n%s=%s - %s", symbol, end, start);
+
+ fprintf (acfg->fp, "\n\t%s ", AS_INT32_DIRECTIVE);
+ fprintf (acfg->fp, "%s", symbol);
+#else
if ((acfg->col_count++ % 8) == 0)
fprintf (acfg->fp, "\n\t%s ", AS_INT32_DIRECTIVE);
else
fprintf (acfg->fp, "%s - %s %d", end, start, offset);
else
fprintf (acfg->fp, "%s - %s", end, start);
+#endif
}
static void
mono_mempool_destroy (w->mempool);
g_free (w);
}
+
+gboolean
+img_writer_subsections_supported (MonoImageWriter *acfg)
+{
+#ifdef TARGET_ASM_APPLE
+ return acfg->use_bin_writer;
+#else
+ return TRUE;
+#endif
+}
+
+FILE *
+img_writer_get_fp (MonoImageWriter *acfg)
+{
+ return acfg->fp;
+}
+
+const char *
+img_writer_get_temp_label_prefix (MonoImageWriter *acfg)
+{
+#ifdef TARGET_ASM_APPLE
+ return "L";
+#else
+ return ".L";
+#endif
+}
void img_writer_emit_unset_mode (MonoImageWriter *acfg) MONO_INTERNAL;
+gboolean img_writer_subsections_supported (MonoImageWriter *acfg) MONO_INTERNAL;
+
+FILE * img_writer_get_fp (MonoImageWriter *acfg) MONO_INTERNAL;
+
+const char *img_writer_get_temp_label_prefix (MonoImageWriter *acfg) MONO_INTERNAL;
+
#endif