Don't relocate debug info for discarded linkonce sections

Alan Modra amodra@bigpond.net.au
Wed Feb 15 19:16:00 GMT 2006


This patch effectively reverts a change HJ made on 2003-06-17.  See
http://sources.redhat.com/ml/binutils/2003-06/msg00499.html.  The
problem with relocating debug info for discarded linkonce sections is
that the resulting misplaced addresses confuse gdb.  In particular,
gdb's idea of pc ranges for a given object can be calculated wrongly,
leading to wrong file/line-number info.  To see why, here is a readelf
dump of part of .debug_aranges corresponding to an object file with a
.text section and some .gnu.linkonce.t.* sections.

  Length:                   604
  Version:                  2
  Offset into .debug_info:  247e
  Pointer Size:             8
  Segment Size:             0

    Address  Length
    10002994 7632
    10004764 176
    10004814 56
    1000484c 336
    1000499c 56
    100049d4 336
    10004b24 56
    10004b5c 336
    10004cac 176
    10004d5c 1436
    100052f8 84
    100020d4 92   <==
    1000534c 68
    10005390 76
    100053dc 80
    1000542c 60
    10005468 176
    10005518 176
    100055c8 116
    1000563c 288
    1000575c 92
    100057b8 92
    10005814 76
    10002130 68   <==

Note how the marked entries (for linkonce sections discarded in this
object) point back before the start of the object file (to the kept
linkonce sections).  Now, I think gdb ignores .debug_aranges, but
exactly the same thing happens in other debug sections, so this is why
gdb gets the low pc values wrong.  A wrong low pc of course means that
gdb sees overlapping address ranges, and might choose a line number for
this object rather than the correct line in the overlapped object.

	* elflink.c (_bfd_elf_default_action_discarded): Return 0 for
	debug sections.
	(elf_link_input_bfd): Adjust comments.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.201
diff -u -p -r1.201 elflink.c
--- bfd/elflink.c	17 Jan 2006 15:32:40 -0000	1.201
+++ bfd/elflink.c	15 Feb 2006 14:06:26 -0000
@@ -6691,7 +6691,7 @@ unsigned int
 _bfd_elf_default_action_discarded (asection *sec)
 {
   if (sec->flags & SEC_DEBUGGING)
-    return PRETEND;
+    return 0;
 
   if (strcmp (".eh_frame", sec->name) == 0)
     return 0;
@@ -7007,8 +7007,7 @@ elf_link_input_bfd (struct elf_final_lin
 	     from discarded sections and section symbols from
 	     removed link-once sections.  Complain about relocs
 	     against discarded sections.  Zero relocs against removed
-	     link-once sections.  Preserve debug information as much
-	     as we can.  */
+	     link-once sections.  */
 	  if (!elf_section_ignore_discarded_relocs (o))
 	    {
 	      Elf_Internal_Rela *rel, *relend;
@@ -7080,16 +7079,11 @@ elf_link_input_bfd (struct elf_final_lin
 			   sym_name, o, input_bfd, sec, sec->owner);
 
 		      /* Try to do the best we can to support buggy old
-			 versions of gcc.  If we've warned, or this is
-			 debugging info, pretend that the symbol is
+			 versions of gcc.  Pretend that the symbol is
 			 really defined in the kept linkonce section.
 			 FIXME: This is quite broken.  Modifying the
 			 symbol here means we will be changing all later
-			 uses of the symbol, not just in this section.
-			 The only thing that makes this half reasonable
-			 is that we warn in non-debug sections, and
-			 debug sections tend to come after other
-			 sections.  */
+			 uses of the symbol, not just in this section.  */
 		      if (action & PRETEND)
 			{
 			  asection *kept;

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Binutils mailing list