@@ -581,6 +581,20 @@ The following assembly and relocations show loading an absolute address:
581581 addi a0, a0, %lo(symbol) # R_RISCV_LO12_I (symbol)
582582----
583583
584+ A symbol can be loaded in multiple fragments using different addends, where
585+ multiple instructions associated with `R_RISCV_LO12_I`/`R_RISCV_LO12_S` share a
586+ single `R_RISCV_HI20`. The HI20 values for the multiple fragments must be
587+ identical, a condition met when the symbol is sufficiently aligned.
588+
589+ [,asm]
590+ ----
591+ lui a0, 0 # R_RISCV_HI20 (symbol)
592+ lw a1, 0(a0) # R_RISCV_LO12_I (symbol)
593+ lw a2, 0(a0) # R_RISCV_LO12_I (symbol+4)
594+ lw a3, 0(a0) # R_RISCV_LO12_I (symbol+8)
595+ lw a0, 0(a0) # R_RISCV_LO12_I (symbol+12)
596+ ----
597+
584598==== Global Offset Table
585599
586600For position independent code in dynamically linked objects, each shared
@@ -1533,16 +1547,39 @@ Relaxation result:
15331547 Example::
15341548+
15351549--
1550+ Relaxation candidate (`tX` and `tY` can be any combination of two general purpose registers):
1551+ [,asm]
1552+ ----
1553+ lui tX, 0 # R_RISCV_HI20 (symbol), R_RISCV_RELAX
1554+ lw tY, 0(tX) # R_RISCV_LO12_I (symbol), R_RISCV_RELAX
1555+ ----
1556+ Relaxation result:
1557+ [,asm]
1558+ ----
1559+ lw tY, <gp-offset-for-symbol>(gp)
1560+ ----
1561+
1562+ A symbol can be loaded in multiple fragments using different addends, where
1563+ multiple instructions associated with `R_RISCV_LO12_I`/`R_RISCV_LO12_S` share a
1564+ single `R_RISCV_HI20`. The HI20 values for the multiple fragments must be
1565+ identical and all the relaxed global-pointer offsets must be in range.
1566+
15361567Relaxation candidate:
15371568[,asm]
15381569----
1539- lui t0, 0 # R_RISCV_HI20 (symbol), R_RISCV_RELAX
1540- lw t1, 0(t0) # R_RISCV_LO12_I (symbol), R_RISCV_RELAX
1570+ lui tX, 0 # R_RISCV_HI20 (symbol), R_RISCV_RELAX
1571+ lw tY, 0(tX) # R_RISCV_LO12_I (symbol), R_RISCV_RELAX
1572+ lw tZ, 0(tX+4) # R_RISCV_LO12_I (symbol+4), R_RISCV_RELAX
1573+ lw tW, 0(tX+8) # R_RISCV_LO12_I (symbol+8), R_RISCV_RELAX
1574+ lw tX, 0(tX+12) # R_RISCV_LO12_I (symbol+12), R_RISCV_RELAX
15411575----
15421576Relaxation result:
15431577[,asm]
15441578----
1545- lw t1, <gp-offset-for-symbol>(gp)
1579+ lw tY, <gp-offset-for-symbol>(gp)
1580+ lw tZ, <gp-offset-for-symbol+4>(gp)
1581+ lw tW, <gp-offset-for-symbol+8>(gp)
1582+ lw tX, <gp-offset-for-symbol+12>(gp)
15461583----
15471584--
15481585
0 commit comments