public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: Roland McGrath <roland@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Subject: Re: dwfl_module_relocate_address() versus base address
Date: Mon, 15 Dec 2008 12:07:00 -0000	[thread overview]
Message-ID: <1229342761.3457.13.camel@dijkstra.wildebeest.org> (raw)
In-Reply-To: <20081212200639.23B51FC3AB@magilla.sf.frob.com>

[-- Attachment #1: Type: text/plain, Size: 1026 bytes --]

Hi Roland,

On Fri, 2008-12-12 at 12:06 -0800, Roland McGrath wrote:
> I think dwfl_module_relocate_address might be applying the wrong bias.  It
> subtracts the dwbias, but it should subtract the main file bias.  The
> address you pass it is an absolute address in that Dwfl's address space,
> and what it should yield is the address relative to the first p_vaddr in
> the DSO (i.e. 0 if not prelinked).

Aha! Doh. Yes, things make a lot more sense now. Since older/current
versions of dwfl_module_relocate_address() will have this bug I am using
dwfl_module_address_section() now, which does seem to do the right
thing. Then to get the relative address of the symbol when the code is
mapped in all we need is the section offset. This seems to work fine in
all cases. Although I am still confused how this ever worked before.
Also for the kernel we still do things slightly differently (making
things relative to _stext) . I checked in the following patch to my
pr6866 branch and will be testing more with it.

Thanks,

Mark

[-- Attachment #2: translate.patch --]
[-- Type: text/x-patch, Size: 1481 bytes --]

diff --git a/translate.cxx b/translate.cxx
index 27f6a04..c60d2da 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -4521,11 +4521,24 @@ dump_unwindsyms (Dwfl_Module *m,
               Dwarf_Addr sym_addr = sym.st_value;
               const char *secname = NULL;
 
-              if (n > 0) // only try to relocate if there exist relocation bases
+              // only try to relocate if there exist relocation bases
+              // and not for the kernel, we readjust against _stext,
+              // through extra_offset above.
+              if (n > 0 && modname != "kernel")
                 {
-                  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);
+		  // libdwfl up to 0.137 could miscalculate the relocated
+		  // address for shared ET_DYN files (n > 0). Luckily
+		  // dwfl_module_address_section does work correctly.
+		  // Then we just need to add the section offset to get
+		  // the (relative) address of the symbol when mapped in.
+		  Dwarf_Addr bias;
+		  Elf_Scn *sec;
+		  GElf_Shdr *shdr, shdr_mem;
+		  sec = dwfl_module_address_section (m, &sym_addr, &bias);
+		  dwfl_assert ("dwfl_module_address_section", sec != NULL);
+		  shdr = gelf_getshdr(sec, &shdr_mem);
+		  sym_addr += shdr->sh_offset;
+		  secname = "";
                 }
 
               if (n == 1 && modname == "kernel")

  reply	other threads:[~2008-12-15 12:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-12 17:37 Mark Wielaard
2008-12-12 18:15 ` Mark Wielaard
2008-12-12 20:07 ` Roland McGrath
2008-12-15 12:07   ` Mark Wielaard [this message]
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=1229342761.3457.13.camel@dijkstra.wildebeest.org \
    --to=mjw@redhat.com \
    --cc=roland@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).