[PATCH] D131812: [BOLT][NFC] Move printRelocationInfo into a method
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 14:48:21 PDT 2022
Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131812
Files:
bolt/include/bolt/Rewrite/RewriteInstance.h
bolt/lib/Rewrite/RewriteInstance.cpp
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2221,6 +2221,30 @@
}
}
+void RewriteInstance::printRelocationInfo(const RelocationRef &Rel,
+ StringRef SymbolName,
+ uint64_t SymbolAddress,
+ uint64_t Addend,
+ uint64_t ExtractedValue) const {
+ SmallString<16> TypeName;
+ Rel.getTypeName(TypeName);
+ const uint64_t Address = SymbolAddress + Addend;
+ const uint64_t Offset = Rel.getOffset();
+ ErrorOr<BinarySection &> Section = BC->getSectionForAddress(SymbolAddress);
+ BinaryFunction *Func = BC->getBinaryFunctionContainingAddress(Offset,
+ false, BC->isAArch64());
+ dbgs() << formatv("Relocation: offset = {0:x}; type = {1}; value = {2:x}; ",
+ Offset, TypeName, ExtractedValue)
+ << formatv("symbol = {0} ({1}); symbol address = {2:x}; ", SymbolName,
+ Section ? Section->getName() : "", SymbolAddress)
+ << formatv("addend = {0:x}; address = {1:x}; in = ", Addend, Address);
+ if (Func)
+ dbgs() << Func->getPrintName();
+ else
+ dbgs() << BC->getSectionForAddress(Rel.getOffset())->getName();
+ dbgs() << '\n';
+}
+
void RewriteInstance::readRelocations(const SectionRef &Section) {
LLVM_DEBUG({
StringRef SectionName = cantFail(Section.getName());
@@ -2257,32 +2281,6 @@
const bool IsAArch64 = BC->isAArch64();
const bool IsFromCode = RelocatedSection.isText();
- auto printRelocationInfo = [&](const RelocationRef &Rel,
- StringRef SymbolName,
- uint64_t SymbolAddress,
- uint64_t Addend,
- uint64_t ExtractedValue) {
- SmallString<16> TypeName;
- Rel.getTypeName(TypeName);
- const uint64_t Address = SymbolAddress + Addend;
- ErrorOr<BinarySection &> Section = BC->getSectionForAddress(SymbolAddress);
- dbgs() << "Relocation: offset = 0x"
- << Twine::utohexstr(Rel.getOffset())
- << "; type = " << TypeName
- << "; value = 0x" << Twine::utohexstr(ExtractedValue)
- << "; symbol = " << SymbolName
- << " (" << (Section ? Section->getName() : "") << ")"
- << "; symbol address = 0x" << Twine::utohexstr(SymbolAddress)
- << "; addend = 0x" << Twine::utohexstr(Addend)
- << "; address = 0x" << Twine::utohexstr(Address)
- << "; in = ";
- if (BinaryFunction *Func = BC->getBinaryFunctionContainingAddress(
- Rel.getOffset(), false, IsAArch64))
- dbgs() << Func->getPrintName() << "\n";
- else
- dbgs() << BC->getSectionForAddress(Rel.getOffset())->getName() << "\n";
- };
-
for (const RelocationRef &Rel : Section.relocations()) {
SmallString<16> TypeName;
Rel.getTypeName(TypeName);
Index: bolt/include/bolt/Rewrite/RewriteInstance.h
===================================================================
--- bolt/include/bolt/Rewrite/RewriteInstance.h
+++ bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -133,6 +133,11 @@
/// Read relocations from a given section.
void readDynamicRelocations(const object::SectionRef &Section);
+ /// Print relocation information.
+ void printRelocationInfo(const RelocationRef &Rel, StringRef SymbolName,
+ uint64_t SymbolAddress, uint64_t Addend,
+ uint64_t ExtractedValue) const;
+
/// Read relocations from a given section.
void readRelocations(const object::SectionRef &Section);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131812.452309.patch
Type: text/x-patch
Size: 3785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220812/21ade102/attachment.bin>
More information about the llvm-commits
mailing list