Improve ODR checking in gold.
authorCary Coutant <ccoutant@google.com>
Thu, 9 Apr 2015 18:52:21 +0000 (11:52 -0700)
committerCary Coutant <ccoutant@google.com>
Thu, 9 Apr 2015 18:53:01 +0000 (11:53 -0700)
gold/
* debug.h (DEBUG_LOCATION): New.
(DEBUG_ALL): Include DEBUG_LOCATION.
(debug_string_to_enum): Add DEBUG_LOCATION.
* dwarf_reader.cc (Sized_dwarf_line_info::read_lines): Fix debug
output to print correct context.
(Sized_dwarf_line_info::do_addr2line): Add debug output. Return
up to 4 more locations at the beginning of the function.
* symtab.cc (Symbol_table::detect_odr_violations): Get canonical
result before sorting list of line numbers.
* testsuite/debug_msg.sh: Allow range of line numbers for
canonical results on optimized code.

gold/ChangeLog
gold/debug.h
gold/dwarf_reader.cc
gold/symtab.cc
gold/testsuite/debug_msg.sh

index fa82e421e0c77dbf98a289732e635e224a2b1c16..9943cf50a1ee814e38f3b8520cc36f5f50097f07 100644 (file)
@@ -1,3 +1,17 @@
+2015-04-09  Cary Coutant  <ccoutant@google.com>
+
+       * debug.h (DEBUG_LOCATION): New.
+       (DEBUG_ALL): Include DEBUG_LOCATION.
+       (debug_string_to_enum): Add DEBUG_LOCATION.
+       * dwarf_reader.cc (Sized_dwarf_line_info::read_lines): Fix debug
+       output to print correct context.
+       (Sized_dwarf_line_info::do_addr2line): Add debug output. Return
+       up to 4 more locations at the beginning of the function.
+       * symtab.cc (Symbol_table::detect_odr_violations): Get canonical
+       result before sorting list of line numbers.
+       * testsuite/debug_msg.sh: Allow range of line numbers for
+       canonical results on optimized code.
+
 2015-04-07  HC Yen <hc.yen@mediatek.com>
 
        Add AArch32 support for gold linker.
index bca55f3798ddf4e445e49ccc0987dd63f4b26c32..3fecbd8bf054779b75bb7c18b3997316160a8cc4 100644 (file)
@@ -38,9 +38,11 @@ const int DEBUG_SCRIPT = 0x2;
 const int DEBUG_FILES = 0x4;
 const int DEBUG_RELAXATION = 0x8;
 const int DEBUG_INCREMENTAL = 0x10;
+const int DEBUG_LOCATION = 0x20;
 
 const int DEBUG_ALL = (DEBUG_TASK | DEBUG_SCRIPT | DEBUG_FILES
-                      | DEBUG_RELAXATION | DEBUG_INCREMENTAL);
+                      | DEBUG_RELAXATION | DEBUG_INCREMENTAL
+                      | DEBUG_LOCATION);
 
 // Convert a debug string to the appropriate enum.
 inline int
@@ -54,6 +56,7 @@ debug_string_to_enum(const char* arg)
     { "files", DEBUG_FILES },
     { "relaxation", DEBUG_RELAXATION },
     { "incremental", DEBUG_INCREMENTAL },
+    { "location", DEBUG_LOCATION },
     { "all", DEBUG_ALL }
   };
 
index e7c95ce64975be9dfdf3bc0dfd8a3e5153d97a22..59b85b8bb41cf6ca2831da8c7915eb219adab55f 100644 (file)
@@ -2205,13 +2205,33 @@ Sized_dwarf_line_info<size, big_endian>::do_addr2line(
     return "";
 
   std::string result = this->format_file_lineno(*it);
+  gold_debug(DEBUG_LOCATION, "do_addr2line: canonical result: %s",
+            result.c_str());
   if (other_lines != NULL)
-    for (++it; it != offsets->end() && it->offset == offset; ++it)
-      {
-        if (it->line_num == -1)
-          continue;  // The end of a previous function.
-        other_lines->push_back(this->format_file_lineno(*it));
-      }
+    {
+      unsigned int last_file_num = it->file_num;
+      int last_line_num = it->line_num;
+      // Return up to 4 more locations from the beginning of the function
+      // for fuzzy matching.
+      for (++it; it != offsets->end(); ++it)
+       {
+         if (it->offset == offset && it->line_num == -1)
+           continue;  // The end of a previous function.
+         if (it->line_num == -1)
+           break;  // The end of the current function.
+         if (it->file_num != last_file_num || it->line_num != last_line_num)
+           {
+             other_lines->push_back(this->format_file_lineno(*it));
+             gold_debug(DEBUG_LOCATION, "do_addr2line: other: %s",
+                        other_lines->back().c_str());
+             last_file_num = it->file_num;
+             last_line_num = it->line_num;
+           }
+         if (it->offset > offset && other_lines->size() >= 4)
+           break;
+       }
+    }
+
   return result;
 }
 
index 045327ac310c378d192e4a1cbd665aaeb0caade7..88e932268ed20649a57786341ca47a530377d445 100644 (file)
@@ -3336,8 +3336,11 @@ Symbol_table::detect_odr_violations(const Task* task,
           first_object_name = locs->object->name();
           first_object_linenos = this->linenos_from_loc(task, *locs);
         }
+      if (first_object_linenos.empty())
+       continue;
 
       // Sort by Odr_violation_compare to make std::set_intersection work.
+      std::string first_object_canonical_result = first_object_linenos.back();
       std::sort(first_object_linenos.begin(), first_object_linenos.end(),
                 Odr_violation_compare());
 
@@ -3349,6 +3352,8 @@ Symbol_table::detect_odr_violations(const Task* task,
           if (linenos.empty())
             continue;
           // Sort by Odr_violation_compare to make std::set_intersection work.
+          gold_assert(!linenos.empty());
+          std::string second_object_canonical_result = linenos.back();
           std::sort(linenos.begin(), linenos.end(), Odr_violation_compare());
 
           Check_intersection intersection_result =
@@ -3367,13 +3372,11 @@ Symbol_table::detect_odr_violations(const Task* task,
               // which may not be the location we expect to intersect
               // with another definition.  We could print the whole
               // set of locations, but that seems too verbose.
-              gold_assert(!first_object_linenos.empty());
-              gold_assert(!linenos.empty());
               fprintf(stderr, _("  %s from %s\n"),
-                      first_object_linenos[0].c_str(),
+                      first_object_canonical_result.c_str(),
                       first_object_name.c_str());
               fprintf(stderr, _("  %s from %s\n"),
-                      linenos[0].c_str(),
+                      second_object_canonical_result.c_str(),
                       locs->object->name().c_str());
               // Only print one broken pair, to avoid needing to
               // compare against a list of the disjoint definition
index 785e5c5f3e7db599a2b883ab1c4a614d5f530313..54c72f1428053a816b33e206dd34cb274884d34f 100755 (executable)
@@ -74,7 +74,7 @@ fi
 # Check we detected the ODR (One Definition Rule) violation.
 check debug_msg.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
 check debug_msg.err "odr_violation1.cc:6"
-check debug_msg.err "odr_violation2.cc:12"
+check debug_msg.err "odr_violation2.cc:1[25]"
 
 # Check we don't have ODR false positives:
 check_missing debug_msg.err "OdrDerived::~OdrDerived()"
@@ -88,7 +88,7 @@ check_missing debug_msg.err "odr_violation1.cc:16"
 check_missing debug_msg.err "odr_violation2.cc:23"
 check debug_msg.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
 check debug_msg.err "debug_msg.cc:68"
-check debug_msg.err "odr_violation2.cc:27"
+check debug_msg.err "odr_violation2.cc:2[78]"
 
 # Check for the same error messages when using --compressed-debug-sections.
 if test -r debug_msg_cdebug.err
@@ -106,7 +106,7 @@ then
   fi
   check debug_msg_cdebug.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
   check debug_msg_cdebug.err "odr_violation1.cc:6"
-  check debug_msg_cdebug.err "odr_violation2.cc:12"
+  check debug_msg_cdebug.err "odr_violation2.cc:1[25]"
   check_missing debug_msg_cdebug.err "OdrDerived::~OdrDerived()"
   check_missing debug_msg_cdebug.err "__adjust_heap"
   check_missing debug_msg_cdebug.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
@@ -114,7 +114,7 @@ then
   check_missing debug_msg_cdebug.err "odr_violation2.cc:23"
   check debug_msg_cdebug.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
   check debug_msg_cdebug.err "debug_msg.cc:68"
-  check debug_msg_cdebug.err "odr_violation2.cc:27"
+  check debug_msg_cdebug.err "odr_violation2.cc:2[78]"
 fi
 
 # When linking together .so's, we don't catch the line numbers, but we
@@ -124,7 +124,7 @@ check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn2()
 check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_int'"
 check debug_msg_so.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
 check debug_msg_so.err "odr_violation1.cc:6"
-check debug_msg_so.err "odr_violation2.cc:12"
+check debug_msg_so.err "odr_violation2.cc:1[25]"
 check_missing debug_msg_so.err "OdrDerived::~OdrDerived()"
 check_missing debug_msg_so.err "__adjust_heap"
 check_missing debug_msg_so.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
@@ -132,7 +132,7 @@ check_missing debug_msg_so.err "odr_violation1.cc:16"
 check_missing debug_msg_so.err "odr_violation2.cc:23"
 check debug_msg_so.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
 check debug_msg_so.err "debug_msg.cc:68"
-check debug_msg_so.err "odr_violation2.cc:27"
+check debug_msg_so.err "odr_violation2.cc:2[78]"
 
 # These messages shouldn't need any debug info to detect:
 check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_fn1()'"
This page took 0.057727 seconds and 4 git commands to generate.