diff --git a/binfmt/libelf/libelf_load.c b/binfmt/libelf/libelf_load.c index 2a6be23bc6b22..9761039fb8bde 100644 --- a/binfmt/libelf/libelf_load.c +++ b/binfmt/libelf/libelf_load.c @@ -187,15 +187,6 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo) { FAR Elf_Shdr *shdr = &loadinfo->shdr[i]; - /* SHF_ALLOC indicates that the section requires memory during - * execution. - */ - - if ((shdr->sh_flags & SHF_ALLOC) == 0) - { - continue; - } - /* SHF_WRITE indicates that the section address space is write- * able */ @@ -209,6 +200,18 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo) pptr = &text; } + /* SHF_ALLOC indicates that the section requires memory during + * execution. + */ + + if ((shdr->sh_flags & SHF_ALLOC) == 0) + { + /* Set the VMA regardless, some relocations might depend on this */ + + shdr->sh_addr = (uintptr_t)*pptr; + continue; + } + if (*pptr == NULL) { if (shdr->sh_type != SHT_NOBITS)