summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cfi-verify
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-cfi-verify')
-rw-r--r--llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp20
-rw-r--r--llvm/tools/llvm-cfi-verify/lib/FileAnalysis.h9
-rw-r--r--llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp10
-rw-r--r--llvm/tools/llvm-cfi-verify/lib/GraphBuilder.h2
-rw-r--r--llvm/tools/llvm-cfi-verify/llvm-cfi-verify.cpp12
5 files changed, 30 insertions, 23 deletions
diff --git a/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp b/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp
index a3750a2735d..ff2ce46a01d 100644
--- a/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp
+++ b/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp
@@ -254,7 +254,8 @@ FileAnalysis::getDirectControlFlowXRefs(const Instr &InstrMeta) const {
return CFCrossReferences;
}
-const std::set<uint64_t> &FileAnalysis::getIndirectInstructions() const {
+const std::set<object::SectionedAddress> &
+FileAnalysis::getIndirectInstructions() const {
return IndirectInstructions;
}
@@ -268,8 +269,10 @@ const MCInstrAnalysis *FileAnalysis::getMCInstrAnalysis() const {
return MIA.get();
}
-Expected<DIInliningInfo> FileAnalysis::symbolizeInlinedCode(uint64_t Address) {
+Expected<DIInliningInfo>
+FileAnalysis::symbolizeInlinedCode(object::SectionedAddress Address) {
assert(Symbolizer != nullptr && "Symbolizer is invalid.");
+
return Symbolizer->symbolizeInlinedCode(Object->getFileName(), Address);
}
@@ -457,13 +460,14 @@ Error FileAnalysis::parseCodeSections() {
ArrayRef<uint8_t> SectionBytes((const uint8_t *)SectionContents.data(),
Section.getSize());
- parseSectionContents(SectionBytes, Section.getAddress());
+ parseSectionContents(SectionBytes,
+ {Section.getAddress(), Section.getIndex()});
}
return Error::success();
}
void FileAnalysis::parseSectionContents(ArrayRef<uint8_t> SectionBytes,
- uint64_t SectionAddress) {
+ object::SectionedAddress Address) {
assert(Symbolizer && "Symbolizer is uninitialised.");
MCInst Instruction;
Instr InstrMeta;
@@ -477,7 +481,7 @@ void FileAnalysis::parseSectionContents(ArrayRef<uint8_t> SectionBytes,
Byte += InstructionSize;
- uint64_t VMAddress = SectionAddress + Byte - InstructionSize;
+ uint64_t VMAddress = Address.Address + Byte - InstructionSize;
InstrMeta.Instruction = Instruction;
InstrMeta.VMAddress = VMAddress;
InstrMeta.InstructionSize = InstructionSize;
@@ -509,8 +513,8 @@ void FileAnalysis::parseSectionContents(ArrayRef<uint8_t> SectionBytes,
// Check if this instruction exists in the range of the DWARF metadata.
if (!IgnoreDWARFFlag) {
- auto LineInfo =
- Symbolizer->symbolizeCode(Object->getFileName(), VMAddress);
+ auto LineInfo = Symbolizer->symbolizeCode(
+ Object->getFileName(), {VMAddress, Address.SectionIndex});
if (!LineInfo) {
handleAllErrors(LineInfo.takeError(), [](const ErrorInfoBase &E) {
errs() << "Symbolizer failed to get line: " << E.message() << "\n";
@@ -522,7 +526,7 @@ void FileAnalysis::parseSectionContents(ArrayRef<uint8_t> SectionBytes,
continue;
}
- IndirectInstructions.insert(VMAddress);
+ IndirectInstructions.insert({VMAddress, Address.SectionIndex});
}
}
diff --git a/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.h b/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.h
index d8031ed5f7d..27135c0debb 100644
--- a/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.h
+++ b/llvm/tools/llvm-cfi-verify/lib/FileAnalysis.h
@@ -139,14 +139,15 @@ public:
bool usesRegisterOperand(const Instr &InstrMeta) const;
// Returns the list of indirect instructions.
- const std::set<uint64_t> &getIndirectInstructions() const;
+ const std::set<object::SectionedAddress> &getIndirectInstructions() const;
const MCRegisterInfo *getRegisterInfo() const;
const MCInstrInfo *getMCInstrInfo() const;
const MCInstrAnalysis *getMCInstrAnalysis() const;
// Returns the inlining information for the provided address.
- Expected<DIInliningInfo> symbolizeInlinedCode(uint64_t Address);
+ Expected<DIInliningInfo>
+ symbolizeInlinedCode(object::SectionedAddress Address);
// Returns whether the provided Graph represents a protected indirect control
// flow instruction in this file.
@@ -178,7 +179,7 @@ protected:
// Disassemble and parse the provided bytes into this object. Instruction
// address calculation is done relative to the provided SectionAddress.
void parseSectionContents(ArrayRef<uint8_t> SectionBytes,
- uint64_t SectionAddress);
+ object::SectionedAddress Address);
// Constructs and initialises members required for disassembly.
Error initialiseDisassemblyMembers();
@@ -225,7 +226,7 @@ private:
DenseMap<uint64_t, std::vector<uint64_t>> StaticBranchTargetings;
// A list of addresses of indirect control flow instructions.
- std::set<uint64_t> IndirectInstructions;
+ std::set<object::SectionedAddress> IndirectInstructions;
// The addresses of functions that will trap on CFI violations.
SmallSet<uint64_t, 4> TrapOnFailFunctionAddresses;
diff --git a/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp b/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
index 1f8fccb32ff..b621836b270 100644
--- a/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
+++ b/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
@@ -93,17 +93,19 @@ void GraphResult::printToDOT(const FileAnalysis &Analysis,
}
GraphResult GraphBuilder::buildFlowGraph(const FileAnalysis &Analysis,
- uint64_t Address) {
+ object::SectionedAddress Address) {
GraphResult Result;
- Result.BaseAddress = Address;
+ Result.BaseAddress = Address.Address;
DenseSet<uint64_t> OpenedNodes;
const auto &IndirectInstructions = Analysis.getIndirectInstructions();
- if (IndirectInstructions.find(Address) == IndirectInstructions.end())
+ // check that IndirectInstructions contains specified Address
+ if (IndirectInstructions.find(Address) == IndirectInstructions.end()) {
return Result;
+ }
- buildFlowGraphImpl(Analysis, OpenedNodes, Result, Address, 0);
+ buildFlowGraphImpl(Analysis, OpenedNodes, Result, Address.Address, 0);
return Result;
}
diff --git a/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.h b/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.h
index c76e89a37ec..dc96e0b2501 100644
--- a/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.h
+++ b/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.h
@@ -102,7 +102,7 @@ public:
// (i.e. the upwards traversal did not make it to a branch node) flows to the
// provided node in GraphResult::OrphanedNodes.
static GraphResult buildFlowGraph(const FileAnalysis &Analysis,
- uint64_t Address);
+ object::SectionedAddress Address);
private:
// Implementation function that actually builds the flow graph. Retrieves a
diff --git a/llvm/tools/llvm-cfi-verify/llvm-cfi-verify.cpp b/llvm/tools/llvm-cfi-verify/llvm-cfi-verify.cpp
index 9fff1a5ec38..c54e5383248 100644
--- a/llvm/tools/llvm-cfi-verify/llvm-cfi-verify.cpp
+++ b/llvm/tools/llvm-cfi-verify/llvm-cfi-verify.cpp
@@ -130,8 +130,8 @@ void printIndirectCFInstructions(FileAnalysis &Analysis,
std::map<unsigned, uint64_t> BlameCounter;
- for (uint64_t Address : Analysis.getIndirectInstructions()) {
- const auto &InstrMeta = Analysis.getInstructionOrDie(Address);
+ for (object::SectionedAddress Address : Analysis.getIndirectInstructions()) {
+ const auto &InstrMeta = Analysis.getInstructionOrDie(Address.Address);
GraphResult Graph = GraphBuilder::buildFlowGraph(Analysis, Address);
CFIProtectionStatus ProtectionStatus =
@@ -153,7 +153,7 @@ void printIndirectCFInstructions(FileAnalysis &Analysis,
auto InliningInfo = Analysis.symbolizeInlinedCode(Address);
if (!InliningInfo || InliningInfo->getNumberOfFrames() == 0) {
- errs() << "Failed to symbolise " << format_hex(Address, 2)
+ errs() << "Failed to symbolise " << format_hex(Address.Address, 2)
<< " with line tables from " << InputFilename << "\n";
exit(EXIT_FAILURE);
}
@@ -164,9 +164,9 @@ void printIndirectCFInstructions(FileAnalysis &Analysis,
if (!Summarize) {
for (uint32_t i = 0; i < InliningInfo->getNumberOfFrames(); ++i) {
const auto &Line = InliningInfo->getFrame(i);
- outs() << " " << format_hex(Address, 2) << " = " << Line.FileName
- << ":" << Line.Line << ":" << Line.Column << " ("
- << Line.FunctionName << ")\n";
+ outs() << " " << format_hex(Address.Address, 2) << " = "
+ << Line.FileName << ":" << Line.Line << ":" << Line.Column
+ << " (" << Line.FunctionName << ")\n";
}
}
OpenPOWER on IntegriCloud