Skip to content

Commit

Permalink
More ELF loader changes
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5261 42af7a65-404d-4744-a932-0658087f49c3
  • Loading branch information
patacongo committed Oct 25, 2012
1 parent 87e9dbc commit abf9559
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ ifneq ($(APPDIR),)
fi
@$(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" distclean
@if [ -r _SAVED_APPS_config ]; then \
@mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \
mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \
{ echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } \
fi
endif
Expand Down
4 changes: 3 additions & 1 deletion arch/sim/src/up_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include <nuttx/config.h>

#include <stdlib.h>
#include <elf.h>
#include <errno.h>
#include <debug.h>

#include <nuttx/arch.h>
#include <nuttx/binfmt/elf.h>
Expand Down Expand Up @@ -113,7 +115,7 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
{
FAR uint32_t *ptr = (FAR uint32_t *)addr;

switch (ELF_REL_TYPE(rel->r_info))
switch (ELF32_R_TYPE(rel->r_info))
{
case R_386_32:
*ptr += sym->st_value;
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/src/common/up_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include <nuttx/config.h>

#include <stdlib.h>
#include <elf.h>
#include <errno.h>
#include <debug.h>

#include <nuttx/arch.h>
#include <nuttx/binfmt/elf.h>
Expand Down Expand Up @@ -113,7 +115,7 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
{
FAR uint32_t *ptr = (FAR uint32_t *)addr;

switch (ELF_REL_TYPE(rel->r_info))
switch (ELF32_R_TYPE(rel->r_info))
{
case R_386_32:
*ptr += sym->st_value;
Expand Down
10 changes: 5 additions & 5 deletions binfmt/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);

if (loadinfo->shdr && loadinfo->ehdr.e_shum > 0)
if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
{
for (i = 0; i < loadinfo->ehdr.e_shum; i++)
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{
FAR ELF32_Shdr *shdr = &loadinfo->shdr[i];
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
bdbg("Sections %d:\n", i);
bdbg(" sh_name: %08x\n", shdr->sh_name);
bdbg(" sh_type: %08x\n", shdr->sh_type);
Expand Down Expand Up @@ -184,7 +184,7 @@ static int elf_loadbinary(struct binary_s *binp)
elf_dumploadinfo(&loadinfo);
if (ret != 0)
{
bdbg("Failed to initialize for load of NXFLT program: %d\n", ret);
bdbg("Failed to initialize for load of ELF program: %d\n", ret);
goto errout;
}

Expand All @@ -194,7 +194,7 @@ static int elf_loadbinary(struct binary_s *binp)
elf_dumploadinfo(&loadinfo);
if (ret != 0)
{
bdbg("Failed to load NXFLT program binary: %d\n", ret);
bdbg("Failed to load ELF program binary: %d\n", ret);
goto errout_with_init;
}

Expand Down
2 changes: 1 addition & 1 deletion binfmt/libelf/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BINFMT_CSRCS += elf.c

# ELF library

BINFMT_CSRCS = libelf_init.c libelf_uninit.c libelf_load.c \
BINFMT_CSRCS += libelf_init.c libelf_uninit.c libelf_load.c \
libelf_unload.c libelf_verify.c libelf_read.c \
libelf_bind.c libelf_symbols.c

Expand Down
2 changes: 1 addition & 1 deletion binfmt/libelf/libelf_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)

/* Update sh_addr to point to copy in memory */

bvdbg("%d. %08x->%08x\n", i, (long)shdr->sh_addr, (long)dest);
shdr->sh_addr = (uintptr_t)dest;
bvdbg("%d. 0x%lx %s\n", (long)shdr->sh_addr, loadinfo->secstrings + shdr->sh_name);

/* Setup the memory pointer for the next time through the loop */

Expand Down
2 changes: 1 addition & 1 deletion binfmt/libnxflat/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BINFMT_CSRCS += nxflat.c

# NXFLAT library

BINFMT_CSRCS = libnxflat_init.c libnxflat_uninit.c libnxflat_load.c \
BINFMT_CSRCS += libnxflat_init.c libnxflat_uninit.c libnxflat_load.c \
libnxflat_unload.c libnxflat_verify.c libnxflat_read.c \
libnxflat_bind.c

Expand Down
4 changes: 2 additions & 2 deletions binfmt/nxflat.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static int nxflat_loadbinary(struct binary_s *binp)
nxflat_dumploadinfo(&loadinfo);
if (ret != 0)
{
bdbg("Failed to initialize for load of NXFLT program: %d\n", ret);
bdbg("Failed to initialize for load of NXFLAT program: %d\n", ret);
goto errout;
}

Expand All @@ -168,7 +168,7 @@ static int nxflat_loadbinary(struct binary_s *binp)
nxflat_dumploadinfo(&loadinfo);
if (ret != 0)
{
bdbg("Failed to load NXFLT program binary: %d\n", ret);
bdbg("Failed to load NXFLAT program binary: %d\n", ret);
goto errout_with_init;
}

Expand Down
12 changes: 6 additions & 6 deletions include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@

/* Definitions for Elf32_Sym::st_info */

#define ELF32_ST_BIND(i) ((i)>>4)
#define ELF32_ST_TYPE(i) ((i)&0xf)
#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
#define ELF32_ST_BIND(i) ((i) >> 4)
#define ELF32_ST_TYPE(i) ((i) & 0xf)
#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))

/* Figure 4-16: Symbol Binding, ELF32_ST_BIND */

Expand All @@ -190,9 +190,9 @@

/* Definitions for Elf32_Rel*::r_info */

#define ELF32_R_SYM(i) ((i)>>8)
#define ELF32_R_TYPE(i) ((unsigned char)(i))
#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((i) & 0xff)
#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))

/* Figure 5-2: Segment Types, p_type */

Expand Down
2 changes: 1 addition & 1 deletion tools/mkconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(int argc, char **argv, char **envp)
printf(" * configured (at present, NXFLAT is the only supported binary.\n");
printf(" * format).\n");
printf(" */\n\n");
printf("#if !defined(CONFIG_NXFLAT)\n");
printf("#if !defined(CONFIG_NXFLAT) && !defined(CONFIG_ELF)\n");
printf("# undef CONFIG_BINFMT_DISABLE\n");
printf("# define CONFIG_BINFMT_DISABLE 1\n");
printf("#endif\n\n");
Expand Down

0 comments on commit abf9559

Please sign in to comment.