Skip to content

Commit 35bd320

Browse files
author
Jim Wilson
authored
Merge pull request #148 from ebahapo/patch-2
Augment the relocations table
2 parents 18155da + c50f48e commit 35bd320

File tree

1 file changed

+91
-69
lines changed

1 file changed

+91
-69
lines changed

riscv-elf.md

Lines changed: 91 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -469,65 +469,65 @@ Global Offset Table or DWARF meta data.
469469
The following table provides details of the RISC-V ELF relocations (instruction
470470
specific relocations show the instruction type in the Details column):
471471

472-
Enum | ELF Reloc Type | Description | Details
473-
:--- | :------------------ | :--------------- | :-----------
474-
0 | R_RISCV_NONE | None |
475-
1 | R_RISCV_32 | Runtime relocation | word32 = S + A
476-
2 | R_RISCV_64 | Runtime relocation | word64 = S + A
477-
3 | R_RISCV_RELATIVE | Runtime relocation | word32,64 = B + A
478-
4 | R_RISCV_COPY | Runtime relocation | must be in executable. not allowed in shared library
479-
5 | R_RISCV_JUMP_SLOT | Runtime relocation | word32,64 = S ;handled by PLT unless LD_BIND_NOW
480-
6 | R_RISCV_TLS_DTPMOD32 | TLS relocation | word32 = S->TLSINDEX
481-
7 | R_RISCV_TLS_DTPMOD64 | TLS relocation | word64 = S->TLSINDEX
482-
8 | R_RISCV_TLS_DTPREL32 | TLS relocation | word32 = TLS + S + A - TLS_TP_OFFSET
483-
9 | R_RISCV_TLS_DTPREL64 | TLS relocation | word64 = TLS + S + A - TLS_TP_OFFSET
484-
10 | R_RISCV_TLS_TPREL32 | TLS relocation | word32 = TLS + S + A + S_TLS_OFFSET - TLS_DTV_OFFSET
485-
11 | R_RISCV_TLS_TPREL64 | TLS relocation | word64 = TLS + S + A + S_TLS_OFFSET - TLS_DTV_OFFSET
486-
16 | R_RISCV_BRANCH | PC-relative branch | (SB-Type)
487-
17 | R_RISCV_JAL | PC-relative jump | (UJ-Type)
488-
18 | R_RISCV_CALL | PC-relative call | MACRO call,tail (auipc+jalr pair)
489-
19 | R_RISCV_CALL_PLT | PC-relative call (PLT) | MACRO call,tail (auipc+jalr pair) PIC
490-
20 | R_RISCV_GOT_HI20 | PC-relative GOT reference | %got_pcrel_hi(symbol) (U-Type)
491-
21 | R_RISCV_TLS_GOT_HI20 | PC-relative TLS IE GOT offset | MACRO la.tls.ie
492-
22 | R_RISCV_TLS_GD_HI20 | PC-relative TLS GD reference | MACRO la.tls.gd
493-
23 | R_RISCV_PCREL_HI20 | PC-relative reference | %pcrel_hi(symbol) (U-Type)
494-
24 | R_RISCV_PCREL_LO12_I | PC-relative reference | %pcrel_lo(pcrel_hi20_address) (I-Type)
495-
25 | R_RISCV_PCREL_LO12_S | PC-relative reference | %pcrel_lo(pcrel_hi20_address) (S-Type)
496-
26 | R_RISCV_HI20 | Absolute address | %hi(symbol) (U-Type)
497-
27 | R_RISCV_LO12_I | Absolute address | %lo(symbol) (I-Type)
498-
28 | R_RISCV_LO12_S | Absolute address | %lo(symbol) (S-Type)
499-
29 | R_RISCV_TPREL_HI20 | TLS LE thread offset | %tprel_hi(symbol) (U-Type)
500-
30 | R_RISCV_TPREL_LO12_I | TLS LE thread offset | %tprel_lo(symbol) (I-Type)
501-
31 | R_RISCV_TPREL_LO12_S | TLS LE thread offset | %tprel_lo(symbol) (S-Type)
502-
32 | R_RISCV_TPREL_ADD | TLS LE thread usage | %tprel_add(symbol)
503-
33 | R_RISCV_ADD8 | 8-bit label addition | word8 = old + S + A
504-
34 | R_RISCV_ADD16 | 16-bit label addition | word16 = old + S + A
505-
35 | R_RISCV_ADD32 | 32-bit label addition | word32 = old + S + A
506-
36 | R_RISCV_ADD64 | 64-bit label addition | word64 = old + S + A
507-
37 | R_RISCV_SUB8 | 8-bit label subtraction | word8 = old - S - A
508-
38 | R_RISCV_SUB16 | 16-bit label subtraction | word16 = old - S - A
509-
39 | R_RISCV_SUB32 | 32-bit label subtraction | word32 = old - S - A
510-
40 | R_RISCV_SUB64 | 64-bit label subtraction | word64 = old - S - A
511-
41 | R_RISCV_GNU_VTINHERIT| GNU C++ vtable hierarchy |
512-
42 | R_RISCV_GNU_VTENTRY | GNU C++ vtable member usage |
513-
43 | R_RISCV_ALIGN | Alignment statement |
514-
44 | R_RISCV_RVC_BRANCH | PC-relative branch offset | (CB-Type)
515-
45 | R_RISCV_RVC_JUMP | PC-relative jump offset | (CJ-Type)
516-
46 | R_RISCV_RVC_LUI | Absolute address | (CI-Type)
517-
47 | R_RISCV_GPREL_I | GP-relative reference | (I-Type)
518-
48 | R_RISCV_GPREL_S | GP-relative reference | (S-Type)
519-
49 | R_RISCV_TPREL_I | TP-relative TLS LE load | (I-Type)
520-
50 | R_RISCV_TPREL_S | TP-relative TLS LE store | (S-Type)
521-
51 | R_RISCV_RELAX | Instruction pair can be relaxed |
522-
52 | R_RISCV_SUB6 | Local label subtraction |
523-
53 | R_RISCV_SET6 | Local label subtraction |
524-
54 | R_RISCV_SET8 | Local label subtraction |
525-
55 | R_RISCV_SET16 | Local label subtraction |
526-
56 | R_RISCV_SET32 | Local label subtraction |
527-
57 | R_RISCV_32_PCREL | PC-relative reference | word32 = S + A - PC
528-
58 | R_RISCV_IRELATIVE | Runtime relocation | word32,64 = ifunc_resolver(B + A)
529-
59-191 | *Reserved* | Reserved for future standard use |
530-
192-255 | *Reserved* | Reserved for nonstandard ABI extensions |
472+
Enum | ELF Reloc Type | Description | Field | Calculation | Details
473+
:--- | :------------------ | :--------------- | :---- | :---------- | :-------
474+
0 | R_RISCV_NONE | None |
475+
1 | R_RISCV_32 | Runtime relocation | _word32_ | S + A
476+
2 | R_RISCV_64 | Runtime relocation | _word64_ | S + A
477+
3 | R_RISCV_RELATIVE | Runtime relocation | _wordclass_ | B + A
478+
4 | R_RISCV_COPY | Runtime relocation | | | Must be in executable. not allowed in shared library
479+
5 | R_RISCV_JUMP_SLOT | Runtime relocation | _wordclass_ | S | Handled by PLT unless `LD_BIND_NOW`
480+
6 | R_RISCV_TLS_DTPMOD32 | TLS relocation | _word32_ | S->TLSINDEX
481+
7 | R_RISCV_TLS_DTPMOD64 | TLS relocation | _word64_ | S->TLSINDEX
482+
8 | R_RISCV_TLS_DTPREL32 | TLS relocation | _word32_ | S + A + TLS - TLS_TP_OFFSET
483+
9 | R_RISCV_TLS_DTPREL64 | TLS relocation | _word64_ | S + A + TLS - TLS_TP_OFFSET
484+
10 | R_RISCV_TLS_TPREL32 | TLS relocation | _word32_ | S + A + TLS + S_TLS_OFFSET - TLS_DTV_OFFSET
485+
11 | R_RISCV_TLS_TPREL64 | TLS relocation | _word64_ | S + A + TLS + S_TLS_OFFSET - TLS_DTV_OFFSET
486+
16 | R_RISCV_BRANCH | PC-relative branch | _B-Type_ | S + A - P
487+
17 | R_RISCV_JAL | PC-relative jump | _J-Type_ | S + A - P
488+
18 | R_RISCV_CALL | PC-relative call | _J-Type_ | S + A - P | Macros `call`, `tail`
489+
19 | R_RISCV_CALL_PLT | PC-relative call (PLT) | _J-Type_ | S + A - P | Macros `call`, `tail` (PIC)
490+
20 | R_RISCV_GOT_HI20 | PC-relative GOT reference | _U-Type_ | G + A | `%got_pcrel_hi(symbol)`
491+
21 | R_RISCV_TLS_GOT_HI20 | PC-relative TLS IE GOT offset | _U-Type_ | | Macro `la.tls.ie`
492+
22 | R_RISCV_TLS_GD_HI20 | PC-relative TLS GD reference | _U-Type_ | | Macro `la.tls.gd`
493+
23 | R_RISCV_PCREL_HI20 | PC-relative reference | _U-Type_ | S + A - P | `%pcrel_hi(symbol)`
494+
24 | R_RISCV_PCREL_LO12_I | PC-relative reference | _I-type_ | S + A - P | `%pcrel_lo(address of %pcrel_hi)`
495+
25 | R_RISCV_PCREL_LO12_S | PC-relative reference | _S-Type_ | S + A - P | `%pcrel_lo(address of %pcrel_hi)`
496+
26 | R_RISCV_HI20 | Absolute address | _U-Type_ | S + A | `%hi(symbol)`
497+
27 | R_RISCV_LO12_I | Absolute address | _I-Type_ | S + A | `%lo(symbol)`
498+
28 | R_RISCV_LO12_S | Absolute address | _S-Type_ | S + A | `%lo(symbol)`
499+
29 | R_RISCV_TPREL_HI20 | TLS LE thread offset | _U-Type_ | | `%tprel_hi(symbol)`
500+
30 | R_RISCV_TPREL_LO12_I | TLS LE thread offset | _I-Type_ | | `%tprel_lo(symbol)`
501+
31 | R_RISCV_TPREL_LO12_S | TLS LE thread offset | _S-Type_ | | `%tprel_lo(symbol)`
502+
32 | R_RISCV_TPREL_ADD | TLS LE thread usage | | | `%tprel_add(symbol)`
503+
33 | R_RISCV_ADD8 | 8-bit label addition | _word8_ | S + A + V
504+
34 | R_RISCV_ADD16 | 16-bit label addition | _word16_ | S + A + V
505+
35 | R_RISCV_ADD32 | 32-bit label addition | _word32_ | S + A + V
506+
36 | R_RISCV_ADD64 | 64-bit label addition | _word64_ | S + A + V
507+
37 | R_RISCV_SUB8 | 8-bit label subtraction | _word8_ | V - S - A
508+
38 | R_RISCV_SUB16 | 16-bit label subtraction | _word16_ | V - S - A
509+
39 | R_RISCV_SUB32 | 32-bit label subtraction | _word32_ | V - S - A
510+
40 | R_RISCV_SUB64 | 64-bit label subtraction | _word64_ | V - S - A
511+
41 | R_RISCV_GNU_VTINHERIT | GNU C++ vtable hierarchy |
512+
42 | R_RISCV_GNU_VTENTRY | GNU C++ vtable member usage |
513+
43 | R_RISCV_ALIGN | Alignment statement |
514+
44 | R_RISCV_RVC_BRANCH | PC-relative branch offset | _CB-Type_ | S + A - P
515+
45 | R_RISCV_RVC_JUMP | PC-relative jump offset | _CJ-Type_ | S + A - P
516+
46 | R_RISCV_RVC_LUI | Absolute address | _CI-Type_ | S + A - P
517+
47 | R_RISCV_GPREL_I | GP-relative reference | _I-Type_ | S + A - GP
518+
48 | R_RISCV_GPREL_S | GP-relative reference | _S-Type_ | S + A - GP
519+
49 | R_RISCV_TPREL_I | TP-relative TLS LE load | _I-Type_
520+
50 | R_RISCV_TPREL_S | TP-relative TLS LE store | _S-Type_
521+
51 | R_RISCV_RELAX | Instruction pair can be relaxed |
522+
52 | R_RISCV_SUB6 | Local label subtraction |
523+
53 | R_RISCV_SET6 | Local label subtraction |
524+
54 | R_RISCV_SET8 | Local label subtraction |
525+
55 | R_RISCV_SET16 | Local label subtraction |
526+
56 | R_RISCV_SET32 | Local label subtraction |
527+
57 | R_RISCV_32_PCREL | PC-relative reference | _word32_ | S + A - P
528+
58 | R_RISCV_IRELATIVE | Runtime relocation | _wordclass_ | `ifunc_resolver(B + A)`
529+
59-191 | *Reserved* | Reserved for future standard use |
530+
192-255 | *Reserved* | Reserved for nonstandard ABI extensions |
531531

532532
Nonstandard extensions are free to use relocation numbers 192-255 for any
533533
purpose. These relocations may conflict with other nonstandard extensions.
@@ -536,21 +536,44 @@ This section and later ones contain fragments written in assembler. The precise
536536
assembler syntax, including that of the relocations, is described in the
537537
[RISC-V Assembly Programmer's Manual](https://github.com/riscv/riscv-asm-manual).
538538

539-
### Address Calculation Symbols
539+
### Calculation Symbols
540540

541-
The following table provides details on the variables used in address calculation:
541+
The following table provides details on the variables used in relocation
542+
calculation:
542543

543-
Variable | Description
544-
:------------- | :----------------
545-
A | Addend field in the relocation entry associated with the symbol
546-
B | Base address of a shared object loaded into memory
547-
G | Offset of the symbol into the GOT (Global Offset Table)
548-
S | Value of the symbol in the symbol table
549-
GP | Value of `__global_pointer$` symbol.
544+
Variable | Description
545+
:------- | :----------------
546+
A | Addend field in the relocation entry associated with the symbol
547+
B | Base address of a shared object loaded into memory
548+
G | Offset of the symbol into the GOT (Global Offset Table)
549+
P | Position of the relocation
550+
S | Value of the symbol in the symbol table
551+
V | Value at the position of the relocation
552+
GP | Value of `__global_pointer$` symbol
550553

551554
**Global Pointer**: It is assumed that program startup code will load the value
552555
of the `__global_pointer$` symbol into register `gp` (aka `x3`).
553556

557+
### Field Symbols
558+
559+
The following table provides details on the variables used in relocation fields:
560+
561+
Variable | Description
562+
:------- | :----------
563+
_word8_ | Specifies an 8-bit field
564+
_word16_ | Specifies a 16-bit field
565+
_word32_ | Specifies a 32-bit field
566+
_word64_ | Specifies a 64-bit field
567+
_wordclass_ | Specifies a _word32_ field for ILP32 or a _word64_ field for LP64
568+
_B-Type_ | Specifies a field as the immediate field in a B-type instruction
569+
_CB-Type_ | Specifies a field as the immediate field in a CB-type instruction
570+
_CI-Type_ | Specifies a field as the immediate field in a CI-type instruction
571+
_CJ-Type_ | Specifies a field as the immediate field in a CJ-type instruction
572+
_I-Type_ | Specifies a field as the immediate field in an I-type instruction
573+
_S-Type_ | Specifies a field as the immediate field in an S-type instruction
574+
_U-Type_ | Specifies a field as the immediate field in an U-type instruction
575+
_J-Type_ | Specifies a field as the immediate field in a J-type instruction
576+
554577
### Absolute Addresses
555578

556579
32-bit absolute addresses in position dependent code are loaded with a pair
@@ -951,4 +974,3 @@ there is no differentiation between ILP32 and LP64 abis.
951974
Here a combination of the **gABI** and the **psABI**
952975
* **gABI**: generic ABI
953976
* **psABI**: processor specific ABI
954-

0 commit comments

Comments
 (0)