incubator-nuttx/binfmt
Ville Juven 996625ec58 riscv/arch_elf.c: Handle PCREL_HI20/LO12_I/S relocations correctly
There is a problem with the current elf loader for risc-v: when a pair of
PCREL_HI20 / LO12 relocations are encountered, it is assumed that these
will follow each other immediately, as follows:

label:
	auipc      a0, %pcrel_hi(symbol)    // R_RISCV_PCREL_HI20
	load/store a0, %pcrel_lo(label)(a0) // R_RISCV_PCREL_LO12_I/S

With this assumption, the hi/lo relocations are both done when a hi20
relocation entry is encountered, first to the current instruction (addr)
and to the next instruction (addr + 4).

However, this assumption is wrong. There is nothing in the elf relocation
specification[1] that mandates this. Thus, the hi/lo relocation always
needs to first fixup the hi-part, and when the lo-part is encountered, it
needs to find the corresponding hi relocation entry, via the given "label".
This necessitates (re-)visiting the relocation entries for the current
section as well as looking for "label" in the symbol table.

The NuttX elf loader does not allow such operations to be done in the
machine specific part, so this patch fixes the relocation issue by
introducing an architecture specific cache for the hi20 relocation and
symbol table entries. When a lo12 relocation is encountered, the cache
can be consulted to find the hi20 part.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc
2023-12-12 17:32:36 -08:00
..
libelf riscv/arch_elf.c: Handle PCREL_HI20/LO12_I/S relocations correctly 2023-12-12 17:32:36 -08:00
libnxflat enable O_CLOEXEC explicit 2023-09-22 13:51:00 +08:00
CMakeLists.txt sched/taskfiles: skip unnecessary file open/close operations to improve performance 2023-11-16 07:30:36 -08:00
Kconfig binfmt/elf: Select ARCH_USE_TEXT_HEAP if ARCH_HAVE_TEXT_HEAP 2023-10-27 15:42:02 +09:00
Makefile sched/taskfiles: skip unnecessary file open/close operations to improve performance 2023-11-16 07:30:36 -08:00
binfmt.h sched/taskfiles: skip unnecessary file open/close operations to improve performance 2023-11-16 07:30:36 -08:00
binfmt_copyactions.c sched/taskfiles: skip unnecessary file open/close operations to improve performance 2023-11-16 07:30:36 -08:00
binfmt_copyargv.c mm/alloc: remove all unnecessary cast for alloc 2023-08-30 14:34:20 +08:00
binfmt_coredump.c elf/coredump: add support of dump task stack without memory segments 2023-05-24 22:34:47 +08:00
binfmt_dumpmodule.c sched/spawn: Support task_spawnattr_[set|get]stackaddr 2022-10-31 12:46:58 +09:00
binfmt_exec.c sched/task_[posix]spawn: Simplify how spawn attributes are handled 2023-10-25 11:55:44 -03:00
binfmt_execmodule.c sched/taskfiles: skip unnecessary file open/close operations to improve performance 2023-11-16 07:30:36 -08:00
binfmt_execsymtab.c libc/symtab: Don't include symtab.h in the header files 2023-07-10 23:03:17 +03:00
binfmt_exit.c Author: Gregory Nutt: update licenses to Apache 2021-02-05 12:15:56 -03:00
binfmt_globals.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
binfmt_initialize.c binfmt: Move [elf|nxflat]_[un]initialize to private header file 2023-07-10 23:03:17 +03:00
binfmt_loadmodule.c binfmt: remove sched_[un]lock 2023-07-26 09:43:51 -07:00
binfmt_register.c binfmt: remove sched_[un]lock 2023-07-26 09:43:51 -07:00
binfmt_unloadmodule.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
binfmt_unregister.c binfmt: remove sched_[un]lock 2023-07-26 09:43:51 -07:00
builtin.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
elf.c binfmt: ELF support load to LMA 2023-09-04 12:23:26 +08:00
nxflat.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00