PR23425, unresolved symbol diagnostic
authorAlan Modra <amodra@gmail.com>
Tue, 11 Sep 2018 14:20:15 +0000 (23:50 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 14 Sep 2018 11:51:28 +0000 (21:21 +0930)
dwarf2.c code reasonably assumes that debug info is local to a file,
an assumption now violated by gcc, resulting in "DWARF error: invalid
abstract instance DIE ref" or wrong details when attempting to print
linker error messages with file, function and line reported.

This is because find_abstract_instance is only prepared to handle
DW_FORM_ref_addr when the .debug_info section referenced is in the
current file.  When that isn't the case, relocations to access another
file's .debug_info will typically be against a symbol defined at the
start of that .debug_info section, plus an addend.  Since the dwarf2.c
code only considers the current file's debug info, that symbol will be
undefined, resolving to zero.  In effect the ref_addr will wrongly
resolve to the current file's .debug_info.

This patch avoids the problem by treating relocations in debug
sections against undefined symbols in a similar manner to the way
relocations against symbols defined in discarded sections are
resolved.  They result in a zero value (except in .debug_ranges)
regardless of the addend.

PR 23425
* reloc.c (bfd_generic_get_relocated_section_contents): Zero reloc
fields in debug sections when reloc is against an undefined symbol
and called from bfd_simple_get_relocated_section_contents or
similar.
* dwarf2.c (find_abstract_instance): Return true for zero offset
DW_FORM_ref_addr without returning values.

bfd/ChangeLog
bfd/dwarf2.c
bfd/reloc.c

index a4991050cd82422f3bfc6ce567f17d0be20d12d3..bbc8e9f352f9240f039fa780c1f95439538a5398 100644 (file)
@@ -1,3 +1,13 @@
+2018-09-14  Alan Modra  <amodra@gmail.com>
+
+       PR 23425
+       * reloc.c (bfd_generic_get_relocated_section_contents): Zero reloc
+       fields in debug sections when reloc is against an undefined symbol
+       and called from bfd_simple_get_relocated_section_contents or
+       similar.
+       * dwarf2.c (find_abstract_instance): Return true for zero offset
+       DW_FORM_ref_addr without returning values.
+
 2018-09-06  Alan Modra  <amodra@gmail.com>
 
        PR 23570
index 8fadb5c4b62b82eedb122bc993375480be88d465..3b2885599ea2f22d29fd22b8744ec285c59b9663 100644 (file)
@@ -2837,7 +2837,9 @@ find_abstract_instance (struct comp_unit *   unit,
       info_ptr = unit->stash->info_ptr_memory;
       info_ptr_end = unit->stash->info_ptr_end;
       total = info_ptr_end - info_ptr;
-      if (!die_ref || die_ref >= total)
+      if (!die_ref)
+       return TRUE;
+      else if (die_ref >= total)
        {
          _bfd_error_handler
            (_("DWARF error: invalid abstract instance DIE ref"));
index eba6091891272d0d10d92dad4656635f738adcfc..67457418e6ed6358dfd09259fc0fe48a94ef26d8 100644 (file)
@@ -8259,7 +8259,18 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
              goto error_return;
            }
 
-         if (symbol->section && discarded_section (symbol->section))
+         /* Zap reloc field when the symbol is from a discarded
+            section, ignoring any addend.  Do the same when called
+            from bfd_simple_get_relocated_section_contents for
+            undefined symbols in debug sections.  This is to keep
+            debug info reasonably sane, in particular so that
+            DW_FORM_ref_addr to another file's .debug_info isn't
+            confused with an offset into the current file's
+            .debug_info.  */
+         if ((symbol->section != NULL && discarded_section (symbol->section))
+             || (symbol->section == bfd_und_section_ptr
+                 && (input_section->flags & SEC_DEBUGGING) != 0
+                 && link_info->input_bfds == link_info->output_bfd))
            {
              bfd_byte *p;
              static reloc_howto_type none_howto
This page took 0.032302 seconds and 4 git commands to generate.