Lines Matching +full:mc +full:- +full:sid
1 //===-- RuntimeDyldELF.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Implementation of ELF support for the MC-JIT runtime dynamic linker.
11 //===----------------------------------------------------------------------===//
52 uint64_t Mask = ((uint64_t)1 << (End + 1 - Start)) - 1; in getBits()
79 return v->isDyldType(); in classof()
91 this->isDyldELFObject = true; in DyldELFObject()
113 // The template-based type cast handles everything else. in updateSectionAddress()
114 shdr->sh_addr = static_cast<addr_type>(Addr); in updateSectionAddress()
125 // The template-based type cast handles everything else. in updateSymbolAddress()
126 sym->st_value = static_cast<addr_type>(Addr); in updateSymbolAddress()
156 for (const auto &Sec : Obj->sections()) { in createRTDyldELFObject()
170 // bitness. The template-based type cast handles everything else. in createRTDyldELFObject()
171 shdr->sh_addr = static_cast<addr_type>(SecLoadAddr); in createRTDyldELFObject()
191 createRTDyldELFObject<ELF32LE>(Buffer->getMemBufferRef(), Obj, L); in createELFDebugObject()
194 createRTDyldELFObject<ELF32BE>(Buffer->getMemBufferRef(), Obj, L); in createELFDebugObject()
197 createRTDyldELFObject<ELF64BE>(Buffer->getMemBufferRef(), Obj, L); in createELFDebugObject()
200 createRTDyldELFObject<ELF64LE>(Buffer->getMemBufferRef(), Obj, L); in createELFDebugObject()
223 for (SID EHFrameSID : UnregisteredEHFrameSections) { in registerEHFrames()
310 int64_t RealOffset = Value + Addend - FinalAddress; in resolveX86_64Relocation()
318 int64_t RealOffset = Value + Addend - FinalAddress; in resolveX86_64Relocation()
327 int64_t RealOffset = Value + Addend - FinalAddress; in resolveX86_64Relocation()
335 // Compute Value - GOTBase. in resolveX86_64Relocation()
344 int64_t GOTOffset = Value - GOTBase + Addend; in resolveX86_64Relocation()
392 uint32_t RealOffset = Value + Addend - FinalAddress; in resolveX86Relocation()
445 uint64_t Result = Value + Addend - FinalAddress; in resolveAArch64Relocation()
452 uint64_t Result = Value + Addend - FinalAddress; in resolveAArch64Relocation()
459 uint64_t Result = Value + Addend - FinalAddress; in resolveAArch64Relocation()
466 write(isBE, TargetPtr, Value + Addend - FinalAddress); in resolveAArch64Relocation()
469 uint64_t BranchImm = Value + Addend - FinalAddress; in resolveAArch64Relocation()
478 uint64_t BranchImm = Value + Addend - FinalAddress; in resolveAArch64Relocation()
491 // Operation: S+A-P. Set Call or B immediate value to bits fff_fffc of the in resolveAArch64Relocation()
493 uint64_t BranchImm = Value + Addend - FinalAddress; in resolveAArch64Relocation()
495 // "Check that -2^27 <= result < 2^27". in resolveAArch64Relocation()
513 // Operation: Page(S+A) - Page(P) in resolveAArch64Relocation()
515 ((Value + Addend) & ~0xfffULL) - (FinalAddress & ~0xfffULL); in resolveAArch64Relocation()
517 // Check that -2^32 <= X < 2^32 in resolveAArch64Relocation()
562 // Operation: S + A - P in resolveAArch64Relocation()
563 uint64_t Result = Value + Addend - FinalAddress; in resolveAArch64Relocation()
565 // "Check that -2^20 <= result < 2^20". in resolveAArch64Relocation()
571 *TargetPtr |= ((Result & 0xffc) << (5 - 2)); in resolveAArch64Relocation()
575 // Operation: S + A - P in resolveAArch64Relocation()
576 uint64_t Result = Value + Addend - FinalAddress; in resolveAArch64Relocation()
578 // "Check that -2^20 <= result < 2^20". in resolveAArch64Relocation()
584 *TargetPtr |= ((Result & 0xffc) << (5 - 2)); in resolveAArch64Relocation()
617 ((Value - FinalAddress) & ~0x80000000); in resolveARMRelocation()
639 int32_t RelValue = static_cast<int32_t>(Value - FinalAddress - 8); in resolveARMRelocation()
657 unsigned AbiVariant = E->getPlatformFlags(); in setMipsABI()
661 IsMipsN64ABI = Obj.getFileFormatName() == "elf64-mips"; in setMipsABI()
697 // Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000 in findPPC64TOCSection()
714 Expected<section_iterator> RelSecOrErr = si->getRelocatedSection(); in findOPDEntrySection()
722 Expected<StringRef> NameOrErr = RelSecI->getName(); in findOPDEntrySection()
730 for (elf_relocation_iterator i = si->relocation_begin(), in findOPDEntrySection()
731 e = si->relocation_end(); in findOPDEntrySection()
735 uint64_t TypeFunc = i->getType(); in findOPDEntrySection()
741 uint64_t TargetSymbolOffset = i->getOffset(); in findOPDEntrySection()
742 symbol_iterator TargetSymbol = i->getSymbol(); in findOPDEntrySection()
744 if (auto AddendOrErr = i->getAddend()) in findOPDEntrySection()
754 uint64_t TypeTOC = i->getType(); in findOPDEntrySection()
765 if (auto TSIOrErr = TargetSymbol->getSection()) in findOPDEntrySection()
771 bool IsCode = TSI->isText(); in findOPDEntrySection()
786 // macros defined in section 4.5.1. Relocation Types of the PPC-elf64abi
883 uint64_t Delta = Value - FinalAddress + Addend; in resolvePPC64Relocation()
888 uint64_t Delta = Value - FinalAddress + Addend; in resolvePPC64Relocation()
893 uint64_t Delta = Value - FinalAddress + Addend; in resolvePPC64Relocation()
904 int64_t delta = static_cast<int64_t>(Value - FinalAddress + Addend); in resolvePPC64Relocation()
913 int64_t delta = static_cast<int64_t>(Value - FinalAddress + Addend); in resolvePPC64Relocation()
920 uint64_t Delta = Value - FinalAddress + Addend; in resolvePPC64Relocation()
939 int64_t Delta = (Value + Addend) - Section.getLoadAddressWithOffset(Offset); in resolveSystemZRelocation()
946 int64_t Delta = (Value + Addend) - Section.getLoadAddressWithOffset(Offset); in resolveSystemZRelocation()
952 int64_t Delta = (Value + Addend) - Section.getLoadAddressWithOffset(Offset); in resolveSystemZRelocation()
958 int64_t Delta = (Value + Addend) - Section.getLoadAddressWithOffset(Offset); in resolveSystemZRelocation()
964 int64_t Delta = (Value + Addend) - Section.getLoadAddressWithOffset(Offset); in resolveSystemZRelocation()
1044 uint64_t SymOffset, SID SectionID) { in resolveRelocation()
1140 const auto &SymInfo = Loc->second; in resolveAArch64ShortBranch()
1150 // branch is cross-section, we don't know exactly how far away it is. in resolveAArch64ShortBranch()
1154 uint64_t SourceOffset = RelI->getOffset(); in resolveAArch64ShortBranch()
1156 // R_AARCH64_CALL26 requires immediate to be in range -2^27 <= imm < 2^27 in resolveAArch64ShortBranch()
1159 if (!isInt<28>(TargetOffset + Value.Addend - SourceOffset)) in resolveAArch64ShortBranch()
1162 RelocationEntry RE(SectionID, SourceOffset, RelI->getType(), Value.Addend); in resolveAArch64ShortBranch()
1179 uint64_t Offset = RelI->getOffset(); in resolveAArch64Branch()
1180 unsigned RelType = RelI->getType(); in resolveAArch64Branch()
1185 Section.getLoadAddressWithOffset(i->second), RelType, 0); in resolveAArch64Branch()
1194 RelocationEntry REmovz_g3(SectionID, StubTargetAddr - Section.getAddress(), in resolveAArch64Branch()
1197 StubTargetAddr - Section.getAddress() + 4, in resolveAArch64Branch()
1200 StubTargetAddr - Section.getAddress() + 8, in resolveAArch64Branch()
1203 StubTargetAddr - Section.getAddress() + 12, in resolveAArch64Branch()
1229 uint64_t RelType = RelI->getType(); in processRelocationRef()
1235 elf_symbol_iterator Symbol = RelI->getSymbol(); in processRelocationRef()
1240 if (auto TargetNameOrErr = Symbol->getName()) in processRelocationRef()
1255 Expected<SymbolRef::Type> SymTypeOrErr = Symbol->getType(); in processRelocationRef()
1265 const auto &SymInfo = gsi->second; in processRelocationRef()
1275 auto SectionOrErr = Symbol->getSection(); in processRelocationRef()
1286 bool isCode = si->isText(); in processRelocationRef()
1316 uint64_t Offset = RelI->getOffset(); in processRelocationRef()
1350 Section.getLoadAddressWithOffset(i->second), RelType, in processRelocationRef()
1359 RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(), in processRelocationRef()
1403 RelocationEntry RE(SectionID, Offset, RelType, i->second); in processRelocationRef()
1417 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(), in processRelocationRef()
1420 StubTargetAddr - Section.getAddress() + 4, in processRelocationRef()
1442 const RelocationValueRef &MatchingValue = I->first; in processRelocationRef()
1443 RelocationEntry &Reloc = I->second; in processRelocationRef()
1481 RE.SymOffset = i->second; in processRelocationRef()
1498 RelocationEntry RE(SectionID, Offset, RelType, i->second); in processRelocationRef()
1513 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(), in processRelocationRef()
1516 StubTargetAddr - Section.getAddress() + 4, in processRelocationRef()
1529 StubTargetAddr - Section.getAddress(), in processRelocationRef()
1532 StubTargetAddr - Section.getAddress() + 4, in processRelocationRef()
1535 StubTargetAddr - Section.getAddress() + 12, in processRelocationRef()
1538 StubTargetAddr - Section.getAddress() + 20, in processRelocationRef()
1568 // signed 24-bits branch address. in processRelocationRef()
1584 uint8_t SymOther = Symbol->getOther(); in processRelocationRef()
1590 int64_t delta = static_cast<int64_t>(Target - RelocTarget); in processRelocationRef()
1591 // If it is within 26-bits branch range, just set the branch target in processRelocationRef()
1608 Section.getLoadAddressWithOffset(i->second), in processRelocationRef()
1618 RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(), in processRelocationRef()
1621 // Generates the 64-bits address loads as exemplified in section in processRelocationRef()
1625 uint64_t StubRelocOffset = StubTargetAddr - Section.getAddress(); in processRelocationRef()
1695 Value.Addend -= TOCValue.Addend; in processRelocationRef()
1737 StubAddress = uintptr_t(Section.getAddressWithOffset(i->second)); in processRelocationRef()
1746 unsigned StubOffset = StubAddress - BaseAddress; in processRelocationRef()
1768 // PLT and this relocation makes a PC-relative call into the PLT. The PLT in processRelocationRef()
1776 // into a PC-relative call directly to the function. For external symbols we in processRelocationRef()
1789 StubAddress = uintptr_t(Section->getAddress()) + i->second; in processRelocationRef()
1795 uintptr_t BaseAddress = uintptr_t(Section->getAddress()); in processRelocationRef()
1796 StubAddress = alignTo(BaseAddress + Section->getStubOffset(), in processRelocationRef()
1798 unsigned StubOffset = StubAddress - BaseAddress; in processRelocationRef()
1803 Section->advanceStubOffset(getMaxStubSize()); in processRelocationRef()
1811 // The load of the GOT address has an addend of -4 in processRelocationRef()
1812 resolveGOTOffsetRelocation(SectionID, StubOffset + 2, GOTOffset - 4, in processRelocationRef()
1844 // Fill in a 64-bit GOT offset. in processRelocationRef()
1900 // Use the approach from "x86-64 Linker Optimizations" from the TLS spec in processX86_64GOTTPOFFRelocation()
1966 (Offset - C.TLSSequenceOffset + C.NewCodeSequence.size()) > in processX86_64GOTTPOFFRelocation()
1973 auto TLSSequenceStartOffset = Offset - C.TLSSequenceOffset; in processX86_64GOTTPOFFRelocation()
1988 ELF::R_X86_64_TPOFF32, Value.Addend - Addend); in processX86_64GOTTPOFFRelocation()
2021 // Use the approach from "x86-64 Linker Optimizations" from the TLS spec in processX86_64TLSRelocation()
2029 // Is the relocation for the __tls_get_addr a PC-relative GOT relocation? in processX86_64TLSRelocation()
2066 0x66, // data16 (no-op prefix) in processX86_64TLSRelocation()
2070 0x48, // rex64 (no-op prefix) in processX86_64TLSRelocation()
2079 0x66, // data16 (no-op prefix) in processX86_64TLSRelocation()
2082 0x66, // data16 prefix (no-op prefix) in processX86_64TLSRelocation()
2083 0x48, // rex64 (no-op prefix) in processX86_64TLSRelocation()
2125 // The TLSGD/TLSLD relocations are PC-relative, so they have an addend. in processX86_64TLSRelocation()
2128 RelocationEntry RE(SectionID, Offset - TLSSequenceOffset + TpoffRelocOffset, in processX86_64TLSRelocation()
2129 ELF::R_X86_64_TPOFF32, Value.Addend - Addend); in processX86_64TLSRelocation()
2146 0x66, 0x66, 0x66, // three data16 prefixes (no-op) in processX86_64TLSRelocation()
2189 0x66, 0x66, 0x66, // three data16 prefixes (no-op) in processX86_64TLSRelocation()
2205 (Offset - TLSSequenceOffset + NewCodeSequence.size()) > in processX86_64TLSRelocation()
2210 auto *TLSSequence = Section.getAddressWithOffset(Offset - TLSSequenceOffset); in processX86_64TLSRelocation()
2281 E.first->second = GOTOffset; in findOrAllocGOTEntry()
2284 return E.first->second; in findOrAllocGOTEntry()
2378 // needed when GOT-based relocations are applied. in finalizeLoad()
2385 if (SI->relocation_begin() != SI->relocation_end()) { in finalizeLoad()
2386 Expected<section_iterator> RelSecOrErr = SI->getRelocatedSection(); in finalizeLoad()
2394 SectionToGOTMap[i->second] = GOTSectionID; in finalizeLoad()
2404 const SectionRef &Section = i->first; in finalizeLoad()
2414 UnregisteredEHFrameSections.push_back(i->second); in finalizeLoad()
2441 // clang-format off in createIFuncResolver()
2461 // clang-format on in createIFuncResolver()
2480 // The first instruction loads a PC-relative address into %r11 which is a in createIFuncStub()
2488 // entry. As mentioned above, we do this two-step jump by first setting in createIFuncStub()
2500 // IFuncStubOffset+3: 32-bit PC-relative address of GOT1. in createIFuncStub()
2518 // The PC-relative value starts 4 bytes from the end of the leaq in createIFuncStub()
2519 // instruction, so the addend is -4. in createIFuncStub()
2521 GOT1 - 4, ELF::R_X86_64_PC32); in createIFuncStub()