patch for bfd/dwarf2.c, problem if .debug_info section was relocated

Stephane Carrez
Tue Feb 22 12:40:00 GMT 2000


I've found a small problem in bfd/dwarf2.c. If I wrote a linker
script that had all the *(.debug_info) sections at beginning, and I had
some undefined symbols during the link, the linker would abort without
any message.

If I write such bad linker script, the .debug_info sections gets relocated
before the undefined symbols are reported. In bfd/dwarf2.c, we call
'bfd_get_section_size_before_reloc' which aborts.

I propose the following fix that checks this situation before aborting
and print an error message. We also don't need to abort: in that case
the dwarf-2 debugging info can simply be ignored. The linker will print
the undefined symbol without the file/line information.

Can you integrate this patch?


2000-02-22  Stephane Carrez  <>

	* dwarf2.c (_bfd_dwarf2_find_nearest_line): Don't abort if
	the .debug_info section was relocated, print an error message.
--- /src/gnu/cygnus/binutils/bfd/dwarf2.c	Wed Jul 14 10:49:38 1999
+++ bfd/dwarf2.c	Mon Feb 21 21:05:17 2000
@@ -1516,6 +1516,19 @@ _bfd_dwarf2_find_nearest_line (abfd, sec
 	  return false;
+      /* If the linker relocates some dwarf-2 sections before some others
+	 (.text, .data), we can't find the line of the symbol.	Complain
+	 and pretend there is no dwarf2 info.  Otherwise, the next call to
+	 'bfd_get_section_size_before_reloc' will abort.  This error can
+	 happen when the default indirect link order is used and the linker
+	 script indicates to relocate dwarf2 section before .text.  */
+      if (msec->reloc_done)
+	{
+	  (* _bfd_error_handler)
+	    ("Linker error: the .debug_info section has been relocated");
+	  return false;
+	}
       size = bfd_get_section_size_before_reloc (msec);
       if (size == 0)
 	return false;

More information about the Binutils mailing list