libs/libc/modlib: fix nxstyle issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
440be65010
commit
8a72eaf557
@ -54,9 +54,9 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dq_entry_t entry;
|
||||
Elf_Sym sym;
|
||||
int idx;
|
||||
dq_entry_t entry;
|
||||
Elf_Sym sym;
|
||||
int idx;
|
||||
} Elf_SymCache;
|
||||
|
||||
struct
|
||||
@ -166,19 +166,19 @@ static inline int modlib_readrelas(FAR struct mod_loadinfo_s *loadinfo,
|
||||
static int modlib_relocate(FAR struct module_s *modp,
|
||||
FAR struct mod_loadinfo_s *loadinfo, int relidx)
|
||||
{
|
||||
FAR Elf_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
FAR Elf_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
|
||||
FAR Elf_Rel *rels;
|
||||
FAR Elf_Rel *rel;
|
||||
FAR Elf_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
FAR Elf_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
|
||||
FAR Elf_Rel *rels;
|
||||
FAR Elf_Rel *rel;
|
||||
FAR Elf_SymCache *cache;
|
||||
FAR Elf_Sym *sym;
|
||||
FAR dq_entry_t *e;
|
||||
dq_queue_t q;
|
||||
uintptr_t addr;
|
||||
int symidx;
|
||||
int ret;
|
||||
int i;
|
||||
int j;
|
||||
FAR Elf_Sym *sym;
|
||||
FAR dq_entry_t *e;
|
||||
dq_queue_t q;
|
||||
uintptr_t addr;
|
||||
int symidx;
|
||||
int ret = OK;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
rels = lib_malloc(CONFIG_MODLIB_RELOCATION_BUFFERCOUNT * sizeof(Elf_Rel));
|
||||
if (!rels)
|
||||
@ -194,8 +194,6 @@ static int modlib_relocate(FAR struct module_s *modp,
|
||||
* to be relocated.
|
||||
*/
|
||||
|
||||
ret = OK;
|
||||
|
||||
for (i = j = 0; i < relsec->sh_size / sizeof(Elf_Rel); i++)
|
||||
{
|
||||
/* Read the relocation entry into memory */
|
||||
@ -342,7 +340,7 @@ static int modlib_relocate(FAR struct module_s *modp,
|
||||
}
|
||||
|
||||
lib_free(rels);
|
||||
while ((e = dq_peek(&q)))
|
||||
while ((e = dq_peek(&q)) != NULL)
|
||||
{
|
||||
dq_rem(e, &q);
|
||||
lib_free(e);
|
||||
@ -355,19 +353,19 @@ static int modlib_relocateadd(FAR struct module_s *modp,
|
||||
FAR struct mod_loadinfo_s *loadinfo,
|
||||
int relidx)
|
||||
{
|
||||
FAR Elf_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
FAR Elf_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
|
||||
FAR Elf_Rela *relas;
|
||||
FAR Elf_Rela *rela;
|
||||
FAR Elf_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
FAR Elf_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
|
||||
FAR Elf_Rela *relas;
|
||||
FAR Elf_Rela *rela;
|
||||
FAR Elf_SymCache *cache;
|
||||
FAR Elf_Sym *sym;
|
||||
FAR dq_entry_t *e;
|
||||
dq_queue_t q;
|
||||
uintptr_t addr;
|
||||
int symidx;
|
||||
int ret;
|
||||
int i;
|
||||
int j;
|
||||
FAR Elf_Sym *sym;
|
||||
FAR dq_entry_t *e;
|
||||
dq_queue_t q;
|
||||
uintptr_t addr;
|
||||
int symidx;
|
||||
int ret = OK;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
relas = lib_malloc(CONFIG_MODLIB_RELOCATION_BUFFERCOUNT *
|
||||
sizeof(Elf_Rela));
|
||||
@ -384,8 +382,6 @@ static int modlib_relocateadd(FAR struct module_s *modp,
|
||||
* to be relocated.
|
||||
*/
|
||||
|
||||
ret = OK;
|
||||
|
||||
for (i = j = 0; i < relsec->sh_size / sizeof(Elf_Rela); i++)
|
||||
{
|
||||
/* Read the relocation entry into memory */
|
||||
@ -532,7 +528,7 @@ static int modlib_relocateadd(FAR struct module_s *modp,
|
||||
}
|
||||
|
||||
lib_free(relas);
|
||||
while ((e = dq_peek(&q)))
|
||||
while ((e = dq_peek(&q)) != NULL)
|
||||
{
|
||||
dq_rem(e, &q);
|
||||
lib_free(e);
|
||||
@ -563,14 +559,14 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
|
||||
FAR Elf_Rel *rels = NULL;
|
||||
FAR Elf_Rel *rel;
|
||||
FAR Elf_Sym *sym = NULL;
|
||||
uintptr_t addr;
|
||||
int ret;
|
||||
int i;
|
||||
int idx_rel;
|
||||
int idx_sym;
|
||||
uintptr_t addr;
|
||||
int ret;
|
||||
int i;
|
||||
int idx_rel;
|
||||
int idx_sym;
|
||||
|
||||
dyn = lib_malloc(shdr->sh_size);
|
||||
ret = modlib_read(loadinfo, (FAR uint8_t *) dyn, shdr->sh_size,
|
||||
ret = modlib_read(loadinfo, (FAR uint8_t *)dyn, shdr->sh_size,
|
||||
shdr->sh_offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -586,31 +582,31 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset((void *) &reldata, 0, sizeof(reldata));
|
||||
memset((void *)&reldata, 0, sizeof(reldata));
|
||||
|
||||
for (i = 0; dyn[i].d_tag != DT_NULL; i++)
|
||||
{
|
||||
switch (dyn[i].d_tag)
|
||||
{
|
||||
case DT_REL :
|
||||
case DT_REL:
|
||||
reldata.reloff[I_REL] = dyn[i].d_un.d_val;
|
||||
break;
|
||||
case DT_RELSZ :
|
||||
case DT_RELSZ:
|
||||
reldata.relsz[I_REL] = dyn[i].d_un.d_val;
|
||||
break;
|
||||
case DT_RELENT :
|
||||
case DT_RELENT:
|
||||
reldata.relentsz = dyn[i].d_un.d_val;
|
||||
break;
|
||||
case DT_SYMTAB :
|
||||
case DT_SYMTAB:
|
||||
reldata.symoff = dyn[i].d_un.d_val;
|
||||
break;
|
||||
case DT_STRTAB :
|
||||
case DT_STRTAB:
|
||||
reldata.stroff = dyn[i].d_un.d_val;
|
||||
break;
|
||||
case DT_JMPREL :
|
||||
case DT_JMPREL:
|
||||
reldata.reloff[I_PLT] = dyn[i].d_un.d_val;
|
||||
break;
|
||||
case DT_PLTRELSZ :
|
||||
case DT_PLTRELSZ:
|
||||
reldata.relsz[I_PLT] = dyn[i].d_un.d_val;
|
||||
break;
|
||||
}
|
||||
@ -686,7 +682,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
|
||||
{
|
||||
berr("ERROR: Section %d reloc %d:"
|
||||
"Relocation address out of range, offset %u\n",
|
||||
relidx, i, (int) rel->r_offset);
|
||||
relidx, i, (int)rel->r_offset);
|
||||
ret = -EINVAL;
|
||||
lib_free(sym);
|
||||
lib_free(rels);
|
||||
@ -700,7 +696,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
|
||||
{
|
||||
if (sym[idx_sym].st_shndx == SHN_UNDEF) /* We have an external reference */
|
||||
{
|
||||
void *ep;
|
||||
FAR void *ep;
|
||||
|
||||
ep = modlib_findglobal(modp, loadinfo, symhdr,
|
||||
&sym[idx_sym]);
|
||||
@ -727,11 +723,16 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
|
||||
addr = rel->r_offset - loadinfo->datasec + loadinfo->datastart;
|
||||
|
||||
if ((*(FAR uint32_t *)addr) < loadinfo->datasec)
|
||||
{
|
||||
dynsym.st_value = *(FAR uint32_t *)addr +
|
||||
loadinfo->textalloc;
|
||||
}
|
||||
else
|
||||
{
|
||||
dynsym.st_value = *(FAR uint32_t *)addr -
|
||||
loadinfo->datasec + loadinfo->datastart;
|
||||
}
|
||||
|
||||
ret = up_relocate(rel, &dynsym, addr);
|
||||
}
|
||||
|
||||
@ -753,17 +754,21 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
|
||||
|
||||
/* Relocate the entries in the table */
|
||||
|
||||
for (i = 0; i < (symhdr->sh_size / sizeof(Elf_Sym)); i++)
|
||||
for (i = 0; i < symhdr->sh_size / sizeof(Elf_Sym); i++)
|
||||
{
|
||||
Elf_Shdr *s = &loadinfo->shdr[sym[i].st_shndx];
|
||||
FAR Elf_Shdr *s = &loadinfo->shdr[sym[i].st_shndx];
|
||||
|
||||
if (sym[i].st_shndx != SHN_UNDEF)
|
||||
{
|
||||
if (s->sh_addr < loadinfo->datasec)
|
||||
{
|
||||
sym[i].st_value = sym[i].st_value + loadinfo->textalloc;
|
||||
}
|
||||
else
|
||||
{
|
||||
sym[i].st_value = sym[i].st_value -
|
||||
loadinfo->datasec + loadinfo->datastart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -828,33 +833,33 @@ int modlib_bind(FAR struct module_s *modp,
|
||||
{
|
||||
switch (loadinfo->shdr[i].sh_type)
|
||||
{
|
||||
case SHT_DYNAMIC :
|
||||
ret = modlib_relocatedyn(modp, loadinfo, i);
|
||||
break;
|
||||
case SHT_DYNSYM :
|
||||
loadinfo->dsymtabidx = i;
|
||||
break;
|
||||
case SHT_INIT_ARRAY :
|
||||
loadinfo->initarr = loadinfo->shdr[i].sh_addr -
|
||||
loadinfo->datasec +
|
||||
loadinfo->datastart;
|
||||
loadinfo->ninit = loadinfo->shdr[i].sh_size /
|
||||
sizeof(uintptr_t);
|
||||
break;
|
||||
case SHT_FINI_ARRAY :
|
||||
loadinfo->finiarr = loadinfo->shdr[i].sh_addr -
|
||||
loadinfo->datasec +
|
||||
loadinfo->datastart;
|
||||
loadinfo->nfini = loadinfo->shdr[i].sh_size /
|
||||
sizeof(uintptr_t);
|
||||
break;
|
||||
case SHT_PREINIT_ARRAY :
|
||||
loadinfo->preiarr = loadinfo->shdr[i].sh_addr -
|
||||
loadinfo->datasec +
|
||||
loadinfo->datastart;
|
||||
loadinfo->nprei = loadinfo->shdr[i].sh_size /
|
||||
sizeof(uintptr_t);
|
||||
break;
|
||||
case SHT_DYNAMIC:
|
||||
ret = modlib_relocatedyn(modp, loadinfo, i);
|
||||
break;
|
||||
case SHT_DYNSYM:
|
||||
loadinfo->dsymtabidx = i;
|
||||
break;
|
||||
case SHT_INIT_ARRAY:
|
||||
loadinfo->initarr = loadinfo->shdr[i].sh_addr -
|
||||
loadinfo->datasec +
|
||||
loadinfo->datastart;
|
||||
loadinfo->ninit = loadinfo->shdr[i].sh_size /
|
||||
sizeof(uintptr_t);
|
||||
break;
|
||||
case SHT_FINI_ARRAY:
|
||||
loadinfo->finiarr = loadinfo->shdr[i].sh_addr -
|
||||
loadinfo->datasec +
|
||||
loadinfo->datastart;
|
||||
loadinfo->nfini = loadinfo->shdr[i].sh_size /
|
||||
sizeof(uintptr_t);
|
||||
break;
|
||||
case SHT_PREINIT_ARRAY:
|
||||
loadinfo->preiarr = loadinfo->shdr[i].sh_addr -
|
||||
loadinfo->datasec +
|
||||
loadinfo->datastart;
|
||||
loadinfo->nprei = loadinfo->shdr[i].sh_size /
|
||||
sizeof(uintptr_t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -865,17 +870,17 @@ int modlib_bind(FAR struct module_s *modp,
|
||||
|
||||
if ((loadinfo->shdr[infosec].sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process the relocations by type */
|
||||
|
||||
switch (loadinfo->shdr[i].sh_type)
|
||||
{
|
||||
case SHT_REL :
|
||||
case SHT_REL:
|
||||
ret = modlib_relocate(modp, loadinfo, i);
|
||||
break;
|
||||
case SHT_RELA :
|
||||
case SHT_RELA:
|
||||
ret = modlib_relocateadd(modp, loadinfo, i);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user