aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-profgen/ProfiledBinary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-profgen/ProfiledBinary.cpp')
-rw-r--r--llvm/tools/llvm-profgen/ProfiledBinary.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 6847ba1..9adc203 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -336,6 +336,12 @@ void ProfiledBinary::setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj,
PreferredTextSegmentAddresses.push_back(Phdr.p_vaddr &
~(PageSize - 1U));
TextSegmentOffsets.push_back(Phdr.p_offset & ~(PageSize - 1U));
+ } else {
+ PhdrInfo Info;
+ Info.FileOffset = Phdr.p_offset;
+ Info.FileSz = Phdr.p_filesz;
+ Info.vAddr = Phdr.p_vaddr;
+ NonTextPhdrInfo.push_back(Info);
}
}
}
@@ -344,6 +350,32 @@ void ProfiledBinary::setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj,
exitWithError("no executable segment found", FileName);
}
+uint64_t ProfiledBinary::CanonicalizeNonTextAddress(uint64_t Address) {
+ uint64_t FileOffset = 0;
+ for (const auto &MMapEvent : MMapNonTextEvents) {
+ if (MMapEvent.Address <= Address &&
+ Address < MMapEvent.Address + MMapEvent.Size) {
+ // If the address is within the mmap event, return the file offset.
+ FileOffset = Address - MMapEvent.Address + MMapEvent.Offset;
+ break;
+ }
+ }
+ if (FileOffset == 0) {
+ // If the address is not within any mmap event, return the address as is.
+ return Address;
+ }
+ for (const auto &PhdrInfo : NonTextPhdrInfo) {
+ // Check if the file offset is within the non-text segment.
+ if (PhdrInfo.FileOffset <= FileOffset &&
+ FileOffset < PhdrInfo.FileOffset + PhdrInfo.FileSz) {
+ // If it is, return the virtual address of the segment.
+ return PhdrInfo.vAddr + (FileOffset - PhdrInfo.FileOffset);
+ }
+ }
+
+ return Address;
+}
+
void ProfiledBinary::setPreferredTextSegmentAddresses(const COFFObjectFile *Obj,
StringRef FileName) {
uint64_t ImageBase = Obj->getImageBase();
@@ -946,6 +978,14 @@ SampleContextFrameVector ProfiledBinary::symbolize(const InstructionPointer &IP,
return CallStack;
}
+StringRef ProfiledBinary::symbolizeDataAddress(uint64_t Address) {
+ DIGlobal DataDIGlobal = unwrapOrError(
+ Symbolizer->symbolizeData(SymbolizerPath.str(), {Address, 0}),
+ SymbolizerPath);
+ auto It = NameStrings.insert(DataDIGlobal.Name);
+ return StringRef(*It.first);
+}
+
void ProfiledBinary::computeInlinedContextSizeForRange(uint64_t RangeBegin,
uint64_t RangeEnd) {
InstructionPointer IP(this, RangeBegin, true);