Skip to content

Commit a6dbcb8

Browse files
BOLT asserts on out-of-range pending relocs
1 parent f23bb53 commit a6dbcb8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

bolt/unittests/Core/BinaryContext.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,33 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
161161
<< "Wrong forward branch value\n";
162162
}
163163

164+
// TODO: BOLT currently asserts when a relocation is out of range.
165+
TEST_P(BinaryContextTester, FlushOptionalOutOfRangePendingRelocCALL26) {
166+
if (GetParam() != Triple::aarch64)
167+
GTEST_SKIP();
168+
169+
// This test checks that flushPendingRelocations skips flushing any optional
170+
// pending relocations that cannot be encoded.
171+
172+
BinarySection &BS = BC->registerOrUpdateSection(
173+
".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
174+
MCSymbol *RelSymbol = BC->getOrCreateGlobalSymbol(4, "Func");
175+
ASSERT_TRUE(RelSymbol);
176+
BS.addPendingRelocation(
177+
Relocation{8, RelSymbol, ELF::R_AARCH64_CALL26, 0, 0});
178+
179+
SmallVector<char> Vect;
180+
raw_svector_ostream OS(Vect);
181+
182+
// FIXME: bolt must be able to skip pending relocs that are out of range.
183+
EXPECT_DEBUG_DEATH(
184+
// Resolve relocation symbol to a high value so encoding will be out of
185+
// range.
186+
BS.flushPendingRelocations(OS,
187+
[&](const MCSymbol *S) { return 0x800000F; }),
188+
".*only PC \\+/- 128MB is allowed for direct call");
189+
}
190+
164191
#endif
165192

166193
TEST_P(BinaryContextTester, BaseAddress) {

0 commit comments

Comments
 (0)