hv: risc-v: add relocation support

This patch implements relocation support for ACRN RISC-V to enable
position-independent execution. The hypervisor can now be loaded at any
physical address and will automatically relocate itself at runtime. Key
changes:
- Add relocate() function to process R_RISCV_RELATIVE relocations in
  .rela sections during early boot
- Implement arch_get_hv_image_delta() to calculate the load address offset
  from the configured base address
- Add relocation processing in cpu_entry.S before jumping to C code
- Update linker script to include .rela sections for relocation data
- Define R_RISCV_RELATIVE relocation type and linker symbol definitions

Tracked-On: #8825
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Jian Jun Chen
2025-09-30 08:55:04 +08:00
committed by acrnsi-robot
parent f904dbffbb
commit 1dee977429
6 changed files with 121 additions and 2 deletions

View File

@@ -188,4 +188,7 @@ static inline uint64_t elf64_r_type(uint64_t i)
/* x86-64 relocation types */
#define R_X86_64_RELATIVE 8U
/* RISC-V relocation types */
#define R_RISCV_RELATIVE 3U
#endif /* !ELF_H */