|
31 | 31 | #include <nuttx/lib/lib.h>
|
32 | 32 | #include <nuttx/lib/modlib.h>
|
33 | 33 |
|
| 34 | +#include "modlib.h" |
| 35 | + |
34 | 36 | /****************************************************************************
|
35 | 37 | * Public Functions
|
36 | 38 | ****************************************************************************/
|
@@ -203,6 +205,59 @@ void modlib_dumpentrypt(FAR struct mod_loadinfo_s *loadinfo)
|
203 | 205 | }
|
204 | 206 | #endif
|
205 | 207 |
|
| 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 | + |
206 | 261 | /****************************************************************************
|
207 | 262 | * Name: modlib_insert
|
208 | 263 | *
|
@@ -306,6 +361,13 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname)
|
306 | 361 | goto errout_with_load;
|
307 | 362 | }
|
308 | 363 |
|
| 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 | + |
309 | 371 | /* Save the load information */
|
310 | 372 |
|
311 | 373 | modp->textalloc = (FAR void *)loadinfo.textalloc;
|
|
0 commit comments