Skip to content

Commit

Permalink
modlib:so need export symbol, exec elf not need
Browse files Browse the repository at this point in the history
Signed-off-by: anjiahao <[email protected]>
  • Loading branch information
anjiahao1 committed Oct 14, 2024
1 parent fe3033c commit 1eb7aa6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
33 changes: 0 additions & 33 deletions libs/libc/modlib/modlib_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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).
Expand Down
62 changes: 62 additions & 0 deletions libs/libc/modlib/modlib_insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <nuttx/lib/lib.h>
#include <nuttx/lib/modlib.h>

#include "modlib.h"

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1eb7aa6

Please sign in to comment.