Q: Relocating (what we can of) a section

Daniel Jacobowitz drow@mvista.com
Sat Mar 23 11:57:00 GMT 2002


GDB nominally supports adding an unlinked object file's symbols and debug
information to a debugging session (add-symbol-file).  This is useful; for
instance, debugging Linux kernel modules.  However, it's got some problems.

Particularly: there are relocations in both the code and in the debug info. 
We don't care about the relocations in the code especially (although I
suppose it may confuse GDB if we're in software-single-step later; but we
generally get that information from target memory directly, for exactly this
reason among others).  Relocations in the debug info are pesky, though.  GDB
fakes supporting relocation against section symbols, by looking up symbols
in the actual symbol table as it encounters them in the debug info, and
adding offsets based on the section offsets (which GDB is told) of the
section the symbol is actually in.  This works for things like shared
libraries, where the relocations for static symbols will be generally
reduced to section + offset.

It doesn't work for object files, when you have something like:
     DW_AT_location    : 5 byte block: 3 0 0 0 0        (DW_OP_addr: 0; )
and:
00015d47  00000c01 R_PPC_ADDR32          00000001  f_Symbol	+ 0

The symbol's address is 0x1 (unlike a section symbol, which would have 0x0).


insmod has some very lightweight code to fix up this sort of thing.  BFD
does not appear to, which is a real shame; duplicating something of this
nature into GDB seems like a real waste.  Is the code I need available in
BFD in some (existing, or reasonably implementable) interface?

I suppose I could get roughly the right effect by "linking" into a shared
library.  This isn't really practical - although with an appropriately
hand-crafted link map containing only the sections I am interested in, I do
get just about the right results.

Better ideas, anyone?

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer



More information about the Binutils mailing list