Lines Matching +full:loongson +full:- +full:3
1 //===- LoongArch.cpp ------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
75 // produces a PC-relative intermediate value with the lowest 12 bits zeroed (the
80 // Here a "page" is in fact just another way to refer to the 12-bit range
95 // (lu32i.d and lu52i.d). Compensate all the sign-extensions is a bit
103 pcalau12i_pc = pc - 8;
109 pcalau12i_pc = pc - 12;
115 uint64_t result = getLoongArchPage(dest) - getLoongArchPage(pcalau12i_pc);
117 result += 0x1000 - 0x1'0000'0000;
131 return begin == 63 ? v >> end : (v & ((1ULL << (begin + 1)) - 1)) >> end;
169 uint64_t mask = count < maxcount ? (1ULL << 7 * count) - 1 : -1ULL;
179 // kernel implementation, and 64KiB is the biggest non-huge page size
191 if (config->is64) {
216 if (config->is64)
217 return cast<ObjFile<ELF64LE>>(f)->getObj().getHeader().e_flags;
218 return cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
222 for (const auto *sec : f->getSections())
223 if (sec && sec->flags & SHF_EXECINSTR)
230 // If there are only binary input files (from -b binary), use a
239 // This is useful for allowing linkage with data-only object files produced
244 // Take the first non-zero e_flags as the reference.
264 // binary-compatible with the upstream i.e. new-world ecosystem, it's not
267 // There are briefly some new-world systems with object ABI v0 binaries too.
297 return config->is64 ? read64le(buf) : read32le(buf);
310 if (config->is64)
311 write64le(buf, in.plt->getVA());
313 write32le(buf, in.plt->getVA());
317 if (config->writeAddends) {
318 if (config->is64)
328 // PC-relative addressing (because `pcaddu12i` is the same as RISCV `auipc`),
329 // in contrast to the AArch64-like page-offset scheme with `pcalau12i` that
330 // is used everywhere else involving PC-relative operations in the LoongArch
339 // addi.[wd] $t1, $t1, -pltHeaderSize-12 ; t1 = &.plt[i] - &.plt[0]
341 // srli.[wd] $t1, $t1, (is64?1:2) ; t1 = &.got.plt[i] - &.got.plt[0]
344 uint32_t offset = in.gotPlt->getVA() - in.plt->getVA();
345 uint32_t sub = config->is64 ? SUB_D : SUB_W;
346 uint32_t ld = config->is64 ? LD_D : LD_W;
347 uint32_t addi = config->is64 ? ADDI_D : ADDI_W;
348 uint32_t srli = config->is64 ? SRLI_D : SRLI_W;
352 write32le(buf + 12, insn(addi, R_T1, R_T1, lo12(-target->pltHeaderSize - 12)));
354 write32le(buf + 20, insn(srli, R_T1, R_T1, config->is64 ? 1 : 2));
355 write32le(buf + 24, insn(ld, R_T0, R_T0, config->wordsize));
368 uint32_t offset = sym.getGotPltVA() - pltEntryAddr;
371 insn(config->is64 ? LD_D : LD_W, R_T3, R_T3, lo12(offset)));
377 return type == target->symbolicRel ? type
403 // [2]: https://github.com/loongson/la-abi-specs/pull/3
468 // (e.g. as outlined in https://github.com/loongson/la-abi-specs/pull/3).
473 // allow for such inter-pass state.
476 // BFD: assuming every R_LARCH_PCALA_HI20 is potentially PLT-needing, only
498 return config->relax ? R_RELAX_HINT : R_NONE;
523 // - psABI v1 relocs that need a stateful stack machine to work, and not
525 // - relocs that are not used anywhere (R_LARCH_{ADD,SUB}_24 [1], and the
526 // two GNU vtable-related relocs).
528 // [1]: https://web.archive.org/web/20230709064026/https://github.com/loongson/LoongArch-Documentation/issues/51
597 // immediate fields, the relocation range is [-128G - 0x20000, +128G -
598 // 0x20000) (of course must be 4-byte aligned).
600 reportRangeError(loc, rel, Twine(val), llvm::minIntN(38) - 0x20000,
601 llvm::maxIntN(38) - 0x20000);
606 // Despite the name, the lower part is actually 18 bits with 4-byte aligned.
705 *loc = (*loc & 0xc0) | ((*loc - val) & 0x3f);
708 *loc -= val;
711 write16le(loc, read16le(loc) - val);
714 write32le(loc, read32le(loc) - val);
717 write64le(loc, read64le(loc) - val);
720 handleUleb128(loc, -val);
725 // no-op
757 const uint64_t loc = secAddr + r.offset - delta;
762 r.sym->isUndefined() ? Log2_64(r.addend) + 1 : r.addend;
763 const uint64_t allBytes = (1ULL << (addend & 0xff)) - 4;
766 const uint64_t off = loc & (align - 1);
767 const uint64_t curBytes = off == 0 ? 0 : align - off;
773 remove = allBytes - curBytes;
791 sa[0].d->size = sa[0].offset - delta - sa[0].d->value;
793 sa[0].d->value = sa[0].offset - delta;
804 a.d->size = a.offset - delta - a.d->value;
806 a.d->value = a.offset - delta;
823 if (config->relocatable)
832 if (!(osec->flags & SHF_EXECINSTR))
844 if (!(osec->flags & SHF_EXECINSTR))
847 RelaxAux &aux = *sec->relaxAux;
851 MutableArrayRef<Relocation> rels = sec->relocs();
852 ArrayRef<uint8_t> old = sec->content();
853 size_t newSize = old.size() - aux.relocDeltas[rels.size() - 1];
857 sec->content_ = p;
858 sec->size = newSize;
859 sec->bytesDropped = 0;
864 uint32_t remove = aux.relocDeltas[i] - delta;
871 uint64_t size = r.offset - offset;
876 memcpy(p, old.data() + offset, old.size() - offset);
885 rels[i].offset -= delta;
889 delta = aux.relocDeltas[i - 1];