Skip to content

Commit 29f2301

Browse files
committed
[BOLT][NFC] Simplify addRelocation
Move the implementation out of the header file. Simplify the method. Add debug logging. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D131811
1 parent 777b6ad commit 29f2301

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

bolt/include/bolt/Core/BinarySection.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,7 @@ class BinarySection {
326326

327327
/// Add a new relocation at the given /p Offset.
328328
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
329-
uint64_t Addend, uint64_t Value = 0,
330-
bool Pending = false) {
331-
assert(Offset < getSize() && "offset not within section bounds");
332-
if (!Pending) {
333-
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
334-
} else {
335-
PendingRelocations.emplace_back(
336-
Relocation{Offset, Symbol, Type, Addend, Value});
337-
}
338-
}
329+
uint64_t Addend, uint64_t Value = 0, bool Pending = false);
339330

340331
/// Add a dynamic relocation at the given /p Offset.
341332
void addDynamicRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,

bolt/lib/Core/BinarySection.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ BinarySection::~BinarySection() {
176176

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

179+
void BinarySection::addRelocation(uint64_t Offset, MCSymbol *Symbol,
180+
uint64_t Type, uint64_t Addend,
181+
uint64_t Value, bool Pending) {
182+
assert(Offset < getSize() && "offset not within section bounds");
183+
LLVM_DEBUG(dbgs() << formatv(
184+
"BOLT-DEBUG: addRelocation in {0}, @{1:x} against {2}\n",
185+
getName(), Offset, Symbol->getName()));
186+
Relocation R{Offset, Symbol, Type, Addend, Value};
187+
if (Pending)
188+
PendingRelocations.emplace_back(R);
189+
else
190+
Relocations.emplace(R);
191+
}
192+
179193
void BinarySection::print(raw_ostream &OS) const {
180194
OS << getName() << ", "
181195
<< "0x" << Twine::utohexstr(getAddress()) << ", " << getSize() << " (0x"

0 commit comments

Comments
 (0)