binfmt: Move elf_allocbuffer to elf_sectname and elf_symname

it's better to allocate the buffer just before really use it.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-07-15 22:11:06 +08:00 committed by Petro Karashchenko
parent 6a1abbcf56
commit 879dab08a6
5 changed files with 22 additions and 33 deletions

View File

@ -572,17 +572,6 @@ int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
return ret;
}
/* Allocate an I/O buffer. This buffer is used by elf_symname() to
* accumulate the variable length symbol name.
*/
ret = elf_allocbuffer(loadinfo);
if (ret < 0)
{
berr("elf_allocbuffer failed: %d\n", ret);
return ret;
}
#ifdef CONFIG_ARCH_ADDRENV
/* If CONFIG_ARCH_ADDRENV=y, then the loaded ELF lies in a virtual address
* space that may not be in place now. elf_addrenv_select() will

View File

@ -82,17 +82,6 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
DEBUGASSERT(loadinfo->ctors == NULL);
/* Allocate an I/O buffer if necessary. This buffer is used by
* elf_sectname() to accumulate the variable length symbol name.
*/
ret = elf_allocbuffer(loadinfo);
if (ret < 0)
{
berr("elf_allocbuffer failed: %d\n", ret);
return -ENOMEM;
}
/* Find the index to the section named ".ctors." NOTE: On old ABI system,
* .ctors is the name of the section containing the list of constructors;
* On newer systems, the similar section is called .init_array. It is

View File

@ -83,17 +83,6 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
DEBUGASSERT(loadinfo->dtors == NULL);
/* Allocate an I/O buffer if necessary. This buffer is used by
* elf_sectname() to accumulate the variable length symbol name.
*/
ret = elf_allocbuffer(loadinfo);
if (ret < 0)
{
berr("elf_allocbuffer failed: %d\n", ret);
return -ENOMEM;
}
/* Find the index to the section named ".dtors." NOTE: On old ABI system,
* .dtors is the name of the section containing the list of destructors;
* On newer systems, the similar section is called .fini_array. It is

View File

@ -82,6 +82,17 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
return -EINVAL;
}
/* Allocate an I/O buffer if necessary. This buffer is used by
* elf_sectname() to accumulate the variable length symbol name.
*/
ret = elf_allocbuffer(loadinfo);
if (ret < 0)
{
berr("elf_allocbuffer failed: %d\n", ret);
return ret;
}
/* Get the section name string table section header */
shstr = &loadinfo->shdr[shstrndx];

View File

@ -82,6 +82,17 @@ static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
return -ESRCH;
}
/* Allocate an I/O buffer. This buffer is used by elf_symname() to
* accumulate the variable length symbol name.
*/
ret = elf_allocbuffer(loadinfo);
if (ret < 0)
{
berr("elf_allocbuffer failed: %d\n", ret);
return ret;
}
offset = loadinfo->shdr[loadinfo->strtabidx].sh_offset + sym->st_name;
/* Loop until we get the entire symbol name into memory */