forked from OSchip/llvm-project
[BOLT][CSSPGO] Pseudo probe decoding
Summary: Make bolt decode pseudo probe section in binary For more detail of pseudo probe, check https://reviews.llvm.org/D86490. (cherry picked from FBD28856316)
This commit is contained in:
parent
226d1c3b0b
commit
8a919593c7
|
@ -31,6 +31,7 @@
|
|||
#include "llvm/MC/MCInstrInfo.h"
|
||||
#include "llvm/MC/MCObjectFileInfo.h"
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
#include "llvm/MC/MCPseudoProbe.h"
|
||||
#include "llvm/MC/MCSectionELF.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
|
@ -591,6 +592,9 @@ public:
|
|||
/// special linux kernel sections
|
||||
std::unordered_map<uint64_t, std::vector<LKInstructionMarkerInfo>> LKMarkers;
|
||||
|
||||
/// PseudoProbe decoder
|
||||
MCPseudoProbeDecoder ProbeDecoder;
|
||||
|
||||
/// DWARF encoding. Available encoding types defined in BinaryFormat/Dwarf.h
|
||||
/// enum Constants, e.g. DW_EH_PE_omit.
|
||||
unsigned TTypeEncoding = dwarf::DW_EH_PE_omit;
|
||||
|
|
|
@ -272,6 +272,11 @@ PrintSDTMarkers("print-sdt",
|
|||
cl::Hidden,
|
||||
cl::cat(BoltCategory));
|
||||
|
||||
static cl::opt<bool>
|
||||
PrintPseudoProbe("print-pseudo-probe",
|
||||
cl::desc("print pseudo probe related info"),
|
||||
cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
|
||||
|
||||
static cl::opt<cl::boolOrDefault>
|
||||
RelocationMode("relocs",
|
||||
cl::desc("use relocations in the binary (default=autodetect)"),
|
||||
|
@ -684,6 +689,40 @@ void RewriteInstance::parseSDTNotes() {
|
|||
printSDTMarkers();
|
||||
}
|
||||
|
||||
void RewriteInstance::parsePseudoProbe() {
|
||||
if (!PseudoProbeDescSection && !PseudoProbeSection)
|
||||
// pesudo probe is not added to binary. It is normal and no warning needed.
|
||||
return;
|
||||
// If only one section is found, it might mean the ELF is corrupted.
|
||||
if (!PseudoProbeDescSection) {
|
||||
errs() << "BOLT-WARNING: fail in reading .pseudo_probe_desc binary\n";
|
||||
return;
|
||||
} else if (!PseudoProbeSection) {
|
||||
errs() << "BOLT-WARNING: fail in reading .pseudo_probe binary\n";
|
||||
return;
|
||||
}
|
||||
|
||||
StringRef Contents = PseudoProbeDescSection->getContents();
|
||||
if (!BC->ProbeDecoder.buildGUID2FuncDescMap(
|
||||
reinterpret_cast<const uint8_t *>(Contents.data()),
|
||||
Contents.size())) {
|
||||
errs() << "BOLT-WARNING: fail in building GUID2FuncDescMap\n";
|
||||
return;
|
||||
}
|
||||
Contents = PseudoProbeSection->getContents();
|
||||
if (!BC->ProbeDecoder.buildAddress2ProbeMap(
|
||||
reinterpret_cast<const uint8_t *>(Contents.data()),
|
||||
Contents.size())) {
|
||||
errs() << "BOLT-WARNING: fail in building Address2ProbeMap\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts::PrintPseudoProbe) {
|
||||
BC->ProbeDecoder.printGUID2FuncDescMap(outs());
|
||||
BC->ProbeDecoder.printProbesForAllAddresses(outs());
|
||||
}
|
||||
}
|
||||
|
||||
void RewriteInstance::printSDTMarkers() {
|
||||
outs() << "BOLT-INFO: Number of SDT markers is " << BC->SDTMarkers.size()
|
||||
<< "\n";
|
||||
|
@ -1546,6 +1585,8 @@ void RewriteInstance::readSpecialSections() {
|
|||
RelaDynSection = BC->getUniqueSectionByName(".rela.dyn");
|
||||
BuildIDSection = BC->getUniqueSectionByName(".note.gnu.build-id");
|
||||
SDTSection = BC->getUniqueSectionByName(".note.stapsdt");
|
||||
PseudoProbeDescSection = BC->getUniqueSectionByName(".pseudo_probe_desc");
|
||||
PseudoProbeSection = BC->getUniqueSectionByName(".pseudo_probe");
|
||||
|
||||
if (ErrorOr<BinarySection &> BATSec =
|
||||
BC->getUniqueSectionByName(BoltAddressTranslation::SECTION_NAME)) {
|
||||
|
@ -1597,6 +1638,8 @@ void RewriteInstance::readSpecialSections() {
|
|||
|
||||
parseSDTNotes();
|
||||
|
||||
parsePseudoProbe();
|
||||
|
||||
// Read .dynamic/PT_DYNAMIC.
|
||||
readELFDynamic();
|
||||
}
|
||||
|
|
|
@ -331,6 +331,10 @@ private:
|
|||
/// Parse .note.stapsdt section
|
||||
void parseSDTNotes();
|
||||
|
||||
/// Parse .pseudo_probe_desc section and .pseudo_probe section
|
||||
/// Setup Pseudo probe decoder
|
||||
void parsePseudoProbe();
|
||||
|
||||
/// Print all SDT markers
|
||||
void printSDTMarkers();
|
||||
|
||||
|
@ -461,6 +465,15 @@ private:
|
|||
/// Contains information about statically defined tracing points
|
||||
ErrorOr<BinarySection &> SDTSection{std::errc::bad_address};
|
||||
|
||||
/// .pseudo_probe_desc section.
|
||||
/// Contains information about pseudo probe description, like its related
|
||||
/// function
|
||||
ErrorOr<BinarySection &> PseudoProbeDescSection{std::errc::bad_address};
|
||||
|
||||
/// .pseudo_probe section.
|
||||
/// Contains information about pseudo probe details, like its address
|
||||
ErrorOr<BinarySection &> PseudoProbeSection{std::errc::bad_address};
|
||||
|
||||
/// A reference to the build-id bytes in the original binary
|
||||
StringRef BuildID;
|
||||
|
||||
|
|
Loading…
Reference in New Issue