This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap 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]

dwfl_module_relocate_address() versus base address


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.


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