// Relocations are sorted by offset, so we can use std::equal_range to do
// binary search.
- auto Range = std::equal_range(IS->Relocations.begin(), IS->Relocations.end(),
- D->Value, RelocationOffsetComparator{});
- for (auto It = std::get<0>(Range); It != std::get<1>(Range); ++It)
- if (isRelExprOneOf<R_PC>(It->Expr))
+ Relocation R;
+ R.Offset = D->Value;
+ auto Range =
+ std::equal_range(IS->Relocations.begin(), IS->Relocations.end(), R,
+ [](const Relocation &LHS, const Relocation &RHS) {
+ return LHS.Offset < RHS.Offset;
+ });
+
+ for (auto It = Range.first; It != Range.second; ++It)
+ if (It->Expr == R_PC)
return &*It;
error("R_RISCV_PCREL_LO12 relocation points to " + IS->getObjMsg(D->Value) +
// Sort relocations by offset to binary search for R_RISCV_PCREL_HI20
if (Config->EMachine == EM_RISCV)
std::stable_sort(Sec.Relocations.begin(), Sec.Relocations.end(),
- RelocationOffsetComparator{});
+ [](const Relocation &LHS, const Relocation &RHS) {
+ return LHS.Offset < RHS.Offset;
+ });
}
template <class ELFT> void elf::scanRelocations(InputSectionBase &S) {
Symbol *Sym;
};
-struct RelocationOffsetComparator {
- bool operator()(const Relocation &Lhs, const Relocation &Rhs) {
- return Lhs.Offset < Rhs.Offset;
- }
-
- // For std::lower_bound, std::upper_bound, std::equal_range.
- bool operator()(const Relocation &Rel, uint64_t Val) {
- return Rel.Offset < Val;
- }
-
- bool operator()(uint64_t Val, const Relocation &Rel) {
- return Val < Rel.Offset;
- }
-};
-
template <class ELFT> void scanRelocations(InputSectionBase &);
void addIRelativeRelocs();