LLVM 22.0.0git
Classes | Enumerations | Functions | Variables
llvm::jitlink::x86 Namespace Reference

Classes

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

Enumerations

enum  EdgeKind_x86 : Edge::Kind {
  Pointer32 = Edge::FirstRelocation , PCRel32 , Pointer16 , PCRel16 ,
  Delta32 , Delta32FromGOT , RequestGOTAndTransformToDelta32FromGOT , BranchPCRel32 ,
  BranchPCRel32ToPtrJumpStub , BranchPCRel32ToPtrJumpStubBypassable
}
 Represets x86 fixups. More...
 

Functions

LLVM_ABI const chargetEdgeKindName (Edge::Kind K)
 Returns a string name for the given x86 edge.
 
Error applyFixup (LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol)
 Apply fixup expression for edge to block content.
 
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.
 
BlockcreatePointerJumpStubBlock (LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)
 Create a jump stub block that jumps via the pointer at the given symbol.
 
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.
 
LLVM_ABI Error optimizeGOTAndStubAccesses (LinkGraph &G)
 Optimize the GOT and Stub relocations if the edge target address is in range.
 

Variables

constexpr uint32_t PointerSize = 4
 x86 pointer size.
 
LLVM_ABI const char NullPointerContent [PointerSize] = {0x00, 0x00, 0x00, 0x00}
 x86 null pointer content.
 
LLVM_ABI const char PointerJumpStubContent [6]
 x86 pointer jump stub content.
 

Enumeration Type Documentation

◆ EdgeKind_x86

Represets x86 fixups.

Enumerator
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.
PCRel32 

A 32-bit PC-relative relocation.

Represents a data/control flow instruction using PC-relative addressing to a target.

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

Errors:

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

A plain 16-bit pointer value relocation.

Fixup expression: Fixup <- Target + Addend : uint16

Errors:

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

A 16-bit PC-relative relocation.

Represents a data/control flow instruction using PC-relative addressing to a target.

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

Errors:

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

A 32-bit delta.

Delta from the fixup to the target.

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

Errors:

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

A 32-bit GOT delta.

Delta from the global offset table to the target.

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

Errors:

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

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

Indicates that this edge should be transformed into a Delta32FromGOT 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
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.

Fixup expression: Fixup <- Target - Fixup + 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
jmp *tgtptr
; ...
.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 : 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 : int32

Errors:

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

Definition at line 23 of file x86.h.

Function Documentation

◆ applyFixup()

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

◆ createAnonymousPointer()

Symbol & llvm::jitlink::x86::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 Pointer32 relocation will be added to the block pointing at InitialTarget.

The pointer block will have the following default values: alignment: 32-bit alignment-offset: 0 address: highest allowable (~7U)

Definition at line 277 of file x86.h.

References B, G, NullPointerContent, Pointer32, and PointerSize.

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

◆ createAnonymousPointerJumpStub()

Symbol & llvm::jitlink::x86::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 309 of file x86.h.

References createPointerJumpStubBlock(), and G.

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

◆ createPointerJumpStubBlock()

Block & llvm::jitlink::x86::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 293 of file x86.h.

References B, G, Pointer32, and PointerJumpStubContent.

Referenced by createAnonymousPointerJumpStub().

◆ getEdgeKindName()

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

◆ optimizeGOTAndStubAccesses()

Error llvm::jitlink::x86::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. (THIS IS UNIMPLEMENTED RIGHT NOW!)
  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 51 of file x86.cpp.

References assert(), B, BranchPCRel32, BranchPCRel32ToPtrJumpStubBypassable, llvm::dbgs(), E, G, getEdgeKindName(), LLVM_DEBUG, PointerJumpStubContent, llvm::jitlink::printEdge(), and llvm::Error::success().

Variable Documentation

◆ NullPointerContent

const char llvm::jitlink::x86::NullPointerContent = {0x00, 0x00, 0x00, 0x00}

x86 null pointer content.

Definition at line 46 of file x86.cpp.

Referenced by createAnonymousPointer().

◆ PointerJumpStubContent

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

x86 pointer jump stub content.

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

Definition at line 48 of file x86.cpp.

Referenced by createPointerJumpStubBlock(), and optimizeGOTAndStubAccesses().

◆ PointerSize

constexpr uint32_t llvm::jitlink::x86::PointerSize = 4
constexpr

x86 pointer size.

Definition at line 255 of file x86.h.

Referenced by createAnonymousPointer().