mirror of
https://github.com/apache/nuttx.git
synced 2025-12-06 17:23:49 +08:00
modlib:support modlib can load PIC elf
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
@@ -28,7 +28,7 @@ config BINFMT_LOADABLE
|
||||
Automatically selected if a loadable binary format is selected.
|
||||
|
||||
config PIC
|
||||
bool
|
||||
bool "Executable elf position-independent support"
|
||||
default n
|
||||
---help---
|
||||
Automatically selected if the binary format requires position
|
||||
|
||||
20
binfmt/elf.c
20
binfmt/elf.c
@@ -33,6 +33,7 @@
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#ifdef CONFIG_ELF
|
||||
|
||||
@@ -119,7 +120,7 @@ static int elf_loadbinary(FAR struct binary_s *binp,
|
||||
|
||||
/* Bind the program to the exported symbol table */
|
||||
|
||||
if (loadinfo.ehdr.e_type == ET_REL)
|
||||
if (loadinfo.ehdr.e_type == ET_REL || loadinfo.gotindex >= 0)
|
||||
{
|
||||
ret = modlib_bind(&binp->mod, &loadinfo, exports, nexports);
|
||||
if (ret != 0)
|
||||
@@ -207,6 +208,23 @@ static int elf_loadbinary(FAR struct binary_s *binp,
|
||||
#endif
|
||||
|
||||
modlib_dumpentrypt(&loadinfo);
|
||||
#ifdef CONFIG_PIC
|
||||
if (loadinfo.gotindex >= 0)
|
||||
{
|
||||
FAR struct dspace_s *dspaces = kmm_zalloc(sizeof(struct dspace_s));
|
||||
|
||||
if (dspaces == NULL)
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_load;
|
||||
}
|
||||
|
||||
dspaces->region = (FAR void *)loadinfo.shdr[loadinfo.gotindex].sh_addr;
|
||||
dspaces->crefs = 1;
|
||||
binp->picbase = (FAR void *)dspaces;
|
||||
}
|
||||
#endif
|
||||
|
||||
modlib_uninitialize(&loadinfo);
|
||||
return OK;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user