Skip to content

Commit

Permalink
[BOLT][NFC] Simplify addRelocation
Browse files Browse the repository at this point in the history
Move the implementation out of the header file.
Simplify the method.
Add debug logging.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D131811
  • Loading branch information
aaupov committed Aug 17, 2022
1 parent 777b6ad commit 29f2301
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 1 addition & 10 deletions bolt/include/bolt/Core/BinarySection.h
Expand Up @@ -326,16 +326,7 @@ class BinarySection {

/// Add a new relocation at the given /p Offset.
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
uint64_t Addend, uint64_t Value = 0,
bool Pending = false) {
assert(Offset < getSize() && "offset not within section bounds");
if (!Pending) {
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
} else {
PendingRelocations.emplace_back(
Relocation{Offset, Symbol, Type, Addend, Value});
}
}
uint64_t Addend, uint64_t Value = 0, bool Pending = false);

/// Add a dynamic relocation at the given /p Offset.
void addDynamicRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
Expand Down
14 changes: 14 additions & 0 deletions bolt/lib/Core/BinarySection.cpp
Expand Up @@ -176,6 +176,20 @@ BinarySection::~BinarySection() {

void BinarySection::clearRelocations() { clearList(Relocations); }

void BinarySection::addRelocation(uint64_t Offset, MCSymbol *Symbol,
uint64_t Type, uint64_t Addend,
uint64_t Value, bool Pending) {
assert(Offset < getSize() && "offset not within section bounds");
LLVM_DEBUG(dbgs() << formatv(
"BOLT-DEBUG: addRelocation in {0}, @{1:x} against {2}\n",
getName(), Offset, Symbol->getName()));
Relocation R{Offset, Symbol, Type, Addend, Value};
if (Pending)
PendingRelocations.emplace_back(R);
else
Relocations.emplace(R);
}

void BinarySection::print(raw_ostream &OS) const {
OS << getName() << ", "
<< "0x" << Twine::utohexstr(getAddress()) << ", " << getSize() << " (0x"
Expand Down

0 comments on commit 29f2301

Please sign in to comment.