Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonojenkins <jo.shields+jenkins@xamarin.com>2020-05-26 19:44:37 +0300
committerGitHub <noreply@github.com>2020-05-26 19:44:37 +0300
commit87ef5557017a8d822ae31587846a54fcd66daf1b (patch)
tree873daed6b2b2e1a9effade6d13f6f901726fa448
parent8c085a99b32e99ae2f0a6b3de61541fefb4d3389 (diff)
Emit DWARF debug_abbrev offset for compile units as a label instead of 0 (#19794)
When outputting DWARF code to start a compilation unit in .debug_info, the standard expect a 4-byte offset from the .debug_abbrev code. Mono has always output an offset of 0. However, this doesn't work in every cases. When we have linux+fullaot, we link two object files (one from Mono, one from LLVM). Both have their .debug_abbrev section. If we use 0 as an offset, it seems possible that the linker will keep thinking that our offset is 0, no matter the circumstances. Since the offset is always 0, it can be using the wrong abbreviation table (i.e. the one from the LLVM assembly instead of the one from the Mono assembly). The consequence of this is that the linked file is not valid DWARF (dwarfdump and objdump will complain about invalid offsets). At best, some tools will be able to work with a part of what we have, but any program requiring entirely valid DWARF will fail. To fix this, we generate a label for the start of our debug_abbrev section and we instead generate it by generating a long with that label. This matches existing behavior seen in the LLVM generated code, and makes dwarfdump and objdump react properly to the linked product. Fixes https://github.com/mono/mono/issues/8806 Co-authored-by: Mathieu Bourgeois <mathieu.bourgeois@gameloft.com>
-rw-r--r--mono/mini/dwarfwriter.c9
-rw-r--r--mono/mini/image-writer.c50
-rw-r--r--mono/mini/image-writer.h2
3 files changed, 55 insertions, 6 deletions
diff --git a/mono/mini/dwarfwriter.c b/mono/mini/dwarfwriter.c
index bf2ff736feb..c93151ec613 100644
--- a/mono/mini/dwarfwriter.c
+++ b/mono/mini/dwarfwriter.c
@@ -182,6 +182,12 @@ emit_int32 (MonoDwarfWriter *w, int value)
}
static void
+emit_symbol (MonoDwarfWriter *w, const char *symbol)
+{
+ mono_img_writer_emit_symbol (w->w, symbol);
+}
+
+static void
emit_symbol_diff (MonoDwarfWriter *w, const char *end, const char* start, int offset)
{
mono_img_writer_emit_symbol_diff (w->w, end, start, offset);
@@ -799,6 +805,7 @@ mono_dwarf_writer_emit_base_info (MonoDwarfWriter *w, const char *cu_name, GSLis
w->cie_program = base_unwind_program;
emit_section_change (w, ".debug_abbrev", 0);
+ emit_label (w, ".Ldebug_abbrev_start");
emit_dwarf_abbrev (w, ABBREV_COMPILE_UNIT, DW_TAG_compile_unit, TRUE,
compile_unit_attr, G_N_ELEMENTS (compile_unit_attr));
emit_dwarf_abbrev (w, ABBREV_SUBPROGRAM, DW_TAG_subprogram, TRUE,
@@ -842,7 +849,7 @@ mono_dwarf_writer_emit_base_info (MonoDwarfWriter *w, const char *cu_name, GSLis
emit_symbol_diff (w, ".Ldebug_info_end", ".Ldebug_info_begin", 0); /* length */
emit_label (w, ".Ldebug_info_begin");
emit_int16 (w, 0x2); /* DWARF version 2 */
- emit_int32 (w, 0); /* .debug_abbrev offset */
+ emit_symbol (w, ".Ldebug_abbrev_start"); /* .debug_abbrev offset */
emit_byte (w, sizeof (target_mgreg_t)); /* address size */
/* Compilation unit */
diff --git a/mono/mini/image-writer.c b/mono/mini/image-writer.c
index 7314c5ee830..b191269667a 100644
--- a/mono/mini/image-writer.c
+++ b/mono/mini/image-writer.c
@@ -410,11 +410,14 @@ create_reloc (MonoImageWriter *acfg, const char *end, const char* start, int off
BinReloc *reloc;
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;
- reloc->val2_offset = acfg->cur_section->cur_offset;
- } else {
- reloc->val2 = mono_mempool_strdup (acfg->mempool, start);
+ if (start)
+ {
+ if (strcmp (start, ".") == 0) {
+ reloc->val2_section = acfg->cur_section;
+ reloc->val2_offset = acfg->cur_section->cur_offset;
+ } else {
+ reloc->val2 = mono_mempool_strdup (acfg->mempool, start);
+ }
}
reloc->offset = offset;
reloc->section = acfg->cur_section;
@@ -425,6 +428,13 @@ create_reloc (MonoImageWriter *acfg, const char *end, const char* start, int off
}
static void
+bin_writer_emit_symbol (MonoImageWriter *acfg, const char *symbol)
+{
+ create_reloc (acfg, symbol, NULL, 0);
+ acfg->cur_section->cur_offset += 4;
+}
+
+static void
bin_writer_emit_symbol_diff (MonoImageWriter *acfg, const char *end, const char* start, int offset)
{
create_reloc (acfg, end, start, offset);
@@ -1925,6 +1935,23 @@ asm_writer_emit_int32 (MonoImageWriter *acfg, int value)
}
static void
+asm_writer_emit_symbol (MonoImageWriter *acfg, const char *symbol)
+{
+ if (acfg->mode != EMIT_LONG) {
+ acfg->mode = EMIT_LONG;
+ acfg->col_count = 0;
+ }
+
+ symbol = get_label (symbol);
+
+ if ((acfg->col_count++ % 8) == 0)
+ fprintf (acfg->fp, "\n\t%s ", AS_INT32_DIRECTIVE);
+ else
+ fprintf (acfg->fp, ",");
+ fprintf (acfg->fp, "%s", symbol);
+}
+
+static void
asm_writer_emit_symbol_diff (MonoImageWriter *acfg, const char *end, const char* start, int offset)
{
#ifdef TARGET_ASM_APPLE
@@ -2214,6 +2241,19 @@ mono_img_writer_emit_int32 (MonoImageWriter *acfg, int value)
}
void
+mono_img_writer_emit_symbol (MonoImageWriter *acfg, const char *symbol)
+{
+#ifdef USE_BIN_WRITER
+ if (acfg->use_bin_writer)
+ bin_writer_emit_symbol (acfg, symbol);
+ else
+ asm_writer_emit_symbol (acfg, symbol);
+#else
+ asm_writer_emit_symbol (acfg, symbol);
+#endif
+}
+
+void
mono_img_writer_emit_symbol_diff (MonoImageWriter *acfg, const char *end, const char* start, int offset)
{
#ifdef USE_BIN_WRITER
diff --git a/mono/mini/image-writer.h b/mono/mini/image-writer.h
index 0c34246422e..309ec37c059 100644
--- a/mono/mini/image-writer.h
+++ b/mono/mini/image-writer.h
@@ -98,6 +98,8 @@ void mono_img_writer_emit_int16 (MonoImageWriter *w, int value);
void mono_img_writer_emit_int32 (MonoImageWriter *w, int value);
+void mono_img_writer_emit_symbol (MonoImageWriter *w, const char *symbol);
+
void mono_img_writer_emit_symbol_diff (MonoImageWriter *w, const char *end, const char* start, int offset);
void mono_img_writer_emit_zero_bytes (MonoImageWriter *w, int num);