reloc_riscv32.c (1217B)
1 /* RelocKind <-> RISC-V ELF reloc-type mapping (ELFCLASS32 / RV32 ILP32*). 2 * 3 * The RISC-V reloc type codes are XLEN-neutral and fit the 8-bit ELF32 r_info 4 * type field, so every code-/data-relative kind is shared verbatim with the 5 * rv64 maps in reloc_riscv64.c — these wrappers just delegate. The only 6 * divergence is the 64-bit-wide kinds (R_ABS64 / R_ADD64 / R_SUB64 <-> 7 * ELF_R_RISCV_64 / ADD64 / SUB64): not valid in an ELFCLASS32 object, so the 8 * write side maps them to ELF_R_RISCV_NONE (emit_elf flags them) and the read 9 * side to the (u32)-1 sentinel (the reader diagnoses them rather than 10 * fabricating a 64-bit RelocKind for a 32-bit object). */ 11 12 #include "obj/elf/elf.h" 13 14 u32 elf_riscv32_reloc_to(u32 kind /* RelocKind */) { 15 /* 64-bit-only kinds are unrepresentable on RV32. */ 16 if (kind == R_ABS64 || kind == R_ADD64 || kind == R_SUB64) 17 return ELF_R_RISCV_NONE; 18 return elf_riscv64_reloc_to(kind); 19 } 20 21 u32 elf_riscv32_reloc_from(u32 elf_type) { 22 /* 64-bit-only wire types are not valid in an ELFCLASS32 object. */ 23 if (elf_type == ELF_R_RISCV_64 || elf_type == ELF_R_RISCV_ADD64 || 24 elf_type == ELF_R_RISCV_SUB64) 25 return (u32)-1; 26 return elf_riscv64_reloc_from(elf_type); 27 }