[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`).
This commit is contained in:
Paschalis Mpeis 2025-02-12 17:24:11 +02:00 committed by GitHub
parent 257754011c
commit 385af283cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 14 deletions

View File

@ -359,15 +359,9 @@ public:
/// 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) {
uint64_t Addend, uint64_t Value = 0) {
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});
}
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
}
/// Add a dynamic relocation at the given /p Offset.

View File

@ -93,12 +93,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
DataSize, 4);
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
ASSERT_TRUE(RelSymbol1);
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0, true);
BS.addPendingRelocation(
Relocation{8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0});
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
ASSERT_TRUE(RelSymbol2);
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0, true);
BS.addPendingRelocation(
Relocation{12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0});
std::error_code EC;
SmallVector<char> Vect(DataSize);
raw_svector_ostream OS(Vect);
@ -134,12 +135,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
(uint8_t *)Data, Size, 4);
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
ASSERT_TRUE(RelSymbol1);
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0, true);
BS.addPendingRelocation(
Relocation{8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0});
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
ASSERT_TRUE(RelSymbol2);
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0, true);
BS.addPendingRelocation(
Relocation{12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0});
std::error_code EC;
SmallVector<char> Vect(Size);
raw_svector_ostream OS(Vect);