Skip to content

Commit 4156eca

Browse files
anjiahao1xiaoxiang781216
authored andcommitted
modlib:so need export symbol, exec elf not need
Signed-off-by: anjiahao <[email protected]>
1 parent 19b8fdb commit 4156eca

File tree

2 files changed

+62
-33
lines changed

2 files changed

+62
-33
lines changed

libs/libc/modlib/modlib_bind.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,6 @@ int modlib_bind(FAR struct module_s *modp,
856856
FAR struct mod_loadinfo_s *loadinfo,
857857
FAR const struct symtab_s *exports, int nexports)
858858
{
859-
FAR Elf_Shdr *symhdr;
860-
FAR Elf_Sym *sym;
861859
int ret;
862860
int i;
863861

@@ -991,37 +989,6 @@ int modlib_bind(FAR struct module_s *modp,
991989
}
992990
}
993991

994-
symhdr = &loadinfo->shdr[loadinfo->symtabidx];
995-
sym = lib_malloc(symhdr->sh_size);
996-
997-
ret = modlib_read(loadinfo, (FAR uint8_t *)sym, symhdr->sh_size,
998-
symhdr->sh_offset);
999-
1000-
if (ret < 0)
1001-
{
1002-
berr("Failed to read symbol table\n");
1003-
lib_free(sym);
1004-
return ret;
1005-
}
1006-
1007-
for (i = 0; i < symhdr->sh_size / sizeof(Elf_Sym); i++)
1008-
{
1009-
FAR Elf_Shdr *s = &loadinfo->shdr[sym[i].st_shndx];
1010-
1011-
if (sym[i].st_shndx != SHN_UNDEF)
1012-
{
1013-
sym[i].st_value = sym[i].st_value + s->sh_addr;
1014-
}
1015-
}
1016-
1017-
ret = modlib_insertsymtab(modp, loadinfo, symhdr, sym);
1018-
lib_free(sym);
1019-
if (ret != 0)
1020-
{
1021-
binfo("Failed to export symbols program binary: %d\n", ret);
1022-
return ret;
1023-
}
1024-
1025992
/* Ensure that the I and D caches are coherent before starting the newly
1026993
* loaded module by cleaning the D cache (i.e., flushing the D cache
1027994
* contents to memory and invalidating the I cache).

libs/libc/modlib/modlib_insert.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <nuttx/lib/lib.h>
3232
#include <nuttx/lib/modlib.h>
3333

34+
#include "modlib.h"
35+
3436
/****************************************************************************
3537
* Public Functions
3638
****************************************************************************/
@@ -203,6 +205,59 @@ void modlib_dumpentrypt(FAR struct mod_loadinfo_s *loadinfo)
203205
}
204206
#endif
205207

208+
/****************************************************************************
209+
* Name: modlib_loadsymtab
210+
*
211+
* Description:
212+
* Load the symbol table into memory.
213+
*
214+
****************************************************************************/
215+
216+
static int modlib_loadsymtab(FAR struct module_s *modp,
217+
FAR struct mod_loadinfo_s *loadinfo)
218+
{
219+
FAR Elf_Shdr *symhdr = &loadinfo->shdr[loadinfo->symtabidx];
220+
FAR Elf_Sym *sym = lib_malloc(symhdr->sh_size);
221+
int ret;
222+
int i;
223+
224+
if (sym == NULL)
225+
{
226+
return -ENOMEM;
227+
}
228+
229+
ret = modlib_read(loadinfo, (FAR uint8_t *)sym, symhdr->sh_size,
230+
symhdr->sh_offset);
231+
232+
if (ret < 0)
233+
{
234+
berr("Failed to read symbol table\n");
235+
lib_free(sym);
236+
return ret;
237+
}
238+
239+
for (i = 0; i < symhdr->sh_size / sizeof(Elf_Sym); i++)
240+
{
241+
if (sym[i].st_shndx != SHN_UNDEF &&
242+
sym[i].st_shndx < loadinfo->ehdr.e_shnum)
243+
{
244+
FAR Elf_Shdr *s = &loadinfo->shdr[sym[i].st_shndx];
245+
246+
sym[i].st_value = sym[i].st_value + s->sh_addr;
247+
}
248+
}
249+
250+
ret = modlib_insertsymtab(modp, loadinfo, symhdr, sym);
251+
lib_free(sym);
252+
if (ret != 0)
253+
{
254+
binfo("Failed to export symbols program binary: %d\n", ret);
255+
return ret;
256+
}
257+
258+
return ret;
259+
}
260+
206261
/****************************************************************************
207262
* Name: modlib_insert
208263
*
@@ -306,6 +361,13 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname)
306361
goto errout_with_load;
307362
}
308363

364+
ret = modlib_loadsymtab(modp, &loadinfo);
365+
if (ret != 0)
366+
{
367+
binfo("Failed to load symbol table: %d\n", ret);
368+
goto errout_with_load;
369+
}
370+
309371
/* Save the load information */
310372

311373
modp->textalloc = (FAR void *)loadinfo.textalloc;

0 commit comments

Comments
 (0)