[BOLT][NFC] Change interface for searching relocations

(cherry picked from FBD28406629)
This commit is contained in:
Maksim Panchenko 2021-05-12 23:29:04 -07:00
parent 500edf26c9
commit 81c59d9a54
3 changed files with 12 additions and 10 deletions

View File

@ -232,10 +232,11 @@ void BinarySection::print(raw_ostream &OS) const {
}
}
std::set<Relocation> BinarySection::reorderRelocations(bool Inplace) const {
BinarySection::RelocationSetType
BinarySection::reorderRelocations(bool Inplace) const {
assert(PendingRelocations.empty() &&
"reodering pending relocations not supported");
std::set<Relocation> NewRelocations;
RelocationSetType NewRelocations;
for (const Relocation &Rel : relocations()) {
uint64_t RelAddr = Rel.Offset + getAddress();
BinaryData *BD = BC.getBinaryDataContainingAddress(RelAddr);

View File

@ -52,7 +52,7 @@ class BinarySection {
// Relocations associated with this section. Relocation offsets are
// wrt. to the original section address and size.
using RelocationSetType = std::set<Relocation>;
using RelocationSetType = std::set<Relocation, std::less<>>;
RelocationSetType Relocations;
// Dynamic relocations associated with this section. Relocation offsets are
@ -119,7 +119,7 @@ class BinarySection {
/// Get the set of relocations refering to data in this section that
/// has been reordered. The relocation offsets will be modified to
/// reflect the new data locations.
std::set<Relocation> reorderRelocations(bool Inplace) const;
RelocationSetType reorderRelocations(bool Inplace) const;
/// Set output info for this section.
void update(uint8_t *NewData,
@ -341,8 +341,7 @@ public:
/// Remove non-pending relocation with the given /p Offset.
bool removeRelocationAt(uint64_t Offset) {
Relocation Key{Offset, 0, 0, 0, 0};
auto Itr = Relocations.find(Key);
auto Itr = Relocations.find(Offset);
if (Itr != Relocations.end()) {
Relocations.erase(Itr);
return true;
@ -352,8 +351,7 @@ public:
void clearRelocations();
/// Add a new relocation at the given /p Offset. Note: pending relocations
/// are only used by .debug_info and should eventually go away.
/// Add a new relocation at the given /p Offset.
void addRelocation(uint64_t Offset,
MCSymbol *Symbol,
uint64_t Type,
@ -399,8 +397,7 @@ public:
/// Lookup the relocation (if any) at the given /p Offset.
const Relocation *getRelocationAt(uint64_t Offset) const {
Relocation Key{Offset, 0, 0, 0, 0};
auto Itr = Relocations.find(Key);
auto Itr = Relocations.find(Offset);
return Itr != Relocations.end() ? &*Itr : nullptr;
}

View File

@ -99,6 +99,10 @@ inline bool operator<(const Relocation &A, const Relocation &B) {
return A.Offset < B.Offset;
}
inline bool operator<(const Relocation &A, uint64_t B) { return A.Offset < B; }
inline bool operator<(uint64_t A, const Relocation &B) { return A < B.Offset; }
inline raw_ostream &operator<<(raw_ostream &OS, const Relocation &Rel) {
Rel.print(OS);
return OS;