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 patch committed: Only keep second of same offset DWARF


When an entry in the DWARF line number table has the same offset as the
previous entry, we should only keep the second entry.  That is what
other DWARF readers do.  This patch implements that.  Committed to
mainline.

Ian


2010-12-20  Ian Lance Taylor  <iant@google.com>

	* dwarf_reader.cc (Sized_dwarf_line_info::read_lines): Only keep
	second of two consecutive entries with same offset.


Index: dwarf_reader.h
===================================================================
RCS file: /cvs/src/src/gold/dwarf_reader.h,v
retrieving revision 1.18
diff -p -u -r1.18 dwarf_reader.h
--- dwarf_reader.h	1 Dec 2010 19:49:22 -0000	1.18
+++ dwarf_reader.h	20 Dec 2010 17:57:47 -0000
@@ -46,7 +46,10 @@ struct Offset_to_lineno_entry
   int header_num;  // which file-list to use (i.e. which .o file are we in)
   int file_num;    // a pointer into files_
   int line_num;    // the line number in the source file
-  // Offsets are unique within a section, so that's a sufficient sort key.
+
+  // When we add entries to the table, we always use the last entry
+  // with a given offset.  Given proper DWARF info, this should ensure
+  // that the offset is a sufficient sort key.
   bool operator<(const Offset_to_lineno_entry& that) const
   { return this->offset < that.offset; }
 };
Index: dwarf_reader.cc
===================================================================
RCS file: /cvs/src/src/gold/dwarf_reader.cc,v
retrieving revision 1.30
diff -p -u -r1.30 dwarf_reader.cc
--- dwarf_reader.cc	14 Dec 2010 19:03:29 -0000	1.30
+++ dwarf_reader.cc	20 Dec 2010 17:57:50 -0000
@@ -493,7 +493,18 @@ Sized_dwarf_line_info<size, big_endian>:
               Offset_to_lineno_entry entry
                   = { lsm.address, this->current_header_index_,
                       lsm.file_num, lsm.line_num };
-              line_number_map_[lsm.shndx].push_back(entry);
+	      std::vector<Offset_to_lineno_entry>&
+		map(this->line_number_map_[lsm.shndx]);
+	      // If we see two consecutive entries with the same
+	      // offset and a real line number, then always use the
+	      // second one.
+	      if (!map.empty()
+		  && (map.back().offset == static_cast<off_t>(lsm.address))
+		  && lsm.line_num != -1
+		  && map.back().line_num != -1)
+		map.back() = entry;
+	      else
+		map.push_back(entry);
             }
           lineptr += oplength;
         }

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