Lines Matching +full:s +full:- +full:merged
1 //===- RISCV.cpp ----------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
36 void writeGotPlt(uint8_t *buf, const Symbol &s) const override;
37 void writeIgotPlt(uint8_t *buf, const Symbol &s) const override;
42 RelExpr getRelExpr(RelType type, const Symbol &s,
99 return (v & ((1ULL << (begin + 1)) - 1)) >> end; in extractBits()
115 if (config->is64) { in RISCV()
141 if (config->is64) in getEFlags()
142 return cast<ObjFile<ELF64LE>>(f)->getObj().getHeader().e_flags; in getEFlags()
143 return cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags; in getEFlags()
147 // If there are only binary input files (from -b binary), use a in calcEFlags()
162 ": cannot link object files with different floating-point ABI from " + in calcEFlags()
191 return config->is64 ? read64le(buf) : read32le(buf); in getImplicitAddend()
197 return config->is64 ? read64le(buf + 8) : read32le(buf + 4); in getImplicitAddend()
202 if (config->is64) in writeGotHeader()
203 write64le(buf, mainPart->dynamic->getVA()); in writeGotHeader()
205 write32le(buf, mainPart->dynamic->getVA()); in writeGotHeader()
208 void RISCV::writeGotPlt(uint8_t *buf, const Symbol &s) const { in writeGotPlt()
209 if (config->is64) in writeGotPlt()
210 write64le(buf, in.plt->getVA()); in writeGotPlt()
212 write32le(buf, in.plt->getVA()); in writeGotPlt()
215 void RISCV::writeIgotPlt(uint8_t *buf, const Symbol &s) const { in writeIgotPlt()
216 if (config->writeAddends) { in writeIgotPlt()
217 if (config->is64) in writeIgotPlt()
218 write64le(buf, s.getVA()); in writeIgotPlt()
220 write32le(buf, s.getVA()); in writeIgotPlt()
228 // addi t1, t1, -pltHeaderSize-12; t1 = &.plt[i] - &.plt[0] in writePltHeader()
230 // srli t1, t1, (rv64?1:2); t1 = &.got.plt[i] - &.got.plt[0] in writePltHeader()
233 uint32_t offset = in.gotPlt->getVA() - in.plt->getVA(); in writePltHeader()
234 uint32_t load = config->is64 ? LD : LW; in writePltHeader()
238 write32le(buf + 12, itype(ADDI, X_T1, X_T1, -target->pltHeaderSize - 12)); in writePltHeader()
240 write32le(buf + 20, itype(SRLI, X_T1, X_T1, config->is64 ? 1 : 2)); in writePltHeader()
241 write32le(buf + 24, itype(load, X_T0, X_T0, config->wordsize)); in writePltHeader()
251 uint32_t offset = sym.getGotPltVA() - pltEntryAddr; in writePlt()
253 write32le(buf + 4, itype(config->is64 ? LD : LW, X_T3, X_T3, lo12(offset))); in writePlt()
259 return type == target->symbolicRel ? type in getDynRel()
263 RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s, in getRelExpr() argument
324 return config->relax ? R_RELAX_HINT : R_NONE; in getRelExpr()
330 ") against symbol " + toString(s)); in getRelExpr()
336 const unsigned bits = config->wordsize * 8; in relocate()
453 uint64_t lo = val - (hi << 12); in relocate()
462 uint64_t lo = val - (hi << 12); in relocate()
470 int64_t displace = SignExtend64(val - gp->getVA(), bits); in relocate()
494 *loc = (*loc & 0xc0) | (((*loc & 0x3f) - val) & 0x3f); in relocate()
497 *loc -= val; in relocate()
500 write16le(loc, read16le(loc) - val); in relocate()
503 write32le(loc, read32le(loc) - val); in relocate()
506 write64le(loc, read64le(loc) - val); in relocate()
526 write32le(loc, val - dtpOffset); in relocate()
529 write64le(loc, val - dtpOffset); in relocate()
536 if (config->is64) in relocate()
560 if (config->is64) in tlsdescToIe()
594 uint64_t secAddr = sec.getOutputSection()->addr; in relocateAlloc()
595 if (auto *s = dyn_cast<InputSection>(&sec)) in relocateAlloc() local
596 secAddr += s->outSecOff; in relocateAlloc()
598 secAddr += ehIn->getParent()->outSecOff; in relocateAlloc()
613 // For R_RISCV_TLSDESC_HI20, store &got(sym)-PC to be used by the in relocateAlloc()
642 tlsdescVal -= rel.offset; in relocateAlloc()
662 auto val = rel.sym->getVA(rel.addend) - rel1.sym->getVA(rel1.addend); in relocateAlloc()
684 if (!(osec->flags & SHF_EXECINSTR)) in initSymbolAnchors()
687 sec->relaxAux = make<RelaxAux>(); in initSymbolAnchors()
688 if (sec->relocs().size()) { in initSymbolAnchors()
689 sec->relaxAux->relocDeltas = in initSymbolAnchors()
690 std::make_unique<uint32_t[]>(sec->relocs().size()); in initSymbolAnchors()
691 sec->relaxAux->relocTypes = in initSymbolAnchors()
692 std::make_unique<RelType[]>(sec->relocs().size()); in initSymbolAnchors()
699 // For a defined symbol foo, we may have `d->file != file` with --wrap=foo. in initSymbolAnchors()
700 // We should process foo, as the defining object file's symbol table may not in initSymbolAnchors()
703 // `!d->scriptDefined` to exclude symbols that are definitely not wrapped. in initSymbolAnchors()
705 // `relaxAux->anchors` may contain duplicate symbols, but that is fine. in initSymbolAnchors()
707 for (Symbol *sym : file->getSymbols()) { in initSymbolAnchors()
709 if (!d || (d->file != file && !d->scriptDefined)) in initSymbolAnchors()
711 if (auto *sec = dyn_cast_or_null<InputSection>(d->section)) in initSymbolAnchors()
712 if (sec->flags & SHF_EXECINSTR && sec->relaxAux) { in initSymbolAnchors()
714 sec->relaxAux->anchors.push_back({d->value, d, false}); in initSymbolAnchors()
715 sec->relaxAux->anchors.push_back({d->value + d->size, d, true}); in initSymbolAnchors()
723 if (!(osec->flags & SHF_EXECINSTR)) in initSymbolAnchors()
726 llvm::sort(sec->relaxAux->anchors, [](auto &a, auto &b) { in initSymbolAnchors()
743 const int64_t displace = dest - loc; in relaxCall()
746 sec.relaxAux->relocTypes[i] = R_RISCV_RVC_JUMP; in relaxCall()
747 sec.relaxAux->writes.push_back(0xa001); // c.j in relaxCall()
750 !config->is64) { // RV32C only in relaxCall()
751 sec.relaxAux->relocTypes[i] = R_RISCV_RVC_JUMP; in relaxCall()
752 sec.relaxAux->writes.push_back(0x2001); // c.jal in relaxCall()
755 sec.relaxAux->relocTypes[i] = R_RISCV_JAL; in relaxCall()
756 sec.relaxAux->writes.push_back(0x6f | rd << 7); // jal in relaxCall()
761 // Relax local-exec TLS when hi20 is zero.
764 uint64_t val = r.sym->getVA(r.addend); in relaxTlsLe()
772 sec.relaxAux->relocTypes[i] = R_RISCV_RELAX; in relaxTlsLe()
777 sec.relaxAux->relocTypes[i] = R_RISCV_32; in relaxTlsLe()
779 sec.relaxAux->writes.push_back(setLO12_I(insn, val)); in relaxTlsLe()
783 sec.relaxAux->relocTypes[i] = R_RISCV_32; in relaxTlsLe()
785 sec.relaxAux->writes.push_back(setLO12_S(insn, val)); in relaxTlsLe()
796 if (!isInt<12>(r.sym->getVA(r.addend) - gp->getVA())) in relaxHi20Lo12()
802 sec.relaxAux->relocTypes[i] = R_RISCV_RELAX; in relaxHi20Lo12()
806 sec.relaxAux->relocTypes[i] = INTERNAL_R_RISCV_GPREL_I; in relaxHi20Lo12()
809 sec.relaxAux->relocTypes[i] = INTERNAL_R_RISCV_GPREL_S; in relaxHi20Lo12()
826 const uint64_t loc = secAddr + r.offset - delta; in relax()
833 remove = nextLoc - ((loc + align - 1) & -align); in relax()
866 !hi20(r.sym->getVA(r.addend)); in relax()
884 sa[0].d->size = sa[0].offset - delta - sa[0].d->value; in relax()
886 sa[0].d->value = sa[0].offset - delta; in relax()
897 a.d->size = a.offset - delta - a.d->value; in relax()
899 a.d->value = a.offset - delta; in relax()
916 llvm::TimeTraceScope timeScope("RISC-V relaxOnce"); in relaxOnce()
917 if (config->relocatable) in relaxOnce()
926 if (!(osec->flags & SHF_EXECINSTR)) in relaxOnce()
935 llvm::TimeTraceScope timeScope("Finalize RISC-V relaxation"); in finalizeRelax()
939 if (!(osec->flags & SHF_EXECINSTR)) in finalizeRelax()
942 RelaxAux &aux = *sec->relaxAux; in finalizeRelax()
946 MutableArrayRef<Relocation> rels = sec->relocs(); in finalizeRelax()
947 ArrayRef<uint8_t> old = sec->content(); in finalizeRelax()
948 size_t newSize = old.size() - aux.relocDeltas[rels.size() - 1]; in finalizeRelax()
953 sec->content_ = p; in finalizeRelax()
954 sec->size = newSize; in finalizeRelax()
955 sec->bytesDropped = 0; in finalizeRelax()
960 uint32_t remove = aux.relocDeltas[i] - delta; in finalizeRelax()
967 uint64_t size = r.offset - offset; in finalizeRelax()
974 // we are in the middle of a 4-byte NOP, and we need to rewrite the NOP in finalizeRelax()
979 skip = r.addend - remove; in finalizeRelax()
1019 memcpy(p, old.data() + offset, old.size() - offset); in finalizeRelax()
1028 rels[i].offset -= delta; in finalizeRelax()
1032 delta = aux.relocDeltas[i - 1]; in finalizeRelax()
1039 // Representation of the merged .riscv.attributes input sections. The psABI
1062 StringRef s) { in mergeArch() argument
1063 auto maybeInfo = RISCVISAInfo::parseNormalizedArchString(s); in mergeArch()
1065 errorOrWarn(toString(sec) + ": " + s + ": " + in mergeArch()
1079 if (std::tie(p.first->second.Major, p.first->second.Minor) < in mergeArch()
1081 p.first->second = ext.second; in mergeArch()
1098 errorOrWarn("atomic abi mismatch for " + oldSection->name + "\n>>> " + in mergeAtomic()
1114 errorOrWarn("unknown atomic abi for " + section->name + "\n>>> " + in mergeAtomic()
1120 it->getSecond() = static_cast<unsigned>(newTag); in mergeAtomic()
1125 it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A6C); in mergeAtomic()
1139 it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A6C); in mergeAtomic()
1142 it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A7); in mergeAtomic()
1153 it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A7); in mergeAtomic()
1182 auto &merged = static_cast<RISCVAttributesSection &>(*in.riscvAttributes); in mergeAttributesSection() local
1188 if (Error e = parser.parse(sec->content(), llvm::endianness::little)) in mergeAttributesSection()
1195 auto r = merged.intAttr.try_emplace(tag.attr, *i); in mergeAttributesSection()
1199 } else if (r.first->second != *i) { in mergeAttributesSection()
1208 merged.intAttr[tag.attr] |= *i; in mergeAttributesSection()
1213 if (auto s = parser.getAttributeString(tag.attr)) { in mergeAttributesSection() local
1215 mergeArch(exts, xlen, sec, *s); in mergeAttributesSection()
1227 auto r = merged.intAttr.try_emplace(tag.attr, *i); in mergeAttributesSection()
1232 static_cast<RISCVAtomicAbiTag>(r.first->getSecond()), in mergeAttributesSection()
1242 // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/352 in mergeAttributesSection()
1245 auto r = merged.intAttr.try_emplace(tag.attr, *i); in mergeAttributesSection()
1246 if (!r.second && r.first->second != *i) in mergeAttributesSection()
1247 r.first->second = 0; in mergeAttributesSection()
1249 } else if (auto s = parser.getAttributeString(tag.attr)) { in mergeAttributesSection() local
1250 auto r = merged.strAttr.try_emplace(tag.attr, *s); in mergeAttributesSection()
1251 if (!r.second && r.first->second != *s) in mergeAttributesSection()
1252 r.first->second = {}; in mergeAttributesSection()
1259 merged.strAttr.try_emplace(RISCVAttrs::ARCH, in mergeAttributesSection()
1260 saver().save((*result)->toString())); in mergeAttributesSection()
1266 // The total size of headers: format-version [ <section-length> "vendor-name" in mergeAttributesSection()
1267 // [ <file-tag> <size>. in mergeAttributesSection()
1268 size_t size = 5 + merged.vendor.size() + 1 + 5; in mergeAttributesSection()
1269 for (auto &attr : merged.intAttr) in mergeAttributesSection()
1272 for (auto &attr : merged.strAttr) in mergeAttributesSection()
1275 merged.size = size; in mergeAttributesSection()
1276 return &merged; in mergeAttributesSection()
1283 write32(buf + 1, size - 1); in writeTo()
1290 write32(buf + 1, end - buf); in writeTo()
1312 [](auto *s) { return s->type == SHT_RISCV_ATTRIBUTES; }) - in mergeRISCVAttributesSections() argument
1319 llvm::erase_if(ctx.inputSections, [&](InputSectionBase *s) { in mergeRISCVAttributesSections() argument
1320 if (s->type != SHT_RISCV_ATTRIBUTES) in mergeRISCVAttributesSections()
1322 sections.push_back(s); in mergeRISCVAttributesSections()
1326 // Add the merged section. in mergeRISCVAttributesSections()