Lines Matching +full:os +full:- +full:manifest +full:- +full:offset

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);
260 uint64_t Offset, uint64_t Value,
273 *Section.getAddressWithOffset(Offset) = TruncatedAddr;
275 << format("%p\n", Section.getAddressWithOffset(Offset)));
282 support::ulittle16_t::ref(Section.getAddressWithOffset(Offset)) =
285 << format("%p\n", Section.getAddressWithOffset(Offset)));
289 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) =
292 << format("%p\n", Section.getAddressWithOffset(Offset)));
302 support::ulittle32_t::ref(Section.getAddressWithOffset(Offset)) =
305 << format("%p\n", Section.getAddressWithOffset(Offset)));
309 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
310 int64_t RealOffset = Value + Addend - FinalAddress;
313 Section.getAddress()[Offset] = TruncOffset;
317 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
318 int64_t RealOffset = Value + Addend - FinalAddress;
321 support::ulittle32_t::ref(Section.getAddressWithOffset(Offset)) =
326 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
327 int64_t RealOffset = Value + Addend - FinalAddress;
328 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) =
335 // Compute Value - GOTBase.
344 int64_t GOTOffset = Value - GOTBase + Addend;
345 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) = GOTOffset;
350 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) = 1;
355 // DTPOFF64 should resolve to the offset in the TLS block, TPOFF64 to the
356 // offset in the *initial* TLS block. Since we are statically linking, all
359 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) =
370 support::ulittle32_t::ref(Section.getAddressWithOffset(Offset)) =
378 uint64_t Offset, uint32_t Value,
382 support::ulittle32_t::ref(Section.getAddressWithOffset(Offset)) =
391 Section.getLoadAddressWithOffset(Offset) & 0xFFFFFFFF;
392 uint32_t RealOffset = Value + Addend - FinalAddress;
393 support::ulittle32_t::ref(Section.getAddressWithOffset(Offset)) =
406 uint64_t Offset, uint64_t Value,
409 reinterpret_cast<uint32_t *>(Section.getAddressWithOffset(Offset));
410 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
415 << format("%llx", Section.getAddressWithOffset(Offset))
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));
592 uint64_t Offset, uint32_t Value,
596 reinterpret_cast<uint32_t *>(Section.getAddressWithOffset(Offset));
597 uint32_t FinalAddress = Section.getLoadAddressWithOffset(Offset) & 0xFFFFFFFF;
601 << Section.getAddressWithOffset(Offset)
613 // Write a 31bit signed offset
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";
664 // Return the .TOC. section and offset.
697 // Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000
704 // Returns the sections and offset associated with the ODP entry referenced
709 // Get the ELF symbol value (st_value) to compare with Relocation offset in
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();
758 // Finally compares the Symbol value and the target symbol offset
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
816 uint64_t Offset, uint64_t Value,
818 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
836 uint64_t Offset, uint64_t Value,
838 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
882 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
883 uint64_t Delta = Value - FinalAddress + Addend;
887 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
888 uint64_t Delta = Value - FinalAddress + Addend;
892 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
893 uint64_t Delta = Value - FinalAddress + Addend;
903 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
904 int64_t delta = static_cast<int64_t>(Value - FinalAddress + Addend);
912 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
913 int64_t delta = static_cast<int64_t>(Value - FinalAddress + Addend);
919 uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset);
920 uint64_t Delta = Value - FinalAddress + Addend;
930 uint64_t Offset, uint64_t Value,
932 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
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);
984 uint64_t Offset, uint64_t Value,
998 write(isBE, Section.getAddressWithOffset(Offset), Value + Addend);
1000 << format("%p\n", Section.getAddressWithOffset(Offset)));
1006 write(isBE, Section.getAddressWithOffset(Offset), static_cast<uint32_t>(Value));
1008 << format("%p\n", Section.getAddressWithOffset(Offset)));
1015 // RE.Offset. RE.SectionID can be used to find the SectionEntry. Each
1037 return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend,
1042 uint64_t Offset, uint64_t Value,
1047 resolveX86_64Relocation(Section, Offset, Value, Type, Addend, SymOffset);
1050 resolveX86Relocation(Section, Offset, (uint32_t)(Value & 0xffffffffL), Type,
1055 resolveAArch64Relocation(Section, Offset, Value, Type, Addend);
1061 resolveARMRelocation(Section, Offset, (uint32_t)(Value & 0xffffffffL), Type,
1066 resolvePPC32Relocation(Section, Offset, Value, Type, Addend);
1070 resolvePPC64Relocation(Section, Offset, Value, Type, Addend);
1073 resolveSystemZRelocation(Section, Offset, Value, Type, Addend);
1077 resolveBPFRelocation(Section, Offset, Value, Type, Addend);
1084 void *RuntimeDyldELF::computePlaceholderAddress(unsigned SectionID, uint64_t Offset) const {
1085 return (void *)(Sections[SectionID].getObjAddress() + Offset);
1088 void RuntimeDyldELF::processSimpleRelocation(unsigned SectionID, uint64_t Offset, unsigned RelType, RelocationValueRef Value) {
1089 RelocationEntry RE(SectionID, Offset, RelType, Value.Addend, Value.Offset);
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();
1184 resolveRelocation(Section, Offset,
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,
1217 resolveRelocation(Section, Offset,
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();
1258 raw_string_ostream OS(Buf);
1259 logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
1260 report_fatal_error(Twine(OS.str()));
1265 const auto &SymInfo = gsi->second;
1267 Value.Offset = SymInfo.getOffset();
1275 auto SectionOrErr = Symbol->getSection();
1278 raw_string_ostream OS(Buf);
1279 logAllUnhandledErrors(SectionOrErr.takeError(), OS);
1280 report_fatal_error(Twine(OS.str()));
1286 bool isCode = si->isText();
1303 // will manifest here as a NULL symbol name.
1316 uint64_t Offset = RelI->getOffset();
1318 LLVM_DEBUG(dbgs() << "\t\tSectionID: " << SectionID << " Offset: " << Offset
1329 resolveGOTOffsetRelocation(SectionID, Offset, GOTOffset + Addend,
1334 resolveGOTOffsetRelocation(SectionID, Offset, GOTOffset + Addend,
1337 processSimpleRelocation(SectionID, Offset, RelType, Value);
1349 resolveRelocation(Section, Offset,
1350 Section.getLoadAddressWithOffset(i->second), RelType,
1359 RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(),
1367 Section, Offset,
1374 reinterpret_cast<uint32_t*>(computePlaceholderAddress(SectionID, Offset));
1382 processSimpleRelocation(SectionID, Offset, RelType, Value);
1386 computePlaceholderAddress(SectionID, Offset));
1403 RelocationEntry RE(SectionID, Offset, RelType, i->second);
1417 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
1420 StubTargetAddr - Section.getAddress() + 4,
1431 RelocationEntry RE(SectionID, Offset, RelType, Section.getStubOffset());
1437 RelocationEntry RE(SectionID, Offset, RelType, Addend);
1442 const RelocationValueRef &MatchingValue = I->first;
1443 RelocationEntry &Reloc = I->second;
1456 RelocationEntry RE(SectionID, Offset, RelType, Addend);
1472 processSimpleRelocation(SectionID, Offset, RelType, Value);
1476 RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
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,
1552 RelocationEntry RE(SectionID, Offset, RelType, Section.getStubOffset());
1557 processSimpleRelocation(SectionID, Offset, RelType, Value);
1568 // signed 24-bits branch address.
1570 uint8_t *Target = Section.getAddressWithOffset(Offset);
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
1596 RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
1607 resolveRelocation(Section, Offset,
1608 Section.getLoadAddressWithOffset(i->second),
1618 RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(),
1621 // Generates the 64-bits address loads as exemplified in section
1624 // the offset according to the target endianness.
1625 uint64_t StubRelocOffset = StubTargetAddr - Section.getAddress();
1651 Section, Offset,
1695 Value.Addend -= TOCValue.Addend;
1696 resolveRelocation(Sections[SectionID], Offset, Value.Addend, RelType, 0);
1712 RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
1737 StubAddress = uintptr_t(Section.getAddressWithOffset(i->second));
1746 unsigned StubOffset = StubAddress - BaseAddress;
1751 Value.Offset);
1760 resolveRelocation(Section, Offset, StubAddress + 8, ELF::R_390_PC32DBL,
1763 resolveRelocation(Section, Offset, StubAddress, RelType, Addend);
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;
1802 // Bump our stub offset counter
1803 Section->advanceStubOffset(getMaxStubSize());
1811 // The load of the GOT address has an addend of -4
1812 resolveGOTOffsetRelocation(SectionID, StubOffset + 2, GOTOffset - 4,
1822 resolveRelocation(*Section, Offset, StubAddress, ELF::R_X86_64_PC32,
1826 computePlaceholderAddress(SectionID, Offset));
1827 processSimpleRelocation(SectionID, Offset, ELF::R_X86_64_PC32, Value);
1833 resolveGOTOffsetRelocation(SectionID, Offset, GOTOffset + Addend,
1838 computeGOTOffsetRE(GOTOffset, Value.Offset, ELF::R_X86_64_64);
1844 // Fill in a 64-bit GOT offset.
1846 resolveRelocation(Sections[SectionID], Offset, GOTOffset,
1851 computeGOTOffsetRE(GOTOffset, Value.Offset, ELF::R_X86_64_64);
1861 resolveGOTOffsetRelocation(SectionID, Offset, Addend, ELF::R_X86_64_PC32);
1864 resolveGOTOffsetRelocation(SectionID, Offset, Addend, ELF::R_X86_64_PC64);
1868 processSimpleRelocation(SectionID, Offset, RelType, Value);
1870 Value.Addend += support::ulittle32_t::ref(computePlaceholderAddress(SectionID, Offset));
1871 processSimpleRelocation(SectionID, Offset, RelType, Value);
1873 Value.Addend += support::ulittle64_t::ref(computePlaceholderAddress(SectionID, Offset));
1874 processSimpleRelocation(SectionID, Offset, RelType, Value);
1876 processX86_64GOTTPOFFRelocation(SectionID, Offset, Value, Addend);
1882 processX86_64TLSRelocation(SectionID, Offset, RelType, Value, Addend,
1885 processSimpleRelocation(SectionID, Offset, RelType, Value);
1889 Value.Addend += support::ulittle32_t::ref(computePlaceholderAddress(SectionID, Offset));
1891 processSimpleRelocation(SectionID, Offset, RelType, Value);
1897 uint64_t Offset,
1900 // Use the approach from "x86-64 Linker Optimizations" from the TLS spec
1910 // The negative offset of the GOTTPOFF relocation to the beginning of
1915 // The offset of the new TPOFF relocation
1965 if (Offset < C.TLSSequenceOffset ||
1966 (Offset - C.TLSSequenceOffset + C.NewCodeSequence.size()) >
1973 auto TLSSequenceStartOffset = Offset - C.TLSSequenceOffset;
1984 // absolute value (which is an offset from %fs:0), so remove the addend
1988 ELF::R_X86_64_TPOFF32, Value.Addend - Addend);
2004 resolveGOTOffsetRelocation(SectionID, Offset, GOTOffset + Addend,
2007 computeGOTOffsetRE(GOTOffset, Value.Offset, ELF::R_X86_64_TPOFF64);
2016 unsigned SectionID, uint64_t Offset, uint64_t RelType,
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?
2050 // The negative offset to the start of the TLS code sequence relative to
2051 // the offset of the TLSGD/TLSLD relocation
2059 // The offset of the new TPOFF32 relocation (offset starting from the
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.
2126 // The new TPOFF32 relocations is used as an absolute offset from
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)
2204 if (Offset < TLSSequenceOffset ||
2205 (Offset - TLSSequenceOffset + NewCodeSequence.size()) >
2210 auto *TLSSequence = Section.getAddressWithOffset(Offset - TLSSequenceOffset);
2275 computeGOTOffsetRE(GOTOffset, Value.Offset, GOTRelType);
2281 E.first->second = GOTOffset;
2284 return E.first->second;
2288 uint64_t Offset,
2292 RelocationEntry GOTRE(SectionID, Offset, Type, GOTOffset);
2353 << " Offset: " << format("%p", Symbol.getOffset())
2365 // If necessary, allocate the global offset table
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);