This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gold commit] Improve warnings for relocations referring to discarded sections


When you get a warning that a relocation refers to a discarded
section, it's notoriously hard to track down the problem, and it
doesn't help that gold only gives you the location of the reference.
I've added information about whether the target was a local symbol or
a global symbol, and either the local symbol index or the global
symbol name. In the case of a local symbol, it's always a compiler or
assembly code error, since references from outside a comdat group to a
local symbol inside a comdat group are strictly forbidden. In the case
of a global symbol, it could be a compiler error or a one-definition
rule violation causing the compiler to emit a different set of symbols
in each CU. This extra information should help the diagnosis.

I'd also like to offer more information about the comdat group --
namely, which object file provided the group we kept, and what the key
symbol was. Unfortunately, by the time we get to the point where we
print this warning, gold has discarded the info we'd need to provide
this.

-cary


2018-04-05  Cary Coutant  <ccoutant@gmail.com>

gold/
        * target-reloc.h (relocate_section): Add local symbol index or global
        symbol name to warning about relocation that refers to discarded
        section.

diff --git a/gold/target-reloc.h b/gold/target-reloc.h
index f52e42f62e..36032fbefb 100644
--- a/gold/target-reloc.h
+++ b/gold/target-reloc.h
@@ -305,6 +305,7 @@ relocate_section(
       const Symbol_value<size> *psymval;
       bool is_defined_in_discarded_section;
       unsigned int shndx;
+      const Symbol* gsym = NULL;
       if (r_sym < local_count
          && (reloc_symbol_changes == NULL
              || (*reloc_symbol_changes)[i] == NULL))
@@ -327,7 +328,6 @@ relocate_section(
        }
       else
        {
-         const Symbol* gsym;
          if (reloc_symbol_changes != NULL
              && (*reloc_symbol_changes)[i] != NULL)
            gsym = (*reloc_symbol_changes)[i];
@@ -383,9 +383,24 @@ relocate_section(
          else
            {
              if (comdat_behavior == CB_WARNING)
-               gold_warning_at_location(relinfo, i, offset,
-                                        _("relocation refers to discarded "
-                                          "section"));
+               {
+                 if (gsym == NULL)
+                   {
+                     gold_warning_at_location(
+                         relinfo, i, offset,
+                         _("relocation refers to local symbol %d "
+                           "defined in discarded section"),
+                         r_sym);
+                   }
+                 else
+                   {
+                     gold_warning_at_location(
+                         relinfo, i, offset,
+                         _("relocation refers to symbol \"%s\" "
+                           "defined in discarded section"),
+                         gsym->demangled_name().c_str());
+                   }
+               }
              symval2.set_output_value(0);
            }
          symval2.set_no_output_symtab_entry();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]