Module goblin::elf::reloc[][src]

Expand description

Relocation computations

The following notation is used to describe relocation computations specific to x86_64 ELF.

  • A: The addend used to compute the value of the relocatable field.
  • B: The base address at which a shared object is loaded into memory during execution. Generally, a shared object file is built with a base virtual address of 0. However, the execution address of the shared object is different.
  • G: The offset into the global offset table at which the address of the relocation entry’s symbol resides during execution.
  • GOT: The address of the global offset table.
  • L: The section offset or address of the procedure linkage table entry for a symbol.
  • P: The section offset or address of the storage unit being relocated, computed using r_offset.
  • S: The value of the symbol whose index resides in the relocation entry.
  • Z: The size of the symbol whose index resides in the relocation entry.

Below are some common x86_64 relocation computations you might find useful:

RelocationValueSizeFormula
R_X86_64_NONE0NONENONE
R_X86_64_64164S + A
R_X86_64_PC32232S + A - P
R_X86_64_GOT32332G + A
R_X86_64_PLT32432L + A - P
R_X86_64_COPY5NONENONE
R_X86_64_GLOB_DAT664S
R_X86_64_JUMP_SLOT764S
R_X86_64_RELATIVE864B + A
R_X86_64_GOTPCREL932G + GOT + A - P
R_X86_64_321032S + A
R_X86_64_32S1132S + A
R_X86_64_161216S + A
R_X86_64_PC161316S + A - P
R_X86_64_8148S + A
R_X86_64_PC8158S + A - P
R_X86_64_DTPMOD641664
R_X86_64_DTPOFF641764
R_X86_64_TPOFF641864
R_X86_64_TLSGD1932
R_X86_64_TLSLD2032
R_X86_64_DTPOFF322132
R_X86_64_GOTTPOFF2232
R_X86_64_TPOFF322332
R_X86_64_PC642464S + A - P
R_X86_64_GOTOFF642564S + A - GOT
R_X86_64_GOTPC322632GOT + A - P
R_X86_64_SIZE323232Z + A
R_X86_64_SIZE643364Z + A
R_X86_64_GOTPC32_TLSDESC 3432
R_X86_64_TLSDESC_CALL35NONE
R_X86_64_TLSDESC3664 × 2
R_X86_64_IRELATIVE3764indirect (B + A)

TLS information is at http://people.redhat.com/aoliva/writeups/TLS/RFC-TLSDESC-x86.txt

R_X86_64_IRELATIVE is similar to R_X86_64_RELATIVE except that the value used in this relocation is the program address returned by the function, which takes no arguments, at the address of the result of the corresponding R_X86_64_RELATIVE relocation.

Read more https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html

Modules

Structs

A unified ELF relocation structure

An ELF section containing relocations, allowing lazy iteration over symbols.

Constants

Direct 32 bit

Copy symbol at runtime

Create GOT entry

32 bit GOT entry

Load from 32 bit GOT entry, relaxable

32 bit offset to GOT

32 bit PC relative offset to GOT

Adjust indirectly by program base

Create PLT entry

No reloc

Keep this the last entry

PC relative 32 bit

32 bit PLT address

Adjust by program base

32-bit symbol size

TLS descriptor containing pointer to code and to argument, returning the TLS offset for the symbol

Marker of call through TLS descriptor for relaxation

ID of module containing symbol

Offset in TLS block

Direct 32 bit for GNU version of general dynamic thread local data

Direct 32 bit for general dynamic thread local data

Relocation for call to __tls_get_addr()

Tag for popl in GD TLS code

Tag for pushl in GD TLS code

GOT offset for TLS descriptor.

GOT entry for static TLS block offset

Address of GOT entry for static TLS block offset

GOT entry for negated static TLS block offset

Direct 32 bit for GNU version of local dynamic thread local data in LE code

Direct 32 bit for local dynamic thread local data in LE code

Relocation for call to __tls_get_addr() in LDM code

Tag for popl in LDM TLS code

Tag for pushl in LDM TLS code

Offset relative to TLS block

Offset relative to static TLS block

Negated offset relative to static TLS block

Offset in static TLS block

Negated offset in static TLS block

Direct 16-bit

Direct 32 bit

Direct 64 bit

Dir. ADD imm. from bits 11:0

P-page-rel. GOT off. ADRP 32:12

PC-rel. ADR imm. from bits 20:0

Page-rel. ADRP imm. from 32:12

Likewise; no overflow check

Likewise for CALL

PC-rel. cond. br. imm. from 20:2.

Copy symbol at runtime

Create GOT entry

GOT-relative 32-bit

GOT-relative 64-bit

PC-rel. GOT off. load imm. 20:2

STT_GNU_IFUNC relocation

PC-rel. B imm. from bits 27:2

Create PLT entry

GOT-rel. off. LD/ST imm. 14:3

GOT-page-rel. GOT off. LD/ST 14:3

Dir. GOT off. LD/ST imm. 11:3

Likewise for LD/ST; no check.

Dir. ADD imm. from bits 11:1

Likewise for bits 11:2

Likewise for bits 11:3

Dir. ADD imm. from bits 11:4

PC-rel. LD imm. from bits 20:2

GOT-rel. off. MOV{N,Z} imm. 15:0.

Likewise for MOVK; no check

GOT-rel. o. MOV{N,Z} imm. 31:16

Likewise for MOVK; no check

GOT-rel. o. MOV{N,Z} imm. 47:32

Likewise for MOVK; no check

GOT-rel. o. MOV{N,Z} imm. 63:48

PC-rel. MOV{N,Z} imm. from 15:0

Likewise for MOVK; no check

PC-rel. MOV{N,Z} imm. from 31:16.

Likewise for MOVK; no check

PC-rel. MOV{N,Z} imm. from 47:32.

Likewise for MOVK; no check

PC-rel. MOV{N,Z} imm. from 63:48.

Dir. MOV{N,Z} imm. from 15:0

Dir. MOV{N,Z} imm. from 31:16

Dir. MOV{N,Z} imm. from 47:32

Dir. MOVZ imm. from bits 15:0

Likewise for MOVK; no check

Dir. MOVZ imm. from bits 31:16

Likewise for MOVK; no check

Dir. MOVZ imm. from bits 47:32

Likewise for MOVK; no check

Dir. MOV{K,Z} imm. from 63:48

No relocation

Direct 32 bit

Copy symbol at runtime

Create GOT entry

STT_GNU_IFUNC relocation

Create PLT entry

Adjust by program base

TLS Descriptor

Module number, 32 bit

Module-relative offset, 32 bit

TP-relative offset, 32 bit

PC-relative 16-bit

PC-relative 32-bit

PC-relative 64-bit

Adjust by program base

TLS Descriptor

Relax ADD

Direct ADD imm. from 11:0

Page-rel. ADRP imm. 32:12

PC-rel. ADR immediate 20:0

Relax BLR

Direct LD off. from 11:3

Relax LDR

PC-rel. load immediate 20:2

GOT-rel. MOVK imm. 15:0; no ck

GOT-rel. MOV{N,Z} imm. 31:16

direct ADD imm. from 11:0

page-rel. ADRP imm. 32:12

PC-relative ADR imm. 20:0

GOT-rel. MOVK imm. 15:0

GOT-rel. MOV{N,Z} 31:16

Page-rel. ADRP 32:12

Direct LD off. 11:3

PC-rel. load imm. 20:2

GOT-rel. MOVK 15:0

GOT-rel. MOV{N,Z} 31:16

DTP-rel. ADD imm. from 23:12.

DTP-rel. ADD imm. from 11:0

Likewise; no ovfl. check

Like 514; local dynamic model

Like 513; local dynamic model

Like 512; local dynamic model

DTP-rel. LD/ST imm. 11:0

Likewise; no check

DTP-rel. LD/ST imm. 11:1

Likewise; no check

DTP-rel. LD/ST imm. 11:2

Likewise; no check

DTP-rel. LD/ST imm. 11:3

Likewise; no check

DTP-rel. LD/ST imm. 11:4.

Likewise; no check

TLS PC-rel. load imm. 20:2

TLS DTP-rel. MOV{N,Z} 15:0

Likewise; MOVK; no check

TLS DTP-rel. MOV{N,Z} 31:16

Likewise; MOVK; no check

TLS DTP-rel. MOV{N,Z} 47:32

Like 516; local dynamic model

Like 515; local dynamic model

TP-rel. ADD imm. 23:12

TP-rel. ADD imm. 11:0

Likewise; no ovfl. check

TP-rel. LD/ST off. 11:0

Likewise; no ovfl. check.

TP-rel. LD/ST off. 11:1

Likewise; no check

TP-rel. LD/ST off. 11:2

Likewise; no check

TP-rel. LD/ST off. 11:3

Likewise; no check

TP-rel. LD/ST off. 11:4

Likewise; no check

TLS TP-rel. MOV{N,Z} 15:0

Likewise; MOVK; no check

TLS TP-rel. MOV{N,Z} 31:16

Likewise; MOVK; no check

TLS TP-rel. MOV{N,Z} 47:32

Module number, 64 bit

Module-relative offset, 64 bit

TP-relative offset, 64 bit

PC-rel. TBZ/TBNZ imm. from 15:2

Direct 8 bit

Direct 12 bit

Direct 16 bit

Direct 32 bit

Direct 32-bit

Obsolete

Obsolete

Obsolete

PC relative (ADD, SUB)

PC relative (ADD, SUB)

PC relative (ADD, SUB)

PC relative (ADD, SUB)

PC relative (ADD, SUB)

Deprecated, prog. base relative

Deprecated, prog. base relative

Program base relative (ADD,SUB)

Program base relative (ADD,SUB)

Program base relative (ADD,SUB)

Program base relative (ADD,SUB)

Program base relative (ADD,SUB)

Adjust by program base

PC relative 24 bit (BL, BLX)

Copy symbol at runtime

Create GOT entry

32 bit GOT entry

32 bit offset to GOT

12 bit, GOT entry relative to GOT origin (LDR, STR)

32 bit PC relative offset to GOT

GOT entry

GOT entry relative to GOT origin (LDR)

PC relative GOT entry

PC relative 24 bit (B, BL)

Create PLT entry

PC relative (LDC, STC)

PC relative (LDC, STC)

PC relative (LDC, STC)

Program base relative (LDC,STC)

Program base relative (LDC,STC)

Program base relative (LDC,STC)

PC relative (STR{D,H},LDR{D,SB,H,SH})

PC relative (STR{D,H},LDR{D,SB,H,SH})

PC relative (STR{D,H},LDR{D,SB,H,SH})

Program base relative (LDR, STR, LDRB, STRB)

Program base relative (LDR, STR, LDRB, STRB)

Program base relative (LDR, STR, LDRB, STRB)

PC relative (LDR,STR,LDRB,STRB)

PC relative (LDR,STR,LDRB,STRB)

Deprecated, prog. base relative

Program base relative (LDR,STR, LDRB, STRB)

Program base relative (LDR, STR, LDRB, STRB)

Program base relative (LDR, STR, LDRB, STRB)

Obsolete

Direct high 16-bit (MOVT)

Program base relative high 16 bit (MOVT)

PC relative (MOVT)

Direct 16-bit (MOVW)

Program base relative 16 bit (MOVW)

Program base relative 16 bit (MOVW)

PC relative 16-bit (MOVW)

No reloc

Keep this the last entry

Deprecated PC relative 26 bit branch

Deprecated, 32 bit PLT address

32 bit PC relative

PC relative 32 bit

PC relative 32-bit

Adjust by program base

Program base relative

Obsolete static relocation

Direct & 0x7C (LDR, STR)

PC relative 12 bit (Thumb32 ADR.W)

GOT entry relative to GOT origin, 12 bit (Thumb32 LDR)

PC relative X & 0x7E (Thumb16 CBZ, CBNZ)

PC relative 20 bit (Thumb32 B.W)

PC relative 24 bit (Thumb32 B.W)

Direct high 16 bit (Thumb32 MOVT)

Program base relative high 16 bit (Thumb32 MOVT)

PC relative high 16 bit (Thumb32 MOVT)

Direct 16 bit (Thumb32 MOVW)

Program base relative 16 bit (Thumb32 MOVW)

Program base relative 16 bit (Thumb32 MOVW)

PC relative 16 bit (Thumb32 MOVW)

PC relative & 0x3FC(Thumb16 LDR, ADD, ADR).

PC relative & 0x1FE (Thumb16 B/B)

PC relative & 0xFFE (Thumb16 B)

PC relative 12 bit (Thumb32 LDR{D,SB,H,SH})

PC relative 24 bit (Thumb32 BL)

Reserved

Reserved

Dynamic relocation

TLS relaxation

ID of module containing symbol

Offset in TLS block

PC-rel 32 bit for global dynamic thread local data

12 bit GOT entry relative to GOT origin (LDR)

PC-rel 32 bit for GOT entry of static TLS block offset

PC-rel 32 bit for local dynamic thread local data

12 bit relative to TLS block (LDR, STR)

32 bit offset relative to TLS block

12 bit relative to static TLS block (LDR, STR)

32 bit offset relative to static TLS block

Offset in static TLS block

Reserved

Direct 16 bit

Direct 26 bit shifted

Direct 32 bit

16 bit GOT entry for function

16 bit GOT entry

GP relative 16 bit

GP relative 32 bit

High 16 bit

16 bit literal entry

Low 16 bit

No reloc

PC relative 16 bit

PC relative 32 bit

Module number 32 bit

Module number 64 bit

Module-relative offset 32 bit

Module-relative offset 64 bit

Module-relative offset, high 16 bits

Module-relative offset, low 16 bits

16 bit GOT offset for GD

16 bit GOT offset for IE

16 bit GOT offset for LDM

TP-relative offset, 32 bit6

TP-relative offset, 64 bit

TP-relative offset, high 16 bits

TP-relative offset, low 16 bits

Runtime relocation: word32 = S + A

Runtime relocation: word64 = S + A

8-bit label addition: word8 = S + A

16-bit label addition: word16 = S + A

32-bit label addition: word32 = S + A

64-bit label addition: word64 = S + A

Alignment statement

PC-relative branch (SB-Type)

PC-relative call: MACRO call,tail (auipc+jalr pair)

PC-relative call (PLT): MACRO call,tail (auipc+jalr pair) PIC

Runtime relocation: must be in executable, not allowed in shared library

GNU C++ vtable member usage

GNU C++ vtable hierarchy

PC-relative GOT reference: MACRO la

GP-relative reference (I-Type)

GP-relative reference (S-Type)

Absolute address: %hi(symbol) (U-Type)

PC-relative jump (UJ-Type)

Runtime relocation: word32,64 = S; handled by PLT unless LD_BIND_NOW

Absolute address: %lo(symbol) (I-Type)

Absolute address: %lo(symbol) (S-Type)

None

PC-relative reference: %pcrel_hi(symbol) (U-Type)

PC-relative reference: %pcrel_lo(symbol) (I-Type)

PC-relative reference: %pcrel_lo(symbol) (S-Type)

Runtime relocation: word32,64 = B + A

Instruction pair can be relaxed

PC-relative branch offset (CB-Type)

PC-relative jump offset (CJ-Type)

Absolute address (CI-Type)

Local label subtraction

Local label subtraction

Local label subtraction

Local label subtraction

Local label subtraction

8-bit label subtraction: word8 = S - A

16-bit label subtraction: word16 = S - A

32-bit label subtraction: word32 = S - A

64-bit label subtraction: word64 = S - A

TLS relocation: word32 = S->TLSINDEX

TLS relocation: word64 = S->TLSINDEX

TLS relocation: word32 = TLS + S + A - TLS_TP_OFFSET

TLS relocation: word64 = TLS + S + A - TLS_TP_OFFSET

PC-relative TLS GD reference: MACRO la.tls.gd

PC-relative TLS IE GOT offset: MACRO la.tls.ie

TLS relocation: word32 = TLS + S + A + S_TLS_OFFSET - TLS_DTV_OFFSET

TLS relocation: word64 = TLS + S + A + S_TLS_OFFSET - TLS_DTV_OFFSET

TLS LE thread usage: %tprel_add(symbol)

TLS LE thread offset: %tprel_hi(symbol) (U-Type)

TP-relative TLS LE load (I-Type)

TLS LE thread offset: %tprel_lo(symbol) (I-Type)

TLS LE thread offset: %tprel_lo(symbol) (S-Type)

TP-relative TLS LE store (S-Type)

Direct 8 bit sign extended.

Direct 16 bit zero extended.

Direct 32 bit zero extended.

Direct 32 bit sign extended.

Direct 64 bit.

Copy symbol at runtime.

ID of module containing symbol.

Offset in TLS block.

Offset in module’s TLS block.

Create GOT entry.

32 bit GOT entry.

64-bit GOT entry offset.

64 bit offset to GOT.

32 bit signed pc relative offset to GOT.

GOT offset for TLS descriptor..

64-bit PC relative offset to GOT.

32 bit signed PC relative offset to GOT.

64-bit PC relative offset to GOT entry.

Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable.

like GOT64, says PLT entry needed.

32 bit signed PC relative offset to GOT entry for IE symbol.

Adjust indirectly by program base.

Create PLT entry.

No reloc.

8 bit sign extended pc relative.

16 bit sign extended pc relative.

PC relative 32 bit signed.

PC relative 64 bit.

32 bit PLT address.

64-bit GOT relative offset to PLT entry.

Adjust by program base.

64-bit adjust by program base.

Load from 32 bit signed pc relative offset to GOT entry with REX prefix, relaxable.

Size of symbol plus 32-bit addend.

Size of symbol plus 64-bit addend.

TLS descriptor..

Marker for call through TLS descriptor..

32 bit signed PC relative offset to two GOT entries for GD symbol.

32 bit signed PC relative offset to two GOT entries for LD symbol.

Offset in initial TLS block.

Offset in initial TLS block.

Functions