void relaxTlsGdToLe(uint8_t *loc, const Relocation &rel, uint64_t val) const;
void relaxTlsGdToIe(uint8_t *loc, const Relocation &rel, uint64_t val) const;
void relaxTlsIeToLe(uint8_t *loc, const Relocation &rel, uint64_t val) const;
- void initRelaxer(ArrayRef<Relocation> relocs) const;
+};
+
+struct AArch64Relaxer {
+ bool safeToRelaxAdrpLdr = false;
+
+ AArch64Relaxer(ArrayRef<Relocation> relocs);
bool tryRelaxAdrpAdd(const Relocation &adrpRel, const Relocation &addRel,
uint64_t secAddr, uint8_t *buf) const;
bool tryRelaxAdrpLdr(const Relocation &adrpRel, const Relocation &ldrRel,
uint64_t secAddr, uint8_t *buf) const;
- mutable bool safeToRelaxAdrpLdr = false;
};
} // namespace
llvm_unreachable("invalid relocation for TLS IE to LE relaxation");
}
-void AArch64::initRelaxer(ArrayRef<Relocation> relocs) const {
+AArch64Relaxer::AArch64Relaxer(ArrayRef<Relocation> relocs) {
if (!config->relax)
return;
// Check if R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC
safeToRelaxAdrpLdr = i == size;
}
-bool AArch64::tryRelaxAdrpAdd(const Relocation &adrpRel,
- const Relocation &addRel, uint64_t secAddr,
- uint8_t *buf) const {
+bool AArch64Relaxer::tryRelaxAdrpAdd(const Relocation &adrpRel,
+ const Relocation &addRel, uint64_t secAddr,
+ uint8_t *buf) const {
// When the address of sym is within the range of ADR then
// we may relax
// ADRP xn, sym
return true;
}
-bool AArch64::tryRelaxAdrpLdr(const Relocation &adrpRel,
- const Relocation &ldrRel, uint64_t secAddr,
- uint8_t *buf) const {
+bool AArch64Relaxer::tryRelaxAdrpLdr(const Relocation &adrpRel,
+ const Relocation &ldrRel, uint64_t secAddr,
+ uint8_t *buf) const {
if (!safeToRelaxAdrpLdr)
return false;
uint64_t secAddr = sec.getOutputSection()->addr;
if (auto *s = dyn_cast<InputSection>(&sec))
secAddr += s->outSecOff;
- initRelaxer(sec.relocations);
+ AArch64Relaxer relaxer(sec.relocations);
for (size_t i = 0, size = sec.relocations.size(); i != size; ++i) {
const Relocation &rel = sec.relocations[i];
uint8_t *loc = buf + rel.offset;
switch (rel.expr) {
case R_AARCH64_GOT_PAGE_PC:
if (i + 1 < size &&
- tryRelaxAdrpLdr(rel, sec.relocations[i + 1], secAddr, buf)) {
+ relaxer.tryRelaxAdrpLdr(rel, sec.relocations[i + 1], secAddr, buf)) {
++i;
continue;
}
break;
case R_AARCH64_PAGE_PC:
if (i + 1 < size &&
- tryRelaxAdrpAdd(rel, sec.relocations[i + 1], secAddr, buf)) {
+ relaxer.tryRelaxAdrpAdd(rel, sec.relocations[i + 1], secAddr, buf)) {
++i;
continue;
}