modlib:so need export symbol, exec elf not need

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao 2024-10-13 17:25:10 +08:00 committed by Xiang Xiao
parent 19b8fdbad6
commit 4156eca0c1
2 changed files with 62 additions and 33 deletions

View file

@ -856,8 +856,6 @@ int modlib_bind(FAR struct module_s *modp,
FAR struct mod_loadinfo_s *loadinfo,
FAR const struct symtab_s *exports, int nexports)
{
FAR Elf_Shdr *symhdr;
FAR Elf_Sym *sym;
int ret;
int i;
@ -991,37 +989,6 @@ int modlib_bind(FAR struct module_s *modp,
}
}
symhdr = &loadinfo->shdr[loadinfo->symtabidx];
sym = lib_malloc(symhdr->sh_size);
ret = modlib_read(loadinfo, (FAR uint8_t *)sym, symhdr->sh_size,
symhdr->sh_offset);
if (ret < 0)
{
berr("Failed to read symbol table\n");
lib_free(sym);
return ret;
}
for (i = 0; i < symhdr->sh_size / sizeof(Elf_Sym); i++)
{
FAR Elf_Shdr *s = &loadinfo->shdr[sym[i].st_shndx];
if (sym[i].st_shndx != SHN_UNDEF)
{
sym[i].st_value = sym[i].st_value + s->sh_addr;
}
}
ret = modlib_insertsymtab(modp, loadinfo, symhdr, sym);
lib_free(sym);
if (ret != 0)
{
binfo("Failed to export symbols program binary: %d\n", ret);
return ret;
}
/* Ensure that the I and D caches are coherent before starting the newly
* loaded module by cleaning the D cache (i.e., flushing the D cache
* contents to memory and invalidating the I cache).

View file

@ -31,6 +31,8 @@
#include <nuttx/lib/lib.h>
#include <nuttx/lib/modlib.h>
#include "modlib.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@ -203,6 +205,59 @@ void modlib_dumpentrypt(FAR struct mod_loadinfo_s *loadinfo)
}
#endif
/****************************************************************************
* Name: modlib_loadsymtab
*
* Description:
* Load the symbol table into memory.
*
****************************************************************************/
static int modlib_loadsymtab(FAR struct module_s *modp,
FAR struct mod_loadinfo_s *loadinfo)
{
FAR Elf_Shdr *symhdr = &loadinfo->shdr[loadinfo->symtabidx];
FAR Elf_Sym *sym = lib_malloc(symhdr->sh_size);
int ret;
int i;
if (sym == NULL)
{
return -ENOMEM;
}
ret = modlib_read(loadinfo, (FAR uint8_t *)sym, symhdr->sh_size,
symhdr->sh_offset);
if (ret < 0)
{
berr("Failed to read symbol table\n");
lib_free(sym);
return ret;
}
for (i = 0; i < symhdr->sh_size / sizeof(Elf_Sym); i++)
{
if (sym[i].st_shndx != SHN_UNDEF &&
sym[i].st_shndx < loadinfo->ehdr.e_shnum)
{
FAR Elf_Shdr *s = &loadinfo->shdr[sym[i].st_shndx];
sym[i].st_value = sym[i].st_value + s->sh_addr;
}
}
ret = modlib_insertsymtab(modp, loadinfo, symhdr, sym);
lib_free(sym);
if (ret != 0)
{
binfo("Failed to export symbols program binary: %d\n", ret);
return ret;
}
return ret;
}
/****************************************************************************
* Name: modlib_insert
*
@ -306,6 +361,13 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname)
goto errout_with_load;
}
ret = modlib_loadsymtab(modp, &loadinfo);
if (ret != 0)
{
binfo("Failed to load symbol table: %d\n", ret);
goto errout_with_load;
}
/* Save the load information */
modp->textalloc = (FAR void *)loadinfo.textalloc;