From 6cafdad8d539bbfbe2a516e46fe41549b8a6b68a Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 26 Oct 2012 02:42:39 +0000 Subject: Rename elf.h to elf32.h; Additional ELF loader changes git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5263 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/README.txt | 8 + apps/examples/elf/elf_main.c | 2 +- apps/examples/nxflat/nxflat_main.c | 2 +- nuttx/ChangeLog | 2 + nuttx/arch/arm/include/elf.h | 2 +- nuttx/arch/sim/src/up_elf.c | 2 +- nuttx/arch/x86/src/common/up_elf.c | 2 +- nuttx/binfmt/elf.c | 2 +- nuttx/binfmt/libelf/gnu-elf.ld | 138 ++++---------- nuttx/binfmt/libelf/libelf.h | 2 +- nuttx/binfmt/libelf/libelf_bind.c | 2 +- nuttx/binfmt/libelf/libelf_init.c | 2 +- nuttx/binfmt/libelf/libelf_load.c | 2 +- nuttx/binfmt/libelf/libelf_read.c | 2 +- nuttx/binfmt/libelf/libelf_symbols.c | 2 +- nuttx/include/elf.h | 352 ----------------------------------- nuttx/include/elf32.h | 352 +++++++++++++++++++++++++++++++++++ nuttx/include/nuttx/binfmt/elf.h | 2 +- 18 files changed, 414 insertions(+), 464 deletions(-) delete mode 100644 nuttx/include/elf.h create mode 100644 nuttx/include/elf32.h diff --git a/apps/examples/README.txt b/apps/examples/README.txt index fa97bd64e..95d49a3fb 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -344,6 +344,14 @@ examples/elf If you really want to do this, you can create a NuttX x86 buildroot toolchain and use that be build the ELF executables for the ROMFS file system. + 5. Linker scripts. You might also want to use a linker scripts to combine + sections better. An example linker script is at nuttx/binfmt/libelf/gnu-elf.ld. + That example might have to be tuned for your particular linker output to + position additional sections correctly. The GNU LD LDELFFLAGS then might + be: + + LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld + examples/ftpc ^^^^^^^^^^^^^ diff --git a/apps/examples/elf/elf_main.c b/apps/examples/elf/elf_main.c index 5699dd284..3a6eae9d9 100644 --- a/apps/examples/elf/elf_main.c +++ b/apps/examples/elf/elf_main.c @@ -174,7 +174,7 @@ int elf_main(int argc, char *argv[]) /* Create a ROM disk for the ROMFS filesystem */ message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR); - ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, romfs_img, + ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, (FAR uint8_t *)romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); if (ret < 0) { diff --git a/apps/examples/nxflat/nxflat_main.c b/apps/examples/nxflat/nxflat_main.c index 2c0030c60..638e960a0 100644 --- a/apps/examples/nxflat/nxflat_main.c +++ b/apps/examples/nxflat/nxflat_main.c @@ -167,7 +167,7 @@ int nxflat_main(int argc, char *argv[]) /* Create a ROM disk for the ROMFS filesystem */ message("Registering romdisk\n"); - ret = romdisk_register(0, romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); + ret = romdisk_register(0, (FAR uint8_t *)romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); if (ret < 0) { err("ERROR: romdisk_register failed: %d\n", ret); diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 2006fcc21..f1f048a35 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -3515,4 +3515,6 @@ include/nuttx/binfmt/. * arch/sim/src/up_elf.c and arch/x86/src/common/up_elf.c: Add for ELF modules. + * arch/arm/include/elf.h: Added ARM ELF header file. + * include/elf32.h: Renamed elf.h to elf32.h. diff --git a/nuttx/arch/arm/include/elf.h b/nuttx/arch/arm/include/elf.h index d85385380..21b2c1c2c 100644 --- a/nuttx/arch/arm/include/elf.h +++ b/nuttx/arch/arm/include/elf.h @@ -50,7 +50,7 @@ * e_ident[EI_DATA] = ELFDATA2LSB (little endian) or ELFDATA2MSB (big endian) */ -#if 0 /* Defined in include/elf.h */ +#if 0 /* Defined in include/elf32.h */ #define EM_ARM 40 #endif diff --git a/nuttx/arch/sim/src/up_elf.c b/nuttx/arch/sim/src/up_elf.c index ca3b642dc..26a8971a7 100644 --- a/nuttx/arch/sim/src/up_elf.c +++ b/nuttx/arch/sim/src/up_elf.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include diff --git a/nuttx/arch/x86/src/common/up_elf.c b/nuttx/arch/x86/src/common/up_elf.c index be166b480..da3f7b993 100644 --- a/nuttx/arch/x86/src/common/up_elf.c +++ b/nuttx/arch/x86/src/common/up_elf.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include diff --git a/nuttx/binfmt/elf.c b/nuttx/binfmt/elf.c index d9c3d0b9c..9a0ac1873 100644 --- a/nuttx/binfmt/elf.c +++ b/nuttx/binfmt/elf.c @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include diff --git a/nuttx/binfmt/libelf/gnu-elf.ld b/nuttx/binfmt/libelf/gnu-elf.ld index 703f36981..bdf82836b 100644 --- a/nuttx/binfmt/libelf/gnu-elf.ld +++ b/nuttx/binfmt/libelf/gnu-elf.ld @@ -1,7 +1,7 @@ /**************************************************************************** - * examples/elf/gnu-elf-gotoff.ld + * examples/elf/gnu-elf.ld * - * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -33,44 +33,11 @@ * ****************************************************************************/ -MEMORY -{ - ISPACE : ORIGIN = 0x0, LENGTH = 2097152 - DSPACE : ORIGIN = 0x0, LENGTH = 2097152 -} - -/**************************************************************************** - * The XFLAT program image is divided into two segments: - * - * (1) ISpace (Instruction Space). This is the segment that contains - * code (.text). Everything in the segment should be fetch-able - * machine PC instructions (jump, branch, call, etc.). - * (2) DSpace (Data Space). This is the segment that contains both - * read-write data (.data, .bss) as well as read-only data (.rodata). - * Everything in this segment should be access-able with machine - * PIC load and store instructions. - * - * Older versions of GCC (at least up to GCC 4.3.3), use GOT-relative - * addressing to access RO data. In that case, read-only data (.rodata) must - * reside in D-Space and this linker script should be used. - * - * Newer versions of GCC (at least as of GCC 4.6.3), use PC-relative - * addressing to access RO data. In that case, read-only data (.rodata) must - * reside in I-Space and this linker script should NOT be used with those - * newer tools. - * - ****************************************************************************/ - SECTIONS { .text 0x00000000 : { - /* ISpace is located at address 0. Every (unrelocated) ISpace - * address is an offset from the begining of this segment. - */ - - text_start = . ; - + _stext = . ; *(.text) *(.text.*) *(.gnu.warning) @@ -79,99 +46,72 @@ SECTIONS *(.glue_7t) *(.jcr) - /* C++ support: The .init and .fini sections contain XFLAT- - * specific logic to manage static constructors and destructors. + /* C++ support: The .init and .fini sections contain specific logic + * to manage static constructors and destructors. */ *(.gnu.linkonce.t.*) *(.init) *(.fini) - - /* This is special code area at the end of the normal - text section. It contains a small lookup table at - the start followed by the code pointed to by entries - in the lookup table. */ - - . = ALIGN (4) ; - PROVIDE(__ctbp = .); - *(.call_table_data) - *(.call_table_text) - _etext = . ; + } - } > ISPACE - - /* DSpace is also located at address 0. Every (unrelocated) DSpace - * address is an offset from the begining of this segment. - */ - - .data 0x00000000 : + .rodata : { - /* In this model, .rodata is access using PC-relative addressing - * and, hence, must also reside in the .text section. - */ - - __data_start = . ; + _srodata = . ; *(.rodata) *(.rodata1) *(.rodata.*) *(.gnu.linkonce.r*) + _erodata = . ; + } + .data : + { + _sdata = . ; *(.data) *(.data1) *(.data.*) *(.gnu.linkonce.d*) - *(.data1) - *(.eh_frame) - *(.gcc_except_table) - - *(.gnu.linkonce.s.*) - *(__libc_atexit) - *(__libc_subinit) - *(__libc_subfreeres) - *(.note.ABI-tag) - - /* C++ support. For each global and static local C++ object, - * GCC creates a small subroutine to construct the object. Pointers - * to these routines (not the routines themselves) are stored as - * simple, linear arrays in the .ctors section of the object file. - * Similarly, pointers to global/static destructor routines are - * stored in .dtors. - */ + _edata = . ; + } - *(.gnu.linkonce.d.*) + /* C++ support. For each global and static local C++ object, + * GCC creates a small subroutine to construct the object. Pointers + * to these routines (not the routines themselves) are stored as + * simple, linear arrays in the .ctors section of the object file. + * Similarly, pointers to global/static destructor routines are + * stored in .dtors. + */ - _ctors_start = . ; + .ctors : + { + _sctros = . ; *(.ctors) - _ctors_end = . ; - _dtors_start = . ; - *(.dtors) - _dtors_end = . ; + _edtors = . ; + } - _edata = . ; - edata = ALIGN( 0x10 ) ; - } > DSPACE + .ctors : + { + _sdtors = . ; + *(.dtors) + _edtors = . ; + } .bss : { - __bss_start = _edata ; - *(.dynsbss) - *(.sbss) - *(.sbss.*) - *(.scommon) - *(.dynbss) + _sbss = . ; *(.bss) *(.bss.*) - *(.bss*) + *(.sbss) + *(.sbss.*) *(.gnu.linkonce.b*) *(COMMON) - end = ALIGN( 0x10 ) ; - _end = ALIGN( 0x10 ) ; - } > DSPACE + _ebss = . ; + } - .got 0 : { *(.got.plt) *(.got) } - .junk 0 : { *(.rel*) *(.rela*) } /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } .stabstr 0 : { *(.stabstr) } .stab.excl 0 : { *(.stab.excl) } diff --git a/nuttx/binfmt/libelf/libelf.h b/nuttx/binfmt/libelf/libelf.h index 37a2ad872..0fb1362dc 100644 --- a/nuttx/binfmt/libelf/libelf.h +++ b/nuttx/binfmt/libelf/libelf.h @@ -43,7 +43,7 @@ #include #include -#include +#include #include diff --git a/nuttx/binfmt/libelf/libelf_bind.c b/nuttx/binfmt/libelf/libelf_bind.c index e398521cc..f41b5a0b6 100644 --- a/nuttx/binfmt/libelf/libelf_bind.c +++ b/nuttx/binfmt/libelf/libelf_bind.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include diff --git a/nuttx/binfmt/libelf/libelf_init.c b/nuttx/binfmt/libelf/libelf_init.c index a3a320b16..f2744eae7 100644 --- a/nuttx/binfmt/libelf/libelf_init.c +++ b/nuttx/binfmt/libelf/libelf_init.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include diff --git a/nuttx/binfmt/libelf/libelf_load.c b/nuttx/binfmt/libelf/libelf_load.c index 4a1a561c3..9378661e3 100644 --- a/nuttx/binfmt/libelf/libelf_load.c +++ b/nuttx/binfmt/libelf/libelf_load.c @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nuttx/binfmt/libelf/libelf_read.c b/nuttx/binfmt/libelf/libelf_read.c index 0b01cf096..da41212f2 100644 --- a/nuttx/binfmt/libelf/libelf_read.c +++ b/nuttx/binfmt/libelf/libelf_read.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include diff --git a/nuttx/binfmt/libelf/libelf_symbols.c b/nuttx/binfmt/libelf/libelf_symbols.c index 05f827963..123f9f77f 100644 --- a/nuttx/binfmt/libelf/libelf_symbols.c +++ b/nuttx/binfmt/libelf/libelf_symbols.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/nuttx/include/elf.h b/nuttx/include/elf.h deleted file mode 100644 index caf0b1876..000000000 --- a/nuttx/include/elf.h +++ /dev/null @@ -1,352 +0,0 @@ -/**************************************************************************** - * include/elf.h - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Reference: System V Application Binary Interface, Edition 4.1, March 18, - * 1997, The Santa Cruz Operation, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_ELF_H -#define __INCLUDE_ELF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Values for Elf32_Ehdr::e_type */ - -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* Relocatable file */ -#define ET_EXEC 2 /* Executable file */ -#define ET_DYN 3 /* Shared object file */ -#define ET_CORE 4 /* Core file */ -#define ET_LOPROC 0xff00 /* Processor-specific */ -#define ET_HIPROC 0xffff /* Processor-specific */ - -/* Values for Elf32_Ehdr::e_machine (most of this were not included in the - * original SCO document but have been gleaned from elsewhere). - */ - -#define EM_NONE 0 /* No machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola 68000 */ -#define EM_88K 5 /* Motorola 88000 */ -#define EM_486 6 /* Intel 486+ */ -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS R3000 Big-Endian */ -#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ -#define EM_PARISC 15 /* HPPA */ -#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* PowerPC64 */ -#define EM_ARM 40 /* ARM */ -#define EM_SH 42 /* SuperH */ -#define EM_SPARCV9 43 /* SPARC v9 64-bit */ -#define EM_IA_64 50 /* HP/Intel IA-64 */ -#define EM_X86_64 62 /* AMD x86-64 */ -#define EM_S390 22 /* IBM S/390 */ -#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ -#define EM_V850 87 /* NEC v850 */ -#define EM_M32R 88 /* Renesas M32R */ -#define EM_H8_300 46 -#define EM_ALPHA 0x9026 -#define EM_CYGNUS_V850 0x9080 -#define EM_CYGNUS_M32R 0x9041 -#define EM_S390_OLD 0xa390 -#define EM_FRV 0x5441 - -/* Values for Elf32_Ehdr::e_version */ - -#define EV_NONE 0 /* Invalid version */ -#define EV_CURRENT 1 /* The current version */ - -/* Ehe ELF identifier */ - -#define EI_MAG0 0 /* File identification */ -#define EI_MAG1 1 /* " " " " */ -#define EI_MAG2 2 /* " " " " */ -#define EI_MAG3 3 /* " " " " */ -#define EI_CLASS 4 /* File class */ -#define EI_DATA 5 /* Data encoding */ -#define EI_VERSION 6 /* File version */ -#define EI_PAD 7 /* Start of padding bytes */ -#define EI_NIDENT 16 /* Size of eident[] */ - -#define EI_MAGIC_SIZE 4 -#define EI_MAGIC {0x7f, 'E', 'L', 'F'} - -/* Values for EI_CLASS */ - -#define ELFCLASSNONE 0 /* Invalid class */ -#define ELFCLASS32 1 /* 32-bit objects */ -#define ELFCLASS64 2 /* 64-bit objects */ - -/* Values for EI_DATA */ - -#define ELFDATANONE 0 /* Invalid data encoding */ -#define ELFDATA2LSB 1 /* Least significant byte occupying the lowest address */ -#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */ - -/* Figure 4-7: Special Section Indexes */ - -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00 -#define SHN_LOPROC 0xff00 -#define SHN_HIPROC 0xff1f -#define SHN_ABS 0xfff1 -#define SHN_COMMON 0xfff2 -#define SHN_HIRESERVE 0xffff - -/* Figure 4-9: Section Types, sh_type */ - -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_LOPROC 0x70000000 -#define SHT_HIPROC 0x7fffffff -#define SHT_LOUSER 0x80000000 -#define SHT_HIUSER 0xffffffff - -/* Figure 4-11: Section Attribute Flags, sh_flags */ - -#define SHF_WRITE 1 -#define SHF_ALLOC 2 -#define SHF_EXECINSTR 4 -#define SHF_MASKPROC 0xf0000000 - -/* 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)) - -/* Figure 4-16: Symbol Binding, ELF32_ST_BIND */ - -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 -#define STB_LOPROC 13 -#define STB_HIPROC 15 - -/* Figure 4-17: Symbol Types, ELF32_ST_TYPE */ - -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 -#define STT_LOPROC 13 -#define STT_HIPROC 15 - -/* Definitions for Elf32_Rel*::r_info */ - -#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 */ - -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_LOPROC 0x70000000 -#define PT_HIPROC 0x7fffffff - -/* Figure 5-3: Segment Flag Bits, p_flags */ - -#define PF_X 1 /* Execute */ -#define PF_W 2 /* Write */ -#define PF_R 4 /* Read */ -#define PF_MASKPROC 0xf0000000 /* Unspecified */ - -/* Figure 5-10: Dynamic Array Tags, d_tag */ - -#define DT_NULL 0 /* d_un=ignored */ -#define DT_NEEDED 1 /* d_un=d_val */ -#define DT_PLTRELSZ 2 /* d_un=d_val */ -#define DT_PLTGOT 3 /* d_un=d_ptr */ -#define DT_HASH 4 /* d_un=d_ptr */ -#define DT_STRTAB 5 /* d_un=d_ptr */ -#define DT_SYMTAB 6 /* d_un=d_ptr */ -#define DT_RELA 7 /* d_un=d_ptr */ -#define DT_RELASZ 8 /* d_un=d_val */ -#define DT_RELAENT 9 /* d_un=d_val */ -#define DT_STRSZ 10 /* d_un=d_val */ -#define DT_SYMENT 11 /* d_un=d_val */ -#define DT_INIT 12 /* d_un=d_ptr */ -#define DT_FINI 13 /* d_un=d_ptr */ -#define DT_SONAME 14 /* d_un=d_val */ -#define DT_RPATH 15 /* d_un=d_val */ -#define DT_SYMBOLIC 16 /* d_un=ignored */ -#define DT_REL 17 /* d_un=d_ptr */ -#define DT_RELSZ 18 /* d_un=d_val */ -#define DT_RELENT 19 /* d_un=d_val */ -#define DT_PLTREL 20 /* d_un=d_val */ -#define DT_DEBUG 21 /* d_un=d_ptr */ -#define DT_TEXTREL 22 /* d_un=ignored */ -#define DT_JMPREL 23 /* d_un=d_ptr */ -#define DT_BINDNOW 24 /* d_un=ignored */ -#define DT_LOPROC 0x70000000 /* d_un=unspecified */ -#define DT_HIPROC 0x7fffffff /* d_un= unspecified */ - -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - -/* Figure 4.2: 32-Bit Data Types */ - -typedef uint32_t Elf32_Addr; /* Unsigned program address */ -typedef uint16_t Elf32_Half; /* Unsigned medium integer */ -typedef uint32_t Elf32_Off; /* Unsigned file offset */ -typedef int32_t Elf32_Sword; /* Signed large integer */ -typedef uint32_t Elf32_Word; /* Unsigned large integer */ - -/* Figure 4-3: ELF Header */ - -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -/* Figure 4-8: Section Header */ - -typedef struct -{ - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -/* Figure 4-15: Symbol Table Entry */ - -typedef struct -{ - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Half st_shndx; -} Elf32_Sym; - -/* Figure 4-19: Relocation Entries */ - -typedef struct -{ - Elf32_Addr r_offset; - Elf32_Word r_info; -} Elf32_Rel; - -typedef struct -{ - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; -} Elf32_Rela; - -/* Figure 5-1: Program Header */ - -typedef struct -{ - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -/* Figure 5-9: Dynamic Structure */ - -typedef struct -{ - Elf32_Sword d_tag; - union - { - Elf32_Word d_val; - Elf32_Addr d_ptr; - } d_un; -} Elf32_Dyn; - -//extern Elf32_Dyn _DYNAMIC[] ; - -#endif /* __INCLUDE_ELF_H */ diff --git a/nuttx/include/elf32.h b/nuttx/include/elf32.h new file mode 100644 index 000000000..e16ae0091 --- /dev/null +++ b/nuttx/include/elf32.h @@ -0,0 +1,352 @@ +/**************************************************************************** + * include/elf32.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Reference: System V Application Binary Interface, Edition 4.1, March 18, + * 1997, The Santa Cruz Operation, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ELF32_H +#define __INCLUDE_ELF32_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Values for Elf32_Ehdr::e_type */ + +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Relocatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ +#define ET_LOPROC 0xff00 /* Processor-specific */ +#define ET_HIPROC 0xffff /* Processor-specific */ + +/* Values for Elf32_Ehdr::e_machine (most of this were not included in the + * original SCO document but have been gleaned from elsewhere). + */ + +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel 486+ */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_PARISC 15 /* HPPA */ +#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ +#define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* PowerPC64 */ +#define EM_ARM 40 /* ARM */ +#define EM_SH 42 /* SuperH */ +#define EM_SPARCV9 43 /* SPARC v9 64-bit */ +#define EM_IA_64 50 /* HP/Intel IA-64 */ +#define EM_X86_64 62 /* AMD x86-64 */ +#define EM_S390 22 /* IBM S/390 */ +#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ +#define EM_V850 87 /* NEC v850 */ +#define EM_M32R 88 /* Renesas M32R */ +#define EM_H8_300 46 +#define EM_ALPHA 0x9026 +#define EM_CYGNUS_V850 0x9080 +#define EM_CYGNUS_M32R 0x9041 +#define EM_S390_OLD 0xa390 +#define EM_FRV 0x5441 + +/* Values for Elf32_Ehdr::e_version */ + +#define EV_NONE 0 /* Invalid version */ +#define EV_CURRENT 1 /* The current version */ + +/* Ehe ELF identifier */ + +#define EI_MAG0 0 /* File identification */ +#define EI_MAG1 1 /* " " " " */ +#define EI_MAG2 2 /* " " " " */ +#define EI_MAG3 3 /* " " " " */ +#define EI_CLASS 4 /* File class */ +#define EI_DATA 5 /* Data encoding */ +#define EI_VERSION 6 /* File version */ +#define EI_PAD 7 /* Start of padding bytes */ +#define EI_NIDENT 16 /* Size of eident[] */ + +#define EI_MAGIC_SIZE 4 +#define EI_MAGIC {0x7f, 'E', 'L', 'F'} + +/* Values for EI_CLASS */ + +#define ELFCLASSNONE 0 /* Invalid class */ +#define ELFCLASS32 1 /* 32-bit objects */ +#define ELFCLASS64 2 /* 64-bit objects */ + +/* Values for EI_DATA */ + +#define ELFDATANONE 0 /* Invalid data encoding */ +#define ELFDATA2LSB 1 /* Least significant byte occupying the lowest address */ +#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */ + +/* Figure 4-7: Special Section Indexes */ + +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + +/* Figure 4-9: Section Types, sh_type */ + +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +/* Figure 4-11: Section Attribute Flags, sh_flags */ + +#define SHF_WRITE 1 +#define SHF_ALLOC 2 +#define SHF_EXECINSTR 4 +#define SHF_MASKPROC 0xf0000000 + +/* 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)) + +/* Figure 4-16: Symbol Binding, ELF32_ST_BIND */ + +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +/* Figure 4-17: Symbol Types, ELF32_ST_TYPE */ + +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + +/* Definitions for Elf32_Rel*::r_info */ + +#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 */ + +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff + +/* Figure 5-3: Segment Flag Bits, p_flags */ + +#define PF_X 1 /* Execute */ +#define PF_W 2 /* Write */ +#define PF_R 4 /* Read */ +#define PF_MASKPROC 0xf0000000 /* Unspecified */ + +/* Figure 5-10: Dynamic Array Tags, d_tag */ + +#define DT_NULL 0 /* d_un=ignored */ +#define DT_NEEDED 1 /* d_un=d_val */ +#define DT_PLTRELSZ 2 /* d_un=d_val */ +#define DT_PLTGOT 3 /* d_un=d_ptr */ +#define DT_HASH 4 /* d_un=d_ptr */ +#define DT_STRTAB 5 /* d_un=d_ptr */ +#define DT_SYMTAB 6 /* d_un=d_ptr */ +#define DT_RELA 7 /* d_un=d_ptr */ +#define DT_RELASZ 8 /* d_un=d_val */ +#define DT_RELAENT 9 /* d_un=d_val */ +#define DT_STRSZ 10 /* d_un=d_val */ +#define DT_SYMENT 11 /* d_un=d_val */ +#define DT_INIT 12 /* d_un=d_ptr */ +#define DT_FINI 13 /* d_un=d_ptr */ +#define DT_SONAME 14 /* d_un=d_val */ +#define DT_RPATH 15 /* d_un=d_val */ +#define DT_SYMBOLIC 16 /* d_un=ignored */ +#define DT_REL 17 /* d_un=d_ptr */ +#define DT_RELSZ 18 /* d_un=d_val */ +#define DT_RELENT 19 /* d_un=d_val */ +#define DT_PLTREL 20 /* d_un=d_val */ +#define DT_DEBUG 21 /* d_un=d_ptr */ +#define DT_TEXTREL 22 /* d_un=ignored */ +#define DT_JMPREL 23 /* d_un=d_ptr */ +#define DT_BINDNOW 24 /* d_un=ignored */ +#define DT_LOPROC 0x70000000 /* d_un=unspecified */ +#define DT_HIPROC 0x7fffffff /* d_un= unspecified */ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Figure 4.2: 32-Bit Data Types */ + +typedef uint32_t Elf32_Addr; /* Unsigned program address */ +typedef uint16_t Elf32_Half; /* Unsigned medium integer */ +typedef uint32_t Elf32_Off; /* Unsigned file offset */ +typedef int32_t Elf32_Sword; /* Signed large integer */ +typedef uint32_t Elf32_Word; /* Unsigned large integer */ + +/* Figure 4-3: ELF Header */ + +typedef struct +{ + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; +} Elf32_Ehdr; + +/* Figure 4-8: Section Header */ + +typedef struct +{ + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; +} Elf32_Shdr; + +/* Figure 4-15: Symbol Table Entry */ + +typedef struct +{ + Elf32_Word st_name; + Elf32_Addr st_value; + Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf32_Half st_shndx; +} Elf32_Sym; + +/* Figure 4-19: Relocation Entries */ + +typedef struct +{ + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct +{ + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +/* Figure 5-1: Program Header */ + +typedef struct +{ + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +/* Figure 5-9: Dynamic Structure */ + +typedef struct +{ + Elf32_Sword d_tag; + union + { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + +//extern Elf32_Dyn _DYNAMIC[] ; + +#endif /* __INCLUDE_ELF32_H */ diff --git a/nuttx/include/nuttx/binfmt/elf.h b/nuttx/include/nuttx/binfmt/elf.h index 6b13c1087..aa04adaf2 100644 --- a/nuttx/include/nuttx/binfmt/elf.h +++ b/nuttx/include/nuttx/binfmt/elf.h @@ -45,7 +45,7 @@ #include #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions -- cgit v1.2.3