nuttx/binfmt/libelf
Ville Juven 9da9d3ea8c binfmt/elf_loadfile: Set sh_addr even if SHF_ALLOC == 0
Set sh_addr for regions that are not allocated. Some relocations might
depend on this.

The fault in my case occurs when setting CONFIG_HAVE_CXX=y. In this case,
the .ctor and .dtor sections do not get allocated, but the crt code
depends on linker defined symbols _sctors/_ectors etc. These generate PC
relative relocations and thus, the .ctor and .dtor output sections need
an output VMA even though nothing is there. Otherwise the relocations will
point to god knows where (in my case to address 0).

The problem results in full system crash later:
elf_symvalue: Other: 00000000+00000001=00000001
up_relocateadd: PCREL_HI20 at c00002dc [00000417] to sym=0x80409e80 st_value=1
_calc_imm: offset=-3221226203: hi=-786432 lo=-731
up_relocateadd: ERROR: PCREL_HI20 at c00002dc bad:ffffffff40000000
elf_relocateadd: ERROR: Section 2 reloc 52: Relocation failed: -22

The RISC-V elf64 linker does not like the uninitialized PC relative
relocation entries, as the relocation offset cannot be reached with
with the RV64 instruction set.

More about this issue can be found here:
https://github.com/apache/nuttx/pull/11322
2024-08-07 08:45:50 +08:00
..
CMakeLists.txt
gnu-elf.ld
Kconfig binfmt: ELF support load to LMA 2023-09-04 12:23:26 +08:00
libelf_addrenv.c libs/modlib: Adding architecture-specific memory allocator for dynamic data loading 2023-10-26 01:53:38 +08:00
libelf_bind.c log messages of binfmt are very much. 2023-12-29 17:36:47 +08:00
libelf_coredump.c Revert "sched: replace some global variables to macro" 2024-06-06 22:00:25 +08:00
libelf_ctors.c mm/alloc: remove all unnecessary cast for alloc 2023-08-30 14:34:20 +08:00
libelf_dtors.c mm/alloc: remove all unnecessary cast for alloc 2023-08-30 14:34:20 +08:00
libelf_init.c enable O_CLOEXEC explicit 2023-09-22 13:51:00 +08:00
libelf_iobuffer.c mm/alloc: remove all unnecessary cast for alloc 2023-08-30 14:34:20 +08:00
libelf_load.c binfmt/elf_loadfile: Set sh_addr even if SHF_ALLOC == 0 2024-08-07 08:45:50 +08:00
libelf_read.c binfmt: Support arch copy section by self for dynamic code loading 2023-09-04 12:23:26 +08:00
libelf_sections.c binfmt: The program headers are optional. 2023-09-05 12:31:31 +08:00
libelf_symbols.c log messages of binfmt are very much. 2023-12-29 17:36:47 +08:00
libelf_uninit.c binfmt: ELF support load to LMA 2023-09-04 12:23:26 +08:00
libelf_unload.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
libelf_verify.c binfmt/elf: Fix the minor style issue 2023-08-27 18:46:40 -03:00
libelf.h binfmt: ELF support load to LMA 2023-09-04 12:23:26 +08:00
Make.defs binfmt: Move [elf|nxflat]_[un]initialize to private header file 2023-07-10 23:03:17 +03:00