|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "bolt/Core/BinaryContext.h"
|
| 10 | +#include "bolt/Utils/CommandLineOpts.h" |
10 | 11 | #include "llvm/BinaryFormat/ELF.h"
|
11 | 12 | #include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
12 | 13 | #include "llvm/Support/TargetSelect.h"
|
@@ -161,12 +162,44 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
|
161 | 162 | << "Wrong forward branch value\n";
|
162 | 163 | }
|
163 | 164 |
|
164 |
| -TEST_P(BinaryContextTester, FlushOptionalOutOfRangePendingRelocCALL26) { |
| 165 | +TEST_P(BinaryContextTester, |
| 166 | + FlushOptionalOutOfRangePendingRelocCALL26_ForcePatchOff) { |
165 | 167 | if (GetParam() != Triple::aarch64)
|
166 | 168 | GTEST_SKIP();
|
167 | 169 |
|
168 |
| - // This test checks that flushPendingRelocations skips flushing any optional |
169 |
| - // pending relocations that cannot be encoded. |
| 170 | + // Tests that flushPendingRelocations exits if any pending relocation is out |
| 171 | + // of range and PatchEntries hasn't run. Pending relocations are added by |
| 172 | + // scanExternalRefs, so this ensures that either all scanExternalRefs |
| 173 | + // relocations were flushed or PatchEntries ran. |
| 174 | + |
| 175 | + BinarySection &BS = BC->registerOrUpdateSection( |
| 176 | + ".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC); |
| 177 | + // Create symbol 'Func0x4' |
| 178 | + MCSymbol *RelSymbol = BC->getOrCreateGlobalSymbol(4, "Func"); |
| 179 | + ASSERT_TRUE(RelSymbol); |
| 180 | + BS.addPendingRelocation(Relocation{8, RelSymbol, ELF::R_AARCH64_CALL26, 0, 0}, |
| 181 | + /*Optional*/ true); |
| 182 | + |
| 183 | + SmallVector<char> Vect; |
| 184 | + raw_svector_ostream OS(Vect); |
| 185 | + |
| 186 | + // Resolve relocation symbol to a high value so encoding will be out of range. |
| 187 | + EXPECT_EXIT(BS.flushPendingRelocations( |
| 188 | + OS, [&](const MCSymbol *S) { return 0x800000F; }), |
| 189 | + ::testing::ExitedWithCode(1), |
| 190 | + "BOLT-ERROR: Cannot fully run scanExternalRefs as pending " |
| 191 | + "relocation for symbol Func0x4 is out-of-range. Cannot proceed " |
| 192 | + "without using -force-patch"); |
| 193 | +} |
| 194 | + |
| 195 | +TEST_P(BinaryContextTester, |
| 196 | + FlushOptionalOutOfRangePendingRelocCALL26_ForcePatchOn) { |
| 197 | + if (GetParam() != Triple::aarch64) |
| 198 | + GTEST_SKIP(); |
| 199 | + |
| 200 | + // Tests that flushPendingRelocations can skip flushing any optional pending |
| 201 | + // relocations that cannot be encoded, given that PatchEntries runs. |
| 202 | + opts::ForcePatch = true; |
170 | 203 |
|
171 | 204 | bool DebugFlagPrev = ::llvm::DebugFlag;
|
172 | 205 | ::llvm::DebugFlag = true;
|
|
0 commit comments