[PATCH] D113648: Respect pgoff and rely on it for all types of binaries

Pavel Kosov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 10 22:53:58 PST 2021


kpdev42 created this revision.
kpdev42 added reviewers: thopre, cmatthews, danilaml.
kpdev42 added a project: LLVM.
Herald added subscribers: dkolesnichenko, wenlei.
kpdev42 requested review of this revision.

This fixes incorrect attribution of events to symbols for ET_DYN objects (shared libraries and PIEs), and also simplifies the code.

Generally, the program linker assigns virtual addresses to segments, and virtual addresses of symbols stored in ELF are also in terms of that.
Upon mmapping a segment, its first byte conicides with the start of the memory mapping.
So to get the value of the program counter in terms of the DSO's virtual addresses, one has to add the virtual address of the segment to the raw PC's offset from the start of the mapping.
Like it is done in perf (see linux/tools/perf/util/map.h):

static inline u64 map__map_ip(struct map *map, u64 ip)
{

  return ip - map->start + map->pgoff;

}

(The addresses are translated in thread__find_map() via invoking the map_ip callback that has a comment saying /* ip -> dso rip */.)

OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg


Repository:
  rLNT LNT

https://reviews.llvm.org/D113648

Files:
  lnt/testing/profile/cPerf.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113648.386427.patch
Type: text/x-patch
Size: 5031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211111/2ce54a76/attachment.bin>


More information about the llvm-commits mailing list