From: Mark Wielaard <mjw@redhat.com>
To: systemtap <systemtap@sources.redhat.com>
Subject: dwfl_module_relocate_address() versus base address
Date: Fri, 12 Dec 2008 17:37:00 -0000 [thread overview]
Message-ID: <1229103422.3397.98.camel@dijkstra.wildebeest.org> (raw)
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.
next reply other threads:[~2008-12-12 17:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 17:37 Mark Wielaard [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1229103422.3397.98.camel@dijkstra.wildebeest.org \
--to=mjw@redhat.com \
--cc=systemtap@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).