Skip to content

Commit cc2b937

Browse files
committed
libs/libc/elf: Fix the nxstyle errors around the FDPIC changes.
The FDPIC work touches these files, and nxstyle reports errors on the lines around every hunk, which fails the check job. The errors are older than this series: a switch body indented two columns too deep in elf_symbols.c, and declarations with no blank line after them. Whitespace and one reworded comment, no change in behaviour. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent f5a8b8d commit cc2b937

3 files changed

Lines changed: 124 additions & 119 deletions

File tree

libs/libc/elf/elf_insert.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void libelf_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo)
8585
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
8686
{
8787
FAR Elf_Shdr *shdr = &loadinfo->shdr[i];
88+
8889
binfo("Sections %d:\n", i);
8990
# ifdef CONFIG_ARCH_USE_SEPARATED_SECTION
9091
if (loadinfo->ehdr.e_type == ET_REL)
@@ -420,27 +421,27 @@ FAR void *libelf_insert(FAR const char *filename, FAR const char *modname)
420421
case ET_REL :
421422
case ET_DYN :
422423

423-
/* Process any preinit_array entries */
424+
/* Process any preinit_array entries */
424425

425-
array = (FAR void (**)(void))loadinfo.preiarr;
426-
for (i = 0; i < loadinfo.nprei; i++)
427-
{
428-
array[i]();
429-
}
426+
array = (FAR void (**)(void))loadinfo.preiarr;
427+
for (i = 0; i < loadinfo.nprei; i++)
428+
{
429+
array[i]();
430+
}
430431

431-
/* Process any init_array entries */
432+
/* Process any init_array entries */
432433

433-
array = (FAR void (**)(void))loadinfo.initarr;
434-
for (i = 0; i < loadinfo.ninit; i++)
435-
{
436-
array[i]();
437-
}
434+
array = (FAR void (**)(void))loadinfo.initarr;
435+
for (i = 0; i < loadinfo.ninit; i++)
436+
{
437+
array[i]();
438+
}
438439

439-
modp->initarr = loadinfo.initarr;
440-
modp->ninit = loadinfo.ninit;
441-
modp->finiarr = loadinfo.finiarr;
442-
modp->nfini = loadinfo.nfini;
443-
break;
440+
modp->initarr = loadinfo.initarr;
441+
modp->ninit = loadinfo.ninit;
442+
modp->finiarr = loadinfo.finiarr;
443+
modp->nfini = loadinfo.nfini;
444+
break;
444445
}
445446

446447
/* Add the new module entry to the registry */

libs/libc/elf/elf_load.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ static inline int libelf_loadfile(FAR struct mod_loadinfo_s *loadinfo)
419419
else
420420
{
421421
size_t bsssize = phdr->p_memsz - phdr->p_filesz;
422+
422423
ret = libelf_read(loadinfo, data, phdr->p_filesz,
423424
phdr->p_offset);
424425
memset(data + phdr->p_filesz, 0, bsssize);
@@ -663,6 +664,7 @@ static int libelf_xipacquire(FAR struct mod_loadinfo_s *loadinfo)
663664
if (ioctl(loadinfo->filfd, XIPFSIOC_PIN, (unsigned long)&base) >= 0)
664665
{
665666
int ret = libelf_pinhold(loadinfo);
667+
666668
if (ret < 0)
667669
{
668670
berr("ERROR: Failed to hold the pinned file: %d\n", ret);

libs/libc/elf/elf_symbols.c

Lines changed: 104 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static int libelf_symcallback(FAR struct module_s *modp, FAR void *arg)
220220

221221
#if CONFIG_LIBC_ELF_MAXDEPEND > 0
222222
int ret = libelf_depend(exportinfo->modp, modp);
223+
223224
if (ret < 0)
224225
{
225226
berr("ERROR: libelf_depend failed: %d\n", ret);
@@ -354,108 +355,108 @@ int libelf_symvalue(FAR struct module_s *modp,
354355

355356
switch (sym->st_shndx)
356357
{
357-
case SHN_COMMON:
358-
{
359-
/* NuttX ELF modules should be compiled with -fno-common. */
360-
361-
berr("ERROR: SHN_COMMON: Re-compile with -fno-common\n");
362-
return -ENOSYS;
363-
}
364-
365-
case SHN_ABS:
366-
{
367-
/* st_value already holds the correct value */
368-
369-
binfo("SHN_ABS: st_value=%08lx\n", (long)sym->st_value);
370-
return OK;
371-
}
372-
373-
case SHN_UNDEF:
374-
{
375-
/* Get the name of the undefined symbol */
376-
377-
ret = libelf_symname(loadinfo, sym, sh_offset);
378-
if (ret < 0)
379-
{
380-
/* There are a few relocations for a few architectures that do
381-
* no depend upon a named symbol. We don't know if that is the
382-
* case here, but return and special error to the caller to
383-
* indicate the nameless symbol.
384-
*/
385-
386-
berr("ERROR: SHN_UNDEF: Failed to get symbol name: %d\n", ret);
387-
return ret;
388-
}
389-
390-
/* First check if the symbol is exported by an installed module.
391-
* Newest modules are installed at the head of the list. Therefore,
392-
* if the symbol is exported by numerous modules, then the most
393-
* recently installed will take precedence.
394-
*/
395-
396-
exportinfo.name = (FAR const char *)loadinfo->iobuffer;
397-
exportinfo.modp = modp;
398-
exportinfo.symbol = NULL;
399-
400-
ret = libelf_registry_foreach(libelf_symcallback,
401-
(FAR void *)&exportinfo);
402-
if (ret < 0)
403-
{
404-
berr("ERROR: libelf_symcallback failed: %d\n", ret);
405-
return ret;
406-
}
407-
408-
symbol = exportinfo.symbol;
409-
410-
/* If the symbol is not exported by any module, then check if the
411-
* base code exports a symbol of this name.
412-
*/
413-
414-
if (symbol == NULL)
415-
{
416-
symbol = symtab_findbyname(exports, exportinfo.name,
417-
nexports);
418-
}
419-
420-
/* Was the symbol found from any exporter? */
421-
422-
if (symbol == NULL)
423-
{
424-
berr("ERROR: SHN_UNDEF: Exported symbol \"%s\" not found\n",
425-
loadinfo->iobuffer);
426-
return -ENOENT;
427-
}
428-
429-
/* Yes... add the exported symbol value to the ELF symbol tablei
430-
* entry
431-
*/
432-
433-
binfo("SHN_UNDEF: name=%s "
434-
"%08" PRIxPTR "+%08" PRIxPTR "=%08" PRIxPTR "\n",
435-
loadinfo->iobuffer,
436-
(uintptr_t)sym->st_value, (uintptr_t)symbol->sym_value,
437-
(uintptr_t)(sym->st_value + (uintptr_t)symbol->sym_value));
438-
439-
sym->st_value += ((uintptr_t)symbol->sym_value);
440-
}
441-
break;
442-
443-
default:
444-
{
445-
secbase = loadinfo->shdr[sym->st_shndx].sh_addr;
446-
447-
binfo("Other[%d]: %08" PRIxPTR "+%08" PRIxPTR "=%08" PRIxPTR "\n",
448-
sym->st_shndx,
449-
(uintptr_t)sym->st_value, secbase,
450-
(uintptr_t)(sym->st_value + secbase));
451-
452-
sym->st_value += secbase;
453-
if (loadinfo->gotindex >= 0)
454-
{
455-
sym->st_value -= loadinfo->shdr[sym->st_shndx].sh_offset;
456-
}
457-
}
458-
break;
358+
case SHN_COMMON:
359+
{
360+
/* NuttX ELF modules should be compiled with -fno-common. */
361+
362+
berr("ERROR: SHN_COMMON: Re-compile with -fno-common\n");
363+
return -ENOSYS;
364+
}
365+
366+
case SHN_ABS:
367+
{
368+
/* st_value already holds the correct value */
369+
370+
binfo("SHN_ABS: st_value=%08lx\n", (long)sym->st_value);
371+
return OK;
372+
}
373+
374+
case SHN_UNDEF:
375+
{
376+
/* Get the name of the undefined symbol */
377+
378+
ret = libelf_symname(loadinfo, sym, sh_offset);
379+
if (ret < 0)
380+
{
381+
/* There are a few relocations for a few architectures that do
382+
* no depend upon a named symbol. We don't know if that is the
383+
* case here, but return and special error to the caller to
384+
* indicate the nameless symbol.
385+
*/
386+
387+
berr("ERROR: SHN_UNDEF: Failed to get symbol name: %d\n", ret);
388+
return ret;
389+
}
390+
391+
/* First check if the symbol is exported by an installed module.
392+
* Newest modules are installed at the head of the list. So if
393+
* the symbol is exported by numerous modules, then the most
394+
* recently installed will take precedence.
395+
*/
396+
397+
exportinfo.name = (FAR const char *)loadinfo->iobuffer;
398+
exportinfo.modp = modp;
399+
exportinfo.symbol = NULL;
400+
401+
ret = libelf_registry_foreach(libelf_symcallback,
402+
(FAR void *)&exportinfo);
403+
if (ret < 0)
404+
{
405+
berr("ERROR: libelf_symcallback failed: %d\n", ret);
406+
return ret;
407+
}
408+
409+
symbol = exportinfo.symbol;
410+
411+
/* If the symbol is not exported by any module, then check if the
412+
* base code exports a symbol of this name.
413+
*/
414+
415+
if (symbol == NULL)
416+
{
417+
symbol = symtab_findbyname(exports, exportinfo.name,
418+
nexports);
419+
}
420+
421+
/* Was the symbol found from any exporter? */
422+
423+
if (symbol == NULL)
424+
{
425+
berr("ERROR: SHN_UNDEF: Exported symbol \"%s\" not found\n",
426+
loadinfo->iobuffer);
427+
return -ENOENT;
428+
}
429+
430+
/* Yes... add the exported symbol value to the ELF symbol tablei
431+
* entry
432+
*/
433+
434+
binfo("SHN_UNDEF: name=%s "
435+
"%08" PRIxPTR "+%08" PRIxPTR "=%08" PRIxPTR "\n",
436+
loadinfo->iobuffer,
437+
(uintptr_t)sym->st_value, (uintptr_t)symbol->sym_value,
438+
(uintptr_t)(sym->st_value + (uintptr_t)symbol->sym_value));
439+
440+
sym->st_value += ((uintptr_t)symbol->sym_value);
441+
}
442+
break;
443+
444+
default:
445+
{
446+
secbase = loadinfo->shdr[sym->st_shndx].sh_addr;
447+
448+
binfo("Other[%d]: %08" PRIxPTR "+%08" PRIxPTR "=%08" PRIxPTR "\n",
449+
sym->st_shndx,
450+
(uintptr_t)sym->st_value, secbase,
451+
(uintptr_t)(sym->st_value + secbase));
452+
453+
sym->st_value += secbase;
454+
if (loadinfo->gotindex >= 0)
455+
{
456+
sym->st_value -= loadinfo->shdr[sym->st_shndx].sh_offset;
457+
}
458+
}
459+
break;
459460
}
460461

461462
return OK;
@@ -597,6 +598,7 @@ static int findep(FAR const void *c1, FAR const void *c2)
597598
{
598599
FAR const struct eptable_s *m1 = (FAR const struct eptable_s *)c1;
599600
FAR const struct eptable_s *m2 = (FAR const struct eptable_s *)c2;
601+
600602
return strcmp((FAR const char *)m1->epname, (FAR const char *)m2->epname);
601603
}
602604

0 commit comments

Comments
 (0)