Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions llvm/tools/llvm-profgen/ProfiledBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "MissingFrameInferrer.h"
#include "Options.h"
#include "ProfileGenerator.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
Expand Down Expand Up @@ -246,6 +248,17 @@ void ProfiledBinary::load() {
// Find the preferred load address for text sections.
setPreferredTextSegmentAddresses(Obj);

// For shared libraries, read build ID to filter perfscript addresses
// in [buildid:]addr format. Main executables use empty FilterBuildID
// since their addresses have no buildid prefix.
file_magic Magic;
if (auto EC = identify_magic(Path, Magic);
!EC && Magic == file_magic::elf_shared_object) {
auto BID = object::getBuildID(Obj);
if (!BID.empty())
FilterBuildID = llvm::toHex(BID, /*LowerCase=*/true);
}

// Load debug info of subprograms from DWARF section.
// If path of debug info binary is specified, use the debug info from it,
// otherwise use the debug info from the executable binary.
Expand Down
9 changes: 9 additions & 0 deletions llvm/tools/llvm-profgen/ProfiledBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Object/BuildID.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -337,6 +338,11 @@ class ProfiledBinary {

bool IsCOFF = false;

// Build ID used to filter perfscript addresses in [buildid:]addr format.
// For shared libraries, set to the binary's build ID.
// For main executables, kept empty (addresses have no buildid prefix).
std::string FilterBuildID;

void setPreferredTextSegmentAddresses(const object::ObjectFile *O);

// LLVMSymbolizer's symbolize{Code, Data} interfaces requires a section index
Expand Down Expand Up @@ -425,6 +431,9 @@ class ProfiledBinary {

bool isCOFF() const { return IsCOFF; }

// Return the build ID used for filtering perfscript addresses.
StringRef getFilterBuildID() const { return FilterBuildID; }

// Canonicalize to use preferred load address as base address.
uint64_t canonicalizeVirtualAddress(uint64_t Address) {
return Address - BaseAddress + getPreferredBaseAddress();
Expand Down