LLVM  14.0.0git
Classes | Enumerations | Functions | Variables
llvm::jitlink::x86_64 Namespace Reference

Classes

class  GOTTableManager
 Global Offset Table Builder. More...
 
class  PLTTableManager
 Procedure Linkage Table Builder. More...
 

Enumerations

enum  EdgeKind_x86_64 : Edge::Kind {
  Pointer64 = Edge::FirstRelocation, Pointer32, Pointer32Signed, Delta64,
  Delta32, NegDelta64, NegDelta32, Delta64FromGOT,
  BranchPCRel32, BranchPCRel32ToPtrJumpStub, BranchPCRel32ToPtrJumpStubBypassable, RequestGOTAndTransformToDelta32,
  RequestGOTAndTransformToDelta64, RequestGOTAndTransformToDelta64FromGOT, PCRel32GOTLoadRelaxable, PCRel32GOTLoadREXRelaxable,
  RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable, RequestGOTAndTransformToPCRel32GOTLoadRelaxable, PCRel32TLVPLoadREXRelaxable, RequestTLSDescInGOTAndTransformToDelta32,
  RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable
}
 Represents x86-64 fixups and other x86-64-specific edge kinds. More...
 

Functions

const char * getEdgeKindName (Edge::Kind K)
 Returns a string name for the given x86-64 edge. More...
 
bool isInRangeForImmU32 (uint64_t Value)
 Returns true if the given uint64_t value is in range for a uint32_t. More...
 
bool isInRangeForImmS32 (int64_t Value)
 Returns true if the given int64_t value is in range for an int32_t. More...
 
Error applyFixup (LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol)
 Apply fixup expression for edge to block content. More...
 
SymbolcreateAnonymousPointer (LinkGraph &G, Section &PointerSection, Symbol *InitialTarget=nullptr, uint64_t InitialAddend=0)
 Creates a new pointer block in the given section and returns an anonymous symbol pointing to it. More...
 
BlockcreatePointerJumpStubBlock (LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)
 Create a jump stub block that jumps via the pointer at the given symbol. More...
 
SymbolcreateAnonymousPointerJumpStub (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. More...
 
Error optimizeGOTAndStubAccesses (LinkGraph &G)
 Optimize the GOT and Stub relocations if the edge target address is in range. More...
 

Variables

constexpr uint64_t PointerSize = 8
 x86_64 pointer size. More...
 
const char NullPointerContent [PointerSize]
 x86-64 null pointer content. More...
 
const char PointerJumpStubContent [6]
 x86-64 pointer jump stub content. More...
 

Enumeration Type Documentation

◆ EdgeKind_x86_64

Represents x86-64 fixups and other x86-64-specific edge kinds.

Enumerator
Pointer64 

A plain 64-bit pointer value relocation.

Fixup expression: Fixup <- Target + Addend : uint64

Pointer32 

A plain 32-bit pointer value relocation.

Fixup expression: Fixup <- Target + Addend : uint32

Errors:

  • The target must reside in the low 32-bits of the address space, otherwise an out-of-range error will be returned.
Pointer32Signed 

A signed 32-bit pointer value relocation.

Fixup expression: Fixup <- Target + Addend : int32

Errors:

  • The target must reside in the signed 32-bits([-2**31, 2**32 - 1]) of the address space, otherwise an out-of-range error will be returned.
Delta64 

A 64-bit delta.

Delta from the fixup to the target.

Fixup expression: Fixup <- Target - Fixup + Addend : int64

Delta32 

A 32-bit delta.

Delta from the fixup to the target.

Fixup expression: Fixup <- Target - Fixup + Addend : int64

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
NegDelta64 

A 64-bit negative delta.

Delta from target back to the fixup.

Fixup expression: Fixup <- Fixup - Target + Addend : int64

NegDelta32 

A 32-bit negative delta.

Delta from the target back to the fixup.

Fixup expression: Fixup <- Fixup - Target + Addend : int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
Delta64FromGOT 

A 64-bit GOT delta.

Delta from the global offset table to the target

Fixup expression: Fixup <- Target - GOTSymbol + Addend : int64

Errors:

  • ASSERTION Failure to a null pointer GOTSymbol, which the GOT section symbol was not been defined.
BranchPCRel32 

A 32-bit PC-relative branch.

Represents a PC-relative call or branch to a target. This can be used to identify, record, and/or patch call sites.

The fixup expression for this kind includes an implicit offset to account for the PC (unlike the Delta edges) so that a Branch32PCRel with a target T and addend zero is a call/branch to the start (offset zero) of T.

Fixup expression: Fixup <- Target - (Fixup + 4) + Addend : int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
BranchPCRel32ToPtrJumpStub 

A 32-bit PC-relative branch to a pointer jump stub.

The target of this relocation should be a pointer jump stub of the form:

.text
jmpq *tgtptr(%rip)
; ...
.data
tgtptr:
.quad 0

This edge kind has the same fixup expression as BranchPCRel32, but further identifies the call/branch as being to a pointer jump stub. For edges of this kind the jump stub should not be bypassed (use BranchPCRel32ToPtrJumpStubBypassable for that), but the pointer location target may be recorded to allow manipulation at runtime.

Fixup expression: Fixup <- Target - Fixup + Addend - 4 : int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
BranchPCRel32ToPtrJumpStubBypassable 

A relaxable version of BranchPCRel32ToPtrJumpStub.

The edge kind has the same fixup expression as BranchPCRel32ToPtrJumpStub, but identifies the call/branch as being to a pointer jump stub that may be bypassed with a direct jump to the ultimate target if the ultimate target is within range of the fixup location.

Fixup expression: Fixup <- Target - Fixup + Addend - 4: int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
RequestGOTAndTransformToDelta32 

A GOT entry getter/constructor, transformed to Delta32 pointing at the GOT entry for the original target.

Indicates that this edge should be transformed into a Delta32 targeting the GOT entry for the edge's current target, maintaining the same addend. A GOT entry for the target should be created if one does not already exist.

Edges of this kind are usually handled by a GOT builder pass inserted by default.

Fixup expression: NONE

Errors:

  • ASSERTION Failure to handle edges of this kind prior to the fixup phase will result in an assert/unreachable during the fixup phase.
RequestGOTAndTransformToDelta64 

A GOT entry getter/constructor, transformed to Delta64 pointing at the GOT entry for the original target.

Indicates that this edge should be transformed into a Delta64 targeting the GOT entry for the edge's current target, maintaining the same addend. A GOT entry for the target should be created if one does not already exist.

Edges of this kind are usually handled by a GOT builder pass inserted by default.

Fixup expression: NONE

Errors:

  • ASSERTION Failure to handle edges of this kind prior to the fixup phase will result in an assert/unreachable during the fixup phase.
RequestGOTAndTransformToDelta64FromGOT 

A GOT entry offset within GOT getter/constructor, transformed to Delta64FromGOT pointing at the GOT entry for the original target.

Indicates that this edge should be transformed into a Delta64FromGOT targeting the GOT entry for the edge's current target, maintaining the same addend. A GOT entry for the target should be created if one does not already exist.

Edges of this kind are usually handled by a GOT builder pass inserted by default

Fixup expression: NONE

Errors:

  • ASSERTION Failure to handle edges of this kind prior to the fixup phase will result in an assert/unreachable during the fixup phase
PCRel32GOTLoadRelaxable 

A PC-relative load of a GOT entry, relaxable if GOT entry target is in-range of the fixup.

TODO: Explain the optimization

Fixup expression Fixup <- Target - (Fixup + 4) + Addend : int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
PCRel32GOTLoadREXRelaxable 

A PC-relative REX load of a GOT entry, relaxable if GOT entry target is in-range of the fixup.

If the GOT entry target is in-range of the fixup then the load from the GOT may be replaced with a direct memory address calculation.

Fixup expression: Fixup <- Target - (Fixup + 4) + Addend : int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable 

A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadREXRelaxable pointing at the GOT entry for the original target.

Indicates that this edge should be lowered to a PC32ToGOTLoadREXRelaxable targeting the GOT entry for the edge's current target, maintaining the same addend. A GOT entry for the target should be created if one does not already exist.

Edges of this kind are usually lowered by a GOT builder pass inserted by default.

Fixup expression: NONE

Errors:

  • ASSERTION Failure to handle edges of this kind prior to the fixup phase will result in an assert/unreachable during the fixup phase.
RequestGOTAndTransformToPCRel32GOTLoadRelaxable 

A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadRelaxable pointing at the GOT entry for the original target.

Indicates that this edge should be lowered to a PC32ToGOTLoadRelaxable targeting the GOT entry for the edge's current target, maintaining the same addend. A GOT entry for the target should be created if one does not already exist.

Edges of this kind are usually lowered by a GOT builder pass inserted by default.

Fixup expression: NONE

Errors:

  • ASSERTION Failure to handle edges of this kind prior to the fixup phase will result in an assert/unreachable during the fixup phase.
PCRel32TLVPLoadREXRelaxable 

A PC-relative REX load of a Thread Local Variable Pointer (TLVP) entry, relaxable if the TLVP entry target is in-range of the fixup.

If the TLVP entry target is in-range of the fixup then the load from the TLVP may be replaced with a direct memory address calculation.

The target of this edge must be a thread local variable entry of the form .quad <tlv getter thunk> .quad <tlv key> .quad <tlv initializer>

Fixup expression: Fixup <- Target - (Fixup + 4) + Addend : int32

Errors:

  • The result of the fixup expression must fit into an int32, otherwise an out-of-range error will be returned.
  • The target must be either external, or a TLV entry of the required form, otherwise a malformed TLV entry error will be returned.
RequestTLSDescInGOTAndTransformToDelta32 

TODO: Explain the generic edge kind.

RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable 

A TLVP entry getter/constructor, transformed to Delta32ToTLVPLoadREXRelaxable.

Indicates that this edge should be transformed into a Delta32ToTLVPLoadREXRelaxable targeting the TLVP entry for the edge's current target. A TLVP entry for the target should be created if one does not already exist.

Fixup expression: NONE

Errors:

  • ASSERTION Failure to handle edges of this kind prior to the fixup phase will result in an assert/unreachable during the fixup phase.

Definition at line 26 of file x86_64.h.

Function Documentation

◆ applyFixup()

Error llvm::jitlink::x86_64::applyFixup ( LinkGraph G,
Block B,
const Edge E,
const Symbol GOTSymbol 
)
inline

◆ createAnonymousPointer()

Symbol& llvm::jitlink::x86_64::createAnonymousPointer ( LinkGraph G,
Section PointerSection,
Symbol InitialTarget = nullptr,
uint64_t  InitialAddend = 0 
)
inline

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)

Definition at line 483 of file x86_64.h.

References B, G, NullPointerContent, and Pointer64.

Referenced by llvm::jitlink::x86_64::GOTTableManager::createEntry().

◆ createAnonymousPointerJumpStub()

Symbol& llvm::jitlink::x86_64::createAnonymousPointerJumpStub ( LinkGraph G,
Section StubSection,
Symbol PointerSymbol 
)
inline

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.

Definition at line 511 of file x86_64.h.

References createPointerJumpStubBlock(), and G.

Referenced by llvm::jitlink::x86_64::PLTTableManager::createEntry().

◆ createPointerJumpStubBlock()

Block& llvm::jitlink::x86_64::createPointerJumpStubBlock ( LinkGraph G,
Section StubSection,
Symbol PointerSymbol 
)
inline

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)

Definition at line 499 of file x86_64.h.

References B, Delta32, G, and PointerJumpStubContent.

Referenced by createAnonymousPointerJumpStub().

◆ getEdgeKindName()

const char * llvm::jitlink::x86_64::getEdgeKindName ( Edge::Kind  K)

◆ isInRangeForImmS32()

bool llvm::jitlink::x86_64::isInRangeForImmS32 ( int64_t  Value)
inline

Returns true if the given int64_t value is in range for an int32_t.

Definition at line 359 of file x86_64.h.

References llvm::max(), and llvm::min().

Referenced by applyFixup(), and optimizeGOTAndStubAccesses().

◆ isInRangeForImmU32()

bool llvm::jitlink::x86_64::isInRangeForImmU32 ( uint64_t  Value)
inline

Returns true if the given uint64_t value is in range for a uint32_t.

Definition at line 354 of file x86_64.h.

Referenced by applyFixup(), and optimizeGOTAndStubAccesses().

◆ optimizeGOTAndStubAccesses()

Error llvm::jitlink::x86_64::optimizeGOTAndStubAccesses ( LinkGraph G)

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

Definition at line 74 of file x86_64.cpp.

References assert(), B, BranchPCRel32, BranchPCRel32ToPtrJumpStubBypassable, llvm::dbgs(), Delta32, E, G, getEdgeKindName(), isInRangeForImmS32(), isInRangeForImmU32(), LLVM_DEBUG, PCRel32GOTLoadRelaxable, PCRel32GOTLoadREXRelaxable, Pointer32, PointerJumpStubContent, llvm::jitlink::printEdge(), and llvm::Error::success().

Referenced by llvm::jitlink::link_ELF_x86_64(), and llvm::jitlink::link_MachO_x86_64().

Variable Documentation

◆ NullPointerContent

const char llvm::jitlink::x86_64::NullPointerContent
Initial value:
= {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00}

x86-64 null pointer content.

Definition at line 68 of file x86_64.cpp.

Referenced by createAnonymousPointer().

◆ PointerJumpStubContent

const char llvm::jitlink::x86_64::PointerJumpStubContent
Initial value:
= {
static_cast<char>(0xFFu), 0x25, 0x00, 0x00, 0x00, 0x00}

x86-64 pointer jump stub content.

Contains the instruction sequence for an indirect jump via an in-memory pointer: jmpq *ptr(rip)

Definition at line 71 of file x86_64.cpp.

Referenced by createPointerJumpStubBlock(), and optimizeGOTAndStubAccesses().

◆ PointerSize

constexpr uint64_t llvm::jitlink::x86_64::PointerSize = 8
constexpr