modlib: Move modlib_allocbuffer to modlib_sectname and modlib_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:24:43 +08:00 committed by Petro Karashchenko
parent 879dab08a6
commit 120c4a1660
3 changed files with 22 additions and 11 deletions

View File

@ -811,17 +811,6 @@ int modlib_bind(FAR struct module_s *modp,
return ret;
}
/* Allocate an I/O buffer. This buffer is used by mod_symname() to
* accumulate the variable length symbol name.
*/
ret = modlib_allocbuffer(loadinfo);
if (ret < 0)
{
berr("ERROR: modlib_allocbuffer failed: %d\n", ret);
return -ENOMEM;
}
/* Process relocations in every allocated section */
for (i = 1; i < loadinfo->ehdr.e_shnum; i++)

View File

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

View File

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