[BOLT][perf2bolt] Fix base address calculation for shared objects
authorMaksim Panchenko <maks@fb.com>
Thu, 14 Apr 2022 02:39:39 +0000 (19:39 -0700)
committerMaksim Panchenko <maks@fb.com>
Thu, 14 Apr 2022 17:29:53 +0000 (10:29 -0700)
commit77b75ca53f464d4400d0b86458f97037b35a4999
treee3e34387de0359a58a0f74628b3522f119f971f6
parent48fbcedb385d5086dff5cb1cefd35b94f786d338
[BOLT][perf2bolt] Fix base address calculation for shared objects

When processing profile data for shared object or PIE, perf2bolt needs
to calculate base address of the binary based on the map info reported
by the perf tool. When the mapping data provided is for the second
(or any other than the first) segment and the segment's file offset
does not match its memory offset, perf2bolt uses wrong assumption
about the binary base address.

Add a function to calculate binary base address using the reported
memory mapping and use the returned base for further address
adjustments.

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D123755
bolt/include/bolt/Core/BinaryContext.h
bolt/include/bolt/Profile/DataAggregator.h
bolt/lib/Core/BinaryContext.cpp
bolt/lib/Profile/DataAggregator.cpp
bolt/unittests/Core/BinaryContext.cpp [new file with mode: 0644]
bolt/unittests/Core/CMakeLists.txt