Skip to content

Commit e69eceb

Browse files
yjndinyy
authored andcommitted
[BOLT][RISCV]fix up GOT Relocation Handling
1 parent 2094568 commit e69eceb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bolt/lib/Passes/FixRISCVCallsPass.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
3434
TargetSym = MIB->getPCRelLoSymbol(AInst);
3535
if (TargetSym) {
3636
auto BI = II;
37-
bool found = false;
37+
bool foundSymbol = false;
3838
while(BI != BB.begin()){
3939
auto *Label = MIB->getInstLabel(*BI);
4040
if (Label && Label == TargetSym) {
@@ -48,6 +48,16 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
4848
MIB->copyAnnotations(*BI, SavedInst);
4949
BB.eraseInstruction(BI);
5050
II = BB.insertInstruction(--II, std::move(SavedInst));
51+
52+
// Verify that the label of the current instruction matches
53+
// the getPCRelLoSymbol of the next instruction
54+
auto NextII = std::next(II);
55+
if (NextII != BB.end()) {
56+
auto *CurrentLabel = MIB->getInstLabel(*II);
57+
auto *NextTargetSym = MIB->getPCRelLoSymbol(*NextII);
58+
assert(CurrentLabel && NextTargetSym && CurrentLabel == NextTargetSym &&
59+
"Label and target symbol mismatch after instruction reordering");
60+
}
5161
II++;
5262
}
5363
}

0 commit comments

Comments
 (0)