From 8f1ad936ff86fcc54d68a791186f067d00a71853 Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Mon, 30 Jan 2023 17:11:08 +0800 Subject: [PATCH] Define relocations for ULEB128 value: R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128 ULEB128 has used in DWARF and exception handling table, it used to record value, or record the distance between two symbols. The later one would be an issue for debug info and exception handling table, since the symbol address might updated during, then the value might incorrect after relaxation, some of those field has alternative encoding type, but some new field defined in DWARF 5 ins't provide alternative format other than ULEB128, e.g. DW_RLE_offset_pair, DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length. This PR basically same as #162, but updated to the trunk, and also document ULEB128 should not shrink the size of the data, since we never know the data used in where and does the length has recorded in somewhere or not, so this would be most safe way. binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html --- riscv-elf.adoc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/riscv-elf.adoc b/riscv-elf.adoc index 95ae9fde..42364623 100644 --- a/riscv-elf.adoc +++ b/riscv-elf.adoc @@ -447,7 +447,11 @@ Description:: Additional information about the relocation <| `ifunc_resolver(B + A)` .2+| 59 .2+| PLT32 .2+| Static | _word32_ .2+| 32-bit relative offset to a function or its PLT entry <| S + A - P -.2+| 60-191 .2+| *Reserved* .2+| - | .2+| Reserved for future standard use +.2+| 60 .2+| SET_ULEB128 .2+| Static | _ULEB128_ .2+| Local label assignment <> + <| S + A +.2+| 61 .2+| SUB_ULEB128 .2+| Static | _ULEB128_ .2+| Local label subtraction <> + <| V - S + A +.2+| 62-191 .2+| *Reserved* .2+| - | .2+| Reserved for future standard use <| .2+| 192-255 .2+| *Reserved* .2+| - | .2+| Reserved for nonstandard ABI extensions <| @@ -460,6 +464,12 @@ This section and later ones contain fragments written in assembler. The precise assembler syntax, including that of the relocations, is described in the _RISC-V Assembly Programmer's Manual_ <>. +[[uleb128-note]] +NOTE: Assembler must preserve enough space for ULEB128 data with +R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128 relocation for the linker; +it can either fill zero and padding to XLEN-bits or fill the precomputed +result of those relocations into the position of the relocation. + ==== Calculation Symbols <> provides details on the variables used in relocation @@ -501,6 +511,7 @@ of the `__global_pointer$` symbol into register `gp` (aka `x3`). | _word16_ | Specifies a 16-bit word | _word32_ | Specifies a 32-bit word | _word64_ | Specifies a 64-bit word +| _ULEB128_ | Specifies a variable-length data encoded in ULEB128 format. | _wordclass_ | Specifies a _word32_ field for ILP32 or a _word64_ field for LP64 | _B-Type_ | Specifies a field as the immediate field in a B-type instruction | _CB-Type_ | Specifies a field as the immediate field in a CB-type instruction @@ -1221,6 +1232,14 @@ are commonly resolved at compile-time, such as intra-function jumps), code generators must in general ensure that relocations are always emitted when relaxation is enabled. +Linkers should adjust relocations that refer to symbols whose addresses have +been updated. + +ULEB128 value with relocation must be padding to the same length even if the +data can be encoded with a shorter byte sequence after linker relaxation, The +linker should report errors if the length of ULEB128 byte sequence is more +extended than the current byte sequence. + === Linker Relaxation Types The purpose of this section is to describe all types of linker relaxation,