Skip to content

Commit 2671e51

Browse files
authored
Fix lo12 calculation of PC-Relative Symbol (#142)
Just like `Absolute Addresses` example, it should shift hi20 back to calculate lo12.
1 parent cec39a0 commit 2671e51

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

riscv-elf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ immediate on the add, load or store instruction the linker finds the
717717
instruction. The addresses for pair of relocations are calculated like this:
718718

719719
- `hi20 = ((symbol_address - hi20_reloc_offset + 0x800) >> 12);`
720-
- `lo12 = symbol_address - hi20_reloc_offset - hi20;`
720+
- `lo12 = symbol_address - hi20_reloc_offset - (hi20 << 12);`
721721

722722
The successive instruction has a signed 12-bit immediate so the value of the
723723
preceding high 20-bit relocation may have 1 added to it.

0 commit comments

Comments
 (0)