lld: fix Linx HI/LO relocation pairing#24
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
There was a problem hiding this comment.
Code Review
This pull request updates the relocation handling in lld/ELF/InputSection.cpp to support recovering R_LINX_PCREL_HI20 relocations in either direction by exact symbol and addend, and defers error reporting for unsupported defined anchors. It also updates getRelocTargetVA to compute the target address directly for RE_LINX_PC_INDIRECT. The reviewer suggested a performance optimization in findLinxPCRelHiBySymbol to avoid calling llvm::lower_bound twice by copying the iterator for the backward search.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const Relocation *before = nullptr; | ||
| while (it != isec->relocs().begin()) { | ||
| --it; | ||
| if (it->sym == sym && isLinxPCRelHi(it->type)) | ||
| return &*it; | ||
| if (it->sym == sym && it->addend == addend && isLinxPCRelHi(it->type)) { | ||
| before = &*it; | ||
| break; | ||
| } | ||
| } | ||
| return nullptr; | ||
|
|
||
| const Relocation *after = nullptr; | ||
| it = llvm::lower_bound( | ||
| isec->relocs(), loOffset, | ||
| [](const Relocation &lhs, uint64_t rhs) { return lhs.offset < rhs; }); | ||
| for (; it != isec->relocs().end(); ++it) { | ||
| if (it->sym == sym && it->addend == addend && isLinxPCRelHi(it->type)) { | ||
| after = &*it; | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
We can avoid calling llvm::lower_bound twice by copying the iterator it for the backward search. This eliminates the redundant binary search overhead on the relocation list.
const Relocation *before = nullptr;
for (auto rollbackIt = it; rollbackIt != isec->relocs().begin();) {
--rollbackIt;
if (rollbackIt->sym == sym && rollbackIt->addend == addend && isLinxPCRelHi(rollbackIt->type)) {
before = &*rollbackIt;
break;
}
}
const Relocation *after = nullptr;
for (; it != isec->relocs().end(); ++it) {
if (it->sym == sym && it->addend == addend && isLinxPCRelHi(it->type)) {
after = &*it;
break;
}
}
This PR fixes Linx LLD HI/LO relocation pairing.
Problem:
Fix:
Validation: