nuttx/libs/libc/modlib
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
..
CMakeLists.txt
gnu-elf.ld
Kconfig
Make.defs binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
modlib_bind.c riscv/arch_elf.c: Handle PCREL_HI20/LO12_I/S relocations correctly 2023-12-12 17:32:36 -08:00
modlib_depend.c libs/libc: fix compile warning about modlib_depend when CONFIG_MODLIB_MAXDEPEND = 0 2023-10-26 01:53:38 +08:00
modlib_globals.S Fix loading of ET_DYN type of shared objects 2023-09-20 09:35:28 -04:00
modlib_init.c libs/modlib: remove dupliate define about modlib_dumpbuffer 2023-10-26 01:53:38 +08:00
modlib_iobuffer.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
modlib_load.c modlib/modlib_load: fix compile warning 2023-10-26 01:53:38 +08:00
modlib_loadhdrs.c libs/modlib: avoid double free when call modlib_unload with erro 2023-09-20 17:02:29 +08:00
modlib_read.c libs/modlib: avoid seeking in each reading 2023-09-20 17:02:29 +08:00
modlib_registry.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
modlib_sections.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
modlib_symbols.c modlib/modlib_load: fix compile warning 2023-10-26 01:53:38 +08:00
modlib_symtab.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
modlib_uninit.c libs/modlib: close fd when error happen 2023-09-20 17:02:29 +08:00
modlib_unload.c libs/modlib: Adding architecture-specific memory allocator for dynamic data loading 2023-10-26 01:53:38 +08:00
modlib_verify.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
modlib.h binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00