Skip to content

Commit 385af28

Browse files
[BOLT] Prevent addRelocation from adding pending relocs (#123635)
`addPendingRelocation` is the only way to add a pending relocation. Can no longer use `addRelocation` for this. Update the only user (`BinaryContextTester`).
1 parent 2577540 commit 385af28

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

bolt/include/bolt/Core/BinarySection.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,9 @@ class BinarySection {
359359

360360
/// Add a new relocation at the given /p Offset.
361361
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
362-
uint64_t Addend, uint64_t Value = 0,
363-
bool Pending = false) {
362+
uint64_t Addend, uint64_t Value = 0) {
364363
assert(Offset < getSize() && "offset not within section bounds");
365-
if (!Pending) {
366-
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
367-
} else {
368-
PendingRelocations.emplace_back(
369-
Relocation{Offset, Symbol, Type, Addend, Value});
370-
}
364+
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
371365
}
372366

373367
/// Add a dynamic relocation at the given /p Offset.

bolt/unittests/Core/BinaryContext.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
9393
DataSize, 4);
9494
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
9595
ASSERT_TRUE(RelSymbol1);
96-
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0, true);
96+
BS.addPendingRelocation(
97+
Relocation{8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0});
9798
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
9899
ASSERT_TRUE(RelSymbol2);
99-
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0, true);
100+
BS.addPendingRelocation(
101+
Relocation{12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0});
100102

101-
std::error_code EC;
102103
SmallVector<char> Vect(DataSize);
103104
raw_svector_ostream OS(Vect);
104105

@@ -134,12 +135,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
134135
(uint8_t *)Data, Size, 4);
135136
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
136137
ASSERT_TRUE(RelSymbol1);
137-
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0, true);
138+
BS.addPendingRelocation(
139+
Relocation{8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0});
138140
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
139141
ASSERT_TRUE(RelSymbol2);
140-
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0, true);
142+
BS.addPendingRelocation(
143+
Relocation{12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0});
141144

142-
std::error_code EC;
143145
SmallVector<char> Vect(Size);
144146
raw_svector_ostream OS(Vect);
145147

0 commit comments

Comments
 (0)