ldelf: support 32-bit RISC-V TAs #8263
FYI @larper2axis
This assumes the value of elf->load_addr + rela->r_offset to be 4-byte aligned. Recommend adding a check to err() if not: unaligned access is UB.
Good point. I copied this from the existing e32_relocate() (Arm32 REL) and e64_relocate() (AArch64 and RV64 RELA), which compute where the same way without an alignment check. Should I add the check to those as well? I could do that in a separate PR
Yes, please do that in a separate PR.
While this avoids duplicating the implementation of e32_get_sym_name(), I wonder if it wouldn't be even better to change the arguments for e32_get_sym_name() to take size_t sym_idx instead of Elf32_Rel *rel.
There are a few affected call sites, but replacing rel with ELF32_R_SYM(rel->r_info) shouldn't be too bad.
hl5746
mikatammi
The TA dev kit builds RV32 TAs (
ta_rv32), but ldelf loads RISC-V TAsonly as ELF64 files: it has no start file for RV32, and it parses and
relocates ELF32 files for ARM32 only, whose relocations are REL.
RV32 TAs are ELF32 files with RELA relocations (
R_RISCV_RELATIVE,R_RISCV_32andR_RISCV_JUMP_SLOT). This parses their header,processes their RELA sections and starts ldelf with
start_rv32.S, whichis
start_rv64.Swith 32-bit words andElf32_Relaentries. Theirstacks are aligned to 16 bytes as on RV64, since the RISC-V psABI asks it
of both.
The RV32 stub of
e64_parse_ehdr()takes avoid: withElf64_Ehdron its continuation line, as in the ARM32 and RV64 stubs, checkpatch
reads the
*as a multiplication.On RV32, ldelf also needs the 64-bit integer routines from #8262 to link.
Upstream can't build RV32 yet. This turned up in a port of OP-TEE to RV32
that is out of tree for now.
Tested:
1006, 1008, 1019 and 4001 pass (698 subtests, 0 failed). Every TA load
goes through this code, and 1019 loads a dynamically linked TA. The
port's full xtest run (119 test cases) passed with this ldelf code too,
apart from the comment in
start_rv32.Sand the stub's parameter type.PLATFORM=virtstill builds.AI disclosure: Claude Opus 5.5 was used in the process