Skip to content

Commit 77e0a25

Browse files
LNT: Only use text segment when isSO.
Limit the segment calculation uses to only when the binary is relocatable.
1 parent 58c7f0d commit 77e0a25

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ static const char* sw_event_names[PERF_COUNT_SW_MAX] = {
361361

362362
struct Map {
363363
uint64_t Start, End, Adjust;
364+
bool isSO;
364365
const char *Filename;
365366
};
366367

@@ -528,10 +529,14 @@ class SymTabOutput : public std::vector<Symbol> {
528529
void reset(Map *M) {
529530
clear();
530531
// Fetch both dynamic and static symbols, sort and unique them.
531-
uint64_t segmentStart = fetchExecSegment (M);
532-
/* Adjust the symbol to a value relative to the start of the load address
533-
to match up with registerNewMapping. */
534-
M->Adjust -= segmentStart;
532+
/* If we're a relocatable object then take the actual start of the text
533+
segment into account. */
534+
if (M->isSO) {
535+
uint64_t segmentStart = fetchExecSegment (M);
536+
/* Adjust the symbol to a value relative to the start of the load address
537+
to match up with registerNewMapping. */
538+
M->Adjust -= segmentStart;
539+
}
535540
fetchSymbols(M);
536541

537542
std::sort(begin(), end());
@@ -852,7 +857,7 @@ void PerfReader::registerNewMapping(unsigned char *Buf, const char *Filename) {
852857
bool IsSO = IsSharedObject(BinaryCacheRoot + std::string(Filename));
853858
uint64_t End = E->start + E->extent;
854859
uint64_t Adjust = IsSO ? E->start - E->pgoff : 0;
855-
Maps.push_back({E->start, End, Adjust, Filename});
860+
Maps.push_back({E->start, End, Adjust, IsSO, Filename});
856861

857862
unsigned char *EndOfEvent = Buf + E->header.size;
858863
// FIXME: The first EventID is used for every event.

0 commit comments

Comments
 (0)