diff options
author | mingmingl <mingmingl@google.com> | 2025-07-10 10:46:01 -0700 |
---|---|---|
committer | mingmingl <mingmingl@google.com> | 2025-07-10 10:46:01 -0700 |
commit | d569960a63ac77a6042ea579506dc48373b7da65 (patch) | |
tree | 2f7a70c38fa8a9d32e869b221c093e7e0d542ab7 /llvm/tools/llvm-profgen/ProfiledBinary.cpp | |
parent | c92d5dad67aafded296653c2b9a369a7fe24ba13 (diff) | |
download | llvm-users/mingmingl-llvm/llvm-profgen.zip llvm-users/mingmingl-llvm/llvm-profgen.tar.gz llvm-users/mingmingl-llvm/llvm-profgen.tar.bz2 |
Extend llvm-profgen to generate vtable profilesusers/mingmingl-llvm/llvm-profgen
Diffstat (limited to 'llvm/tools/llvm-profgen/ProfiledBinary.cpp')
-rw-r--r-- | llvm/tools/llvm-profgen/ProfiledBinary.cpp | 40 |
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); |