//===-- x86_64.h - Generic JITLink x86-64 edge kinds, utilities -*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Generic utilities for graphs representing x86-64 objects. // //===----------------------------------------------------------------------===// #ifndef LLVM_EXECUTIONENGINE_JITLINK_X86_64_H #define LLVM_EXECUTIONENGINE_JITLINK_X86_64_H #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/JITLink/TableManager.h" namespace llvm { namespace jitlink { namespace x86_64 { /// Represents x86-64 fixups and other x86-64-specific edge kinds. enum EdgeKind_x86_64 : Edge::Kind { … }; /// Returns a string name for the given x86-64 edge. For debugging purposes /// only. const char *getEdgeKindName(Edge::Kind K); /// Apply fixup expression for edge to block content. inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol) { … } /// x86_64 pointer size. constexpr uint64_t PointerSize = …; /// x86-64 null pointer content. extern const char NullPointerContent[PointerSize]; /// x86-64 pointer jump stub content. /// /// Contains the instruction sequence for an indirect jump via an in-memory /// pointer: /// jmpq *ptr(%rip) extern const char PointerJumpStubContent[6]; /// Creates a new pointer block in the given section and returns an anonymous /// symbol pointing to it. /// /// If InitialTarget is given then an Pointer64 relocation will be added to the /// block pointing at InitialTarget. /// /// The pointer block will have the following default values: /// alignment: 64-bit /// alignment-offset: 0 /// address: highest allowable (~7U) inline Symbol &createAnonymousPointer(LinkGraph &G, Section &PointerSection, Symbol *InitialTarget = nullptr, uint64_t InitialAddend = 0) { … } /// Create a jump stub block that jumps via the pointer at the given symbol. /// /// The stub block will have the following default values: /// alignment: 8-bit /// alignment-offset: 0 /// address: highest allowable: (~5U) inline Block &createPointerJumpStubBlock(LinkGraph &G, Section &StubSection, Symbol &PointerSymbol) { … } /// Create a jump stub that jumps via the pointer at the given symbol and /// an anonymous symbol pointing to it. Return the anonymous symbol. /// /// The stub block will be created by createPointerJumpStubBlock. inline Symbol &createAnonymousPointerJumpStub(LinkGraph &G, Section &StubSection, Symbol &PointerSymbol) { … } /// Global Offset Table Builder. class GOTTableManager : public TableManager<GOTTableManager> { … }; /// Procedure Linkage Table Builder. class PLTTableManager : public TableManager<PLTTableManager> { … }; /// Optimize the GOT and Stub relocations if the edge target address is in range /// 1. PCRel32GOTLoadRelaxable. For this edge kind, if the target is in range, /// then replace GOT load with lea /// 2. BranchPCRel32ToPtrJumpStubRelaxable. For this edge kind, if the target is /// in range, replace a indirect jump by plt stub with a direct jump to the /// target Error optimizeGOTAndStubAccesses(LinkGraph &G); } // namespace x86_64 } // end namespace jitlink } // end namespace llvm #endif // LLVM_EXECUTIONENGINE_JITLINK_X86_64_H