This is the mail archive of the mailing list for the GDB 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]

Avoid potential crashes with --gc-sections and low addresses


The attached patch deals with a problem that occurs with some embedded
targets when the linker garbage collection feature of GNU ld
(--gc-sections) is used.

Linker gc can cause DWARF2 debug info for eliminated functions and frames
to be retained in the binary, but with the location set to 0. This works
most of the time. The problem occurs when there is retained valid code with
a location close to 0, as can happen on an embedded target.

In dwarf2_frame_find_fde we have:
      while (fde)
	  if (*pc >= fde->initial_location + offset
	      && *pc < fde->initial_location + offset + fde->address_range)
	      *pc = fde->initial_location + offset;
	      return fde;

	  fde = fde->next;

In most executables on other targets, eliminated code would not match this,
but when there is code close to 0, the pc comparison test can succeed and
match the debug information for the eliminated code because that code is
within the address range.

The simplest solution is to prevent these sorts of FDEs being loaded in the
 first place, by only incorporating FDEs with non-NULL initial locations,
as per the attached patch. This also avoids using up memory and processing
time for debug info we'll never use.

The patch was in fact written by a colleague, but since it's a one-liner, I
assume copyright assignments are superfluous under the "simple changes"
rule. I do have check-in perms (it's been a while I know) if that helps.


2008-07-27  Bart Veer  <>

	* dwarf2-frame.c (decode_frame_entry_1): Only add FDE if it has
	a valid location.

eCosCentric Limited     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine

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