Skip to contentSkip to conversation

util/grub-image: fix riscv32 relocation offset

PATCH In review Anaëlle Cazuc 2 participants 2 messages Sep 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/grub-image: fix riscv32 relocation offset

When using grub-mkrescue for a riscv32 target, an invalid implicit cast on the offset calculation produces an error during the relocation
process: grub-mkrescue: error: target XXX not reachable from pc=fc.

This patch adds an explicit int64_t cast to compute the offset as a 64bit subtraction.

---
 util/grub-mkimagexx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/grub-mkimagexx.c +1 -1
index 448862b2e..5fb7e695c 100644
@@ -1354,7 +1354,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;
+		 off = (grub_int64_t)sym_addr - target_section_addr - offset - image_target->vaddr_offset;
 
 		 switch (ELF_R_TYPE (info))
 		   {
Signature · 7 lines
2.39.5


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Anaëlle Cazuc

When using grub-mkrescue for a riscv32 target, an invalid implicit cast on the offset calculation produces an error during the relocation
process: grub-mkrescue: error: target XXX not reachable from pc=fc.

This patch adds an explicit int64_t cast to compute the offset as a 64bit subtraction.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel