riscv: fix computation of pc-relative relocation offset
PATCH 1/1 riscv: fix computation of pc-relative relocation offset
The offset calculation was missing the relocation addend.
Signed-off-by Andreas Schwab <[email protected]>
--- util/grub-mkimagexx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
util/grub-mkimagexx.c +2 -2
@@ -1232,8 +1232,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,grub_uint32_t *t32 = (grub_uint32_t *) target;grub_uint16_t *t16 = (grub_uint16_t *) target;grub_uint8_t *t8 = (grub_uint8_t *) target; -grub_int64_t off = (long )sym_addr - target_section_addr - offset - - image_target->vaddr_offset; +grub_int64_t off;/* * Instructions and instruction encoding are documented in the RISC-V
@@ -1243,6 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,*/ sym_addr += addend; + off = sym_addr - target_section_addr - offset - image_target->vaddr_offset;switch (ELF_R_TYPE (info)) {
Signature · 6 lines
2.22.0 -- Andreas Schwab, SUSE Labs, [email protected] GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."
Quoted 22 lines · Andreas Schwab
The offset calculation was missing the relocation addend.
Signed-off-by Andreas Schwab <[email protected]>--- util/grub-mkimagexx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/grub-mkimagexx.c +1
-2@@ -1232,8 +1232,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,grub_uint32_t *t32 = (grub_uint32_t *) target;grub_uint16_t *t16 = (grub_uint16_t *) target;grub_uint8_t *t8 = (grub_uint8_t *) target; -grub_int64_t off = (long )sym_addr - target_section_addr - offset - - image_target->vaddr_offset; +grub_int64_t off;/* * Instructions and instruction encoding are documented in the RISC-V
util/grub-mkimagexx.c SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, · line 1248
Quoted 7 lines
util/grub-mkimagexx.c +1
-0@@ -1243,6 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,*/ sym_addr += addend; + off = sym_addr - target_section_addr - offset - image_target->vaddr_offset;switch (ELF_R_TYPE (info)) {
This patch can fix a grub abort issue which randomly shows 'unaligned pointer' warnings on console. I tried this patch on QEMU v4.0.50 + grub-2.0.4-rc1.
Tested-by Chester Lin <[email protected]>
Daniel Kiper
Reviewed-byQuoted 28 lines · Chester Lin
Quoted 27 lines · Andreas Schwab
The offset calculation was missing the relocation addend.
Signed-off-by Andreas Schwab <[email protected]>--- util/grub-mkimagexx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/grub-mkimagexx.c +2
-2@@ -1232,8 +1232,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,grub_uint32_t *t32 = (grub_uint32_t *) target;grub_uint16_t *t16 = (grub_uint16_t *) target;grub_uint8_t *t8 = (grub_uint8_t *) target; -grub_int64_t off = (long )sym_addr - target_section_addr - offset - - image_target->vaddr_offset; +grub_int64_t off;/* * Instructions and instruction encoding are documented in the RISC-V @@ -1243,6 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,*/ sym_addr += addend; + off = sym_addr - target_section_addr - offset - image_target->vaddr_offset;
Quoted 7 lines
util/grub-mkimagexx.c SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, · line 1248
Quoted 2 lines
util/grub-mkimagexx.c +0
-0switch (ELF_R_TYPE (info)) {This patch can fix a grub abort issue which randomly shows 'unaligned pointer' warnings on console. I tried this patch on QEMU v4.0.50 + grub-2.0.4-rc1.
Tested-by Chester Lin <[email protected]>
Reviewed-by Daniel Kiper <[email protected]>
Daniel