binfmt/libelf: Enable ELF loader if text heap read is word-aligned
The ELF loader needs to load the app into the memory before executing it from the same location. As expected, this memory space should be able to execute code. For architectures containing data and instruction buses, the instruction bus may not be able to be accessed in a non-aligned way, which is usually required when copying data to that location. Eventually, this same memory space can be accessed through the data bus, using different address ranges. This commit enables accessing the memory through the data bus to copy the app's data before executing it when `CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ` is enabled.
This commit is contained in:
parent
d74a612a6e
commit
84d39a8d9a
|
@ -96,7 +96,11 @@ static void elf_elfsize(FAR struct elf_loadinfo_s *loadinfo)
|
||||||
* able
|
* able
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((shdr->sh_flags & SHF_WRITE) != 0)
|
if ((shdr->sh_flags & SHF_WRITE) != 0
|
||||||
|
#ifdef CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ
|
||||||
|
|| (shdr->sh_flags & SHF_EXECINSTR) == 0
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
datasize = _ALIGN_UP(datasize, shdr->sh_addralign);
|
datasize = _ALIGN_UP(datasize, shdr->sh_addralign);
|
||||||
datasize += ELF_ALIGNUP(shdr->sh_size);
|
datasize += ELF_ALIGNUP(shdr->sh_size);
|
||||||
|
@ -200,7 +204,11 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
|
||||||
* able
|
* able
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((shdr->sh_flags & SHF_WRITE) != 0)
|
if ((shdr->sh_flags & SHF_WRITE) != 0
|
||||||
|
#ifdef CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ
|
||||||
|
|| (shdr->sh_flags & SHF_EXECINSTR) == 0
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
pptr = &data;
|
pptr = &data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/elf.h>
|
#include <nuttx/elf.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -200,7 +201,7 @@ int up_relocateadd(const Elf32_Rela *rel, const Elf32_Sym *sym,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_XTENSA_SLOT0_OP:
|
case R_XTENSA_SLOT0_OP:
|
||||||
p = (unsigned char *)addr;
|
p = (unsigned char *)up_textheap_data_address((void *)addr);
|
||||||
if (is_l32r(p))
|
if (is_l32r(p))
|
||||||
{
|
{
|
||||||
/* Xtensa ISA:
|
/* Xtensa ISA:
|
||||||
|
|
|
@ -112,7 +112,11 @@ static void modlib_elfsize(FAR struct mod_loadinfo_s *loadinfo)
|
||||||
* able
|
* able
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((shdr->sh_flags & SHF_WRITE) != 0)
|
if ((shdr->sh_flags & SHF_WRITE) != 0
|
||||||
|
#ifdef CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ
|
||||||
|
|| (shdr->sh_flags & SHF_EXECINSTR) == 0
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
datasize = _ALIGN_UP(datasize, shdr->sh_addralign);
|
datasize = _ALIGN_UP(datasize, shdr->sh_addralign);
|
||||||
datasize += ELF_ALIGNUP(shdr->sh_size);
|
datasize += ELF_ALIGNUP(shdr->sh_size);
|
||||||
|
@ -214,7 +218,11 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
|
||||||
* able
|
* able
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((shdr->sh_flags & SHF_WRITE) != 0)
|
if ((shdr->sh_flags & SHF_WRITE) != 0
|
||||||
|
#ifdef CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ
|
||||||
|
|| (shdr->sh_flags & SHF_EXECINSTR) == 0
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
pptr = &data;
|
pptr = &data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue