Add new relocation type for global array accesses with non-constant indices.#489
Add new relocation type for global array accesses with non-constant indices.#489LiqinWeng wants to merge 2 commits intoriscv-non-isa:masterfrom
Conversation
…ndices. Relocation Type: R_RISCV_REGREL_ADD/R_RISCV_REGREL_SHXADD/R_RISCV_REGREL_LO12_I/R_RISCV_REGREL_LO12_S The RISC-V architecture addresses non-constant subscript elements using lui + addi + add + ld/st. The low-address calculation process of addi instruction is offloaded th the ld/st, thereby eliminating low-address calculation and reducing addressing instructions. The scenario is as follows: same as sh1add/sh2add/sh3add ``` lui vr1, %hi(sym) addi vr1, vr1, %lo(sym) add vr2, vrx, vr1 lbu vr3, off(vr2) ``` After Compiler Transformation ``` lui vr1, %hi(sym+off) add vr2, vrx, vr1, %regrel_add(sym+off) lbu vr3, %regrel_lo(sym+off)(vr2) ``` After Linker Relaxation: ``` add vr2, vrx, gp lbu vr3, <gp-relative-offset>(vr2) ``` Need update the ld/st's offset and add/sh1add/sh2add/sh3add's src2 be replace by gp, so need add new relocation deal with this scenario.
|
cc @lenary |
lenary
left a comment
There was a problem hiding this comment.
Initial comments, to facilitate reviews.
These seem reasonable improvements to me, if we're continuing down the route of adding more relaxations and are willing to do marker relocations.
I think it is reasonable that the REGREL_* relocations take the global symbol they relate to, but this does prevent them being implicitly relax (as we want to use the symbol in R_RISCV_RELAX for an arch string), which will cause a blow-up in the static relocation tables. That's the price of more linker relaxations, I feel.
riscv-elf.adoc
Outdated
| .2+| 67 .2+| REGREL_LO12_I .2+| Static | _I-Type_ .2+| Low 12 bits of 32-bit Global Array Offset, `%regrel_lo(symbol)` | ||
| <| | ||
| .2+| 68 .2+| REGREL_LO12_S .2+| Static | _S-Type_ .2+| Low 12 bits of 32-bit Global Array Offset, `%regrel_lo(symbol)` | ||
| <| | ||
| .2+| 69 .2+| REGREL_ADD .2+| Static | .2+| Global Array usage, `%regrel_add(symbol)` | ||
| <| | ||
| .2+| 70 .2+| REGREL_SHXADD .2+| Static | .2+| Global Array usage, `%regrel_shxadd(symbol)` | ||
| <| | ||
| .2+| 71-76 .2+| *Reserved* .2+| - | .2+| Reserved for Y base ISA |
There was a problem hiding this comment.
67-76 are reserved for a specific use - these relocations do not relate to Y base ISA. Please use values from 77 onwards.
riscv-elf.adoc
Outdated
| [,asm] | ||
| ---- | ||
| add tY, tY, gp | ||
| lw t1, <address-of-symbol>(tY) |
There was a problem hiding this comment.
| lw t1, <address-of-symbol>(tY) | |
| lw t1, <gp-offset-for-symbol>(tY) |
There was a problem hiding this comment.
Could you take a look : llvm/llvm-project#185586 (comment) like to know if adding the handling logic for the inst scenarios below introduces any potential , as: add.uw/sh1add.uw/sh2add.uw/sh3add.uw
| Target Relocation:: R_RISCV_HI20, R_RISCV_REGREL_LO12_I, R_RISCV_REGREL_LO12_S, | ||
| R_RISCV_REGREL_ADD, R_RISCV_REGREL_SHXADD |
There was a problem hiding this comment.
Please split off the R_RISCV_REGREL_SHXADD relaxation into a separate description, or add a shxadd example below (either way, an example is needed, as that relaxation is more complex).
|
Hi @LiqinWeng, thanks for this proposal! There is few review comment: I think Also, I suggest adding a set of |
|
REGREL is a bit of a strange name. I imagine you've done it because of TPREL, but that's a bit different. With TPREL for TLS, TP is a pointer, and you materialise the offset of the TLS symbol within the static TLS block in a register that you add to TP (and since that's an offset not an address, you're always using lui+addi, never auipc+addi). With your proposed REGREL, the GPR in question isn't a pointer, it's some additional offset, and it's the lui+addi that's the pointer (and hence why auipc+addi would be needed for medany/PIE/PIC). This naming therefore seems backwards. |
One question for the case of |
I'm inclined to require that |
Yeah, I agree the naming is a bit confusing. I didn't have a good idea when I first replied, but after thinking more, how about I considered |
Relocation Type Includes: R_RISCV_REGREL_ADD/R_RISCV_REGREL_SHXADD/R_RISCV_REGREL_LO12_I/R_RISCV_REGREL_LO12_S
The RISC-V architecture addresses non-constant subscript elements using lui + addi + add + ld/st. The low-address calculation process of addi instruction is offloaded th the ld/st, thereby eliminating low-address calculation and reducing addressing instructions.
The scenario is as follows: same as sh1add/sh2add/sh3add
After Compiler Transformation
After Linker Relaxation:
Need update the ld/st's offset and add/sh1add/sh2add/sh3add's src2 be replace by gp, so need add new relocation deal with this scenario.