LLVM 20.0.0git
Classes | Enumerations | Functions | Variables
llvm::jitlink::i386 Namespace Reference

Classes

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

Enumerations

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

Functions

const chargetEdgeKindName (Edge::Kind K)
 Returns a string name for the given i386 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.
 
Error optimizeGOTAndStubAccesses (LinkGraph &G)
 Optimize the GOT and Stub relocations if the edge target address is in range.
 

Variables

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

Enumeration Type Documentation

◆ EdgeKind_i386

Represets i386 fixups.

Enumerator
None 

None.

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 21 of file i386.h.

Function Documentation

◆ applyFixup()

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

◆ createAnonymousPointer()

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

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

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

◆ createAnonymousPointerJumpStub()

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

References createPointerJumpStubBlock(), and G.

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

◆ createPointerJumpStubBlock()

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

References B, G, Pointer32, and PointerJumpStubContent.

Referenced by createAnonymousPointerJumpStub().

◆ getEdgeKindName()

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

◆ optimizeGOTAndStubAccesses()

Error llvm::jitlink::i386::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 53 of file i386.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::i386::NullPointerContent = {0x00, 0x00, 0x00, 0x00}

i386 null pointer content.

Definition at line 48 of file i386.cpp.

Referenced by createAnonymousPointer().

◆ PointerJumpStubContent

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

i386 pointer jump stub content.

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

Definition at line 50 of file i386.cpp.

Referenced by createPointerJumpStubBlock(), and optimizeGOTAndStubAccesses().

◆ PointerSize

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

i386 pointer size.

Definition at line 261 of file i386.h.

Referenced by createAnonymousPointer().