public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Ulf Hermann <ulf.hermann@qt.io>
To: Mark Wielaard <mark@klomp.org>, elfutils-devel@sourceware.org
Cc: Christoph Sterz <christoph.sterz@kdab.com>
Subject: Re: Handling pgoff in perf elf mmap/mmap2 elf info
Date: Fri, 21 Sep 2018 13:35:00 -0000	[thread overview]
Message-ID: <edebd174-de25-8f5b-9de9-ec3967aade96@qt.io> (raw)
In-Reply-To: <1537535249.6167.23.camel@klomp.org>

> OK, so pgoff is like the offset argument of the mmap call?

As far as I understand it, yes.

> Is it just recording all user space mmap events that have PROT_EXEC in
> their prot argument? 

It just records all mmap events, also the ones without PROT_EXEC.

We check in perfparser if the file in question is supposed to be an elf 
file and consider everything that looks like one for later reporting to 
dwfl. We then report modules on demand, though. So, if no sample ever 
touches a module, the module doesn't get reported. Mmaps without 
PROT_EXEC shouldn't show up in any samples, except if the trace data is 
bad in some other way. But then, if we reported to dwfl a module that 
isn't actually linked in the target application but still mapped to a 
place in memory, that wouldn't disturb the unwinding for other modules. 
Would it?

We can probably determine the initial PROT_EXEC state for some mmaps, 
though. There are two possible variants of mmap events in the perf 
trace, one of which has a "prot" field. However, I don't know if we can 
rely on that being present in traces from the systems in question.

> What about if the mapping was later changed with mprotect? 

We don't get separate events for mprotect, so the "prot" field is 
probably worthless.

> Or does PERF_RECORD_MMAP only map to some internal kernel mmap action?

I don't know exactly where the mmap events are generated, but it has to 
be somewhere in the kernel. That is how perf_event_open operates, and, 
by extension, how perf gets its data. We might get some synthesized mmap 
events generated from the current memory map of an application when we 
attach while it's already running. I don't quite know how that works.

> dwfl_report_elf indeed does assume the whole ELF file is mapped in
> according to the PHDRs in the file and the given base address. But what
> you are actually seeing (I think, depending on the answers on the
> questions above) is the dynamic loader mapping in the file in pieces.

Yes, that is my interpretation of the (limited) data I have. Maybe 
Christoph can add something here.

> And so you would like an interface where you can report the module
> piece wise while it is being mapped in. So what would be most
> convenient would be some kind of dwfl_report_elf_mmap function that you
> can use to either get a new Dwfl_Module or to extend an existing one.

That sounds about right.

> I have to think how that interacts with mprotect and mmunmap.

We don't get any extra events for mprotect and munmap. If we detect an 
address space conflict between different modules, we just throw out the 
dwfl state and restart the reporting. (I know, there is a potential for 
optimization here: We could use the callback to dwfl_report_end and only 
throw out the conflicting modules.)

cheers,
Ulf

  reply	other threads:[~2018-09-21 13:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19 12:12 Christoph Sterz
2018-09-19 12:24 ` Ulf Hermann
2018-09-21 13:07   ` Mark Wielaard
2018-09-21 13:35     ` Ulf Hermann [this message]
2018-09-26 14:38     ` Milian Wolff
2018-10-09 20:33       ` Milian Wolff
2018-10-11 17:02         ` Ulf Hermann
2018-10-11 17:37           ` Mark Wielaard
2018-10-11 18:14             ` Milian Wolff
2018-10-15 20:39               ` Milian Wolff
2018-10-15 21:05                 ` Mark Wielaard
2018-10-15 21:06                   ` Milian Wolff
2018-10-17 14:52                     ` Milian Wolff
2018-10-17 22:26                       ` Mark Wielaard
2018-10-18  7:41                 ` Ulf Hermann
2018-10-20 10:49                 ` Milian Wolff
2018-10-15 20:48               ` Milian Wolff

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=edebd174-de25-8f5b-9de9-ec3967aade96@qt.io \
    --to=ulf.hermann@qt.io \
    --cc=christoph.sterz@kdab.com \
    --cc=elfutils-devel@sourceware.org \
    --cc=mark@klomp.org \
    /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).