public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* dwfl_module_relocate_address() versus base address
@ 2008-12-12 17:37 Mark Wielaard
  2008-12-12 18:15 ` Mark Wielaard
  2008-12-12 20:07 ` Roland McGrath
  0 siblings, 2 replies; 12+ messages in thread
From: Mark Wielaard @ 2008-12-12 17:37 UTC (permalink / raw)
  To: systemtap

Hi,

I am slightly confused when dwfl_module_relocate_address() strips off
the base address and when not. In translate.cxx we have
dump_unwindsyms() which is the callback for dwfl_getmodules(). We are
trying to build a symbol table here that is relative to the base
address. We do this by calling dwfl_module_relocate_address(), which
will return the address without the given base, but only for shared
libraries where there is a dwbias (according to dwfl_module_info()).
This is the case for example for glibc. But for other shared libraries
(*) dwbias is -1 and so the address isn't made relative to the base
address. So we end up in stap-symbols.h with some shared library modules
having a symbol section that is relative to the module base address and
others that aren't.

To work around this I now have the following patch which seems to work
in all cases, but I am not completely clear why:

diff --git a/translate.cxx b/translate.cxx
index 27f6a04..88f01ac 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -4523,9 +4523,17 @@ dump_unwindsyms (Dwfl_Module *m,
 
               if (n > 0) // only try to relocate if there exist relocation base
                 {
+                  Dwarf_Addr dwbias;
                   int ki = dwfl_module_relocate_address (m, &sym_addr);
                   dwfl_assert ("dwfl_module_relocate_address", ki >= 0);
                   secname = dwfl_module_relocation_info (m, ki, NULL);
+
+                  // Check whether the relocation took dwbias into account,
+                  // if not, we need to adjust the address by hand.
+                  dwfl_module_info (m, NULL, NULL, NULL, &dwbias,
+                                    NULL, NULL, NULL);
+                  if (dwbias == (Dwarf_Addr) -1)
+                    extra_offset = base;
                 }
 
               if (n == 1 && modname == "kernel")


If anybody could enlighten me that would be appreciated.

Cheers,

Mark

(*) A simple reproducer, without the above patch applied, is compiling
this little library:

$ gcc usymbols_lib.c -fPIC -shared -o libusymbols.so

And doing:
$ stap -k -d /lib/libc.so.6 -d `pwd`/libusymbols.so \
	-e 'probe begin {exit()}'

Where usymbols_lib.c contains just one function like:

void lib_main () {}

You will see that the stap-symbols.h file will contain libusymbols
addresses that have dwarf_module_base added, while the libc symbol
addresses don't have those.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-12-18 23:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-12 17:37 dwfl_module_relocate_address() versus base address Mark Wielaard
2008-12-12 18:15 ` Mark Wielaard
2008-12-12 20:07 ` Roland McGrath
2008-12-15 12:07   ` Mark Wielaard
2008-12-15 13:42     ` Mark Wielaard
2008-12-16  9:12     ` Roland McGrath
2008-12-16 13:28       ` Mark Wielaard
2008-12-16 23:06         ` Roland McGrath
2008-12-17 15:37           ` Mark Wielaard
2008-12-18  0:00             ` Roland McGrath
2008-12-18 14:50               ` Mark Wielaard
2008-12-18 23:59                 ` Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).