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