diff --git a/arch/arm/include/elf.h b/arch/arm/include/elf.h index 510fcf3b8d95c..7a1f64e778a7c 100644 --- a/arch/arm/include/elf.h +++ b/arch/arm/include/elf.h @@ -38,13 +38,6 @@ */ #define EM_ARCH EM_ARM -#define ELF_CLASS ELFCLASS32 - -#ifdef CONFIG_ENDIAN_BIG -# define ELF_DATA ELFDATA2MSB -#else -# define ELF_DATA ELFDATA2LSB -#endif /* Table 4-2, ARM-specific e_flags */ @@ -211,6 +204,10 @@ #define R_ARM_THM_TLS_DESCSEQ16 129 /* Thumb16 */ #define R_ARM_THM_TLS_DESCSEQ32 130 /* Thumb32 */ +/* Processor specific values for the Phdr p_type field. */ + +#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */ + /* 5.2.1 Platform architecture compatibility data */ #define PT_ARM_ARCHEXT_FMTMSK 0xff000000 diff --git a/arch/sim/include/elf.h b/arch/sim/include/elf.h index 800894a1434ae..68ddd55c7f8b4 100644 --- a/arch/sim/include/elf.h +++ b/arch/sim/include/elf.h @@ -28,25 +28,14 @@ /* 4.3.1 ELF Identification. Should have: * * e_machine = EM_386 - * e_ident[EI_CLASS] = ELFCLASS32 - * e_ident[EI_DATA] = ELFDATA2LSB (little endian) or - * ELFDATA2MSB (big endian) */ #ifdef CONFIG_SIM_M32 -# define EM_ARCH EM_386 -# define ELF_CLASS ELFCLASS32 +# define EM_ARCH EM_386 #else -# define EM_ARCH EM_X86_64 -# define ELF_CLASS ELFCLASS32 +# define EM_ARCH EM_X86_64 #endif -#ifdef CONFIG_ENDIAN_BIG -# define ELF_DATA ELFDATA2MSB -#else -# define ELF_DATA ELFDATA2LSB -#endif - -#define EF_FLAG 0 +#define EF_FLAG 0 #endif /* __ARCH_SIM_INCLUDE_ELF_H */ diff --git a/include/elf.h b/include/elf.h index 8d2fc0abe3bc7..ca982c2b18425 100644 --- a/include/elf.h +++ b/include/elf.h @@ -215,15 +215,11 @@ #define PT_SHLIB 5 #define PT_PHDR 6 -/* Processor specific values for the Phdr p_type field. */ - -#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */ - /* GCC specific */ -#define PT_GNU_EH_FRAME 0x6474e550 /* GCC exception handler frame */ -#define PT_GNU_STACK 0x6474e551 /* Stack executability */ -#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ +#define PT_GNU_EH_FRAME 0x6474e550 /* GCC exception handler frame */ +#define PT_GNU_STACK 0x6474e551 /* Stack executability */ +#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ #define PT_LOPROC 0x70000000 #define PT_HIPROC 0x7fffffff @@ -366,4 +362,10 @@ #define NT_VERSION 1 /* Contains a version string. */ +#ifdef CONFIG_ENDIAN_BIG +# define ELF_DATA ELFDATA2MSB +#else +# define ELF_DATA ELFDATA2LSB +#endif + #endif /* __INCLUDE_ELF_H */ diff --git a/include/elf32.h b/include/elf32.h index ef4d511d049b6..1bfcb920e066c 100644 --- a/include/elf32.h +++ b/include/elf32.h @@ -34,17 +34,20 @@ * Pre-processor Definitions ****************************************************************************/ +#define ELF_CLASS ELFCLASS32 + #define ELF32_ST_BIND(i) ((i) >> 4) #define ELF32_ST_TYPE(i) ((i) & 0xf) #define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf)) /* 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)) +#define ELF32_R_SYM(i) ((i) >> 8) +#define ELF32_R_TYPE(i) ((i) & 0xff) +#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff)) -#define ELF_R_SYM(i) ELF32_R_SYM(i) +#define ELF_R_SYM(i) ELF32_R_SYM(i) +#define ELF_R_TYPE(i) ELF32_R_TYPE(i) /**************************************************************************** * Public Type Definitions @@ -52,11 +55,11 @@ /* 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 */ +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 */ @@ -110,60 +113,62 @@ typedef struct typedef struct { - Elf32_Addr r_offset; - Elf32_Word r_info; + 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_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_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-7: Note Information */ typedef struct { - Elf32_Word n_namesz; /* Length of the note's name. */ - Elf32_Word n_descsz; /* Length of the note's descriptor. */ - Elf32_Word n_type; /* Type of the note. */ + Elf32_Word n_namesz; /* Length of the note's name. */ + Elf32_Word n_descsz; /* Length of the note's descriptor. */ + Elf32_Word n_type; /* Type of the note. */ } Elf32_Nhdr; /* Figure 5-9: Dynamic Structure */ typedef struct { - Elf32_Sword d_tag; + Elf32_Sword d_tag; union { - Elf32_Word d_val; - Elf32_Addr d_ptr; + Elf32_Word d_val; + Elf32_Addr d_ptr; } d_un; } Elf32_Dyn; -typedef Elf32_Addr Elf_Addr; -typedef Elf32_Ehdr Elf_Ehdr; -typedef Elf32_Rel Elf_Rel; -typedef Elf32_Rela Elf_Rela; -typedef Elf32_Nhdr Elf_Nhdr; -typedef Elf32_Phdr Elf_Phdr; -typedef Elf32_Sym Elf_Sym; -typedef Elf32_Shdr Elf_Shdr; -typedef Elf32_Word Elf_Word; +typedef Elf32_Addr Elf_Addr; +typedef Elf32_Ehdr Elf_Ehdr; +typedef Elf32_Rel Elf_Rel; +typedef Elf32_Rela Elf_Rela; +typedef Elf32_Nhdr Elf_Nhdr; +typedef Elf32_Phdr Elf_Phdr; +typedef Elf32_Sym Elf_Sym; +typedef Elf32_Shdr Elf_Shdr; +typedef Elf32_Off Elf_Off; +typedef Elf32_Word Elf_Word; +typedef Elf32_Dyn Elf_Dyn; #endif /* __INCLUDE_ELF32_H */ diff --git a/include/elf64.h b/include/elf64.h index 1f6da826c7a61..a8fb3b8abc0c3 100644 --- a/include/elf64.h +++ b/include/elf64.h @@ -34,6 +34,8 @@ * Pre-processor Definitions ****************************************************************************/ +#define ELF_CLASS ELFCLASS64 + /* See ELF-64 Object File Format: Version 1.5 Draft 2 */ /* Definitions for Elf64_Rel*::r_info */ @@ -43,6 +45,7 @@ #define ELF64_R_INFO(s,t) (((s)<< 32) + ((t) & 0xffffffffL)) #define ELF_R_SYM(i) ELF64_R_SYM(i) +#define ELF_R_TYPE(i) ELF64_R_TYPE(i) /**************************************************************************** * Public Type Definitions @@ -50,13 +53,13 @@ /* Table 1: ELF-64 Data Types */ -typedef uint64_t Elf64_Addr; /* Unsigned program address */ -typedef uint64_t Elf64_Off; /* Unsigned file offset */ -typedef uint16_t Elf64_Half; /* Unsigned medium integer */ -typedef uint32_t Elf64_Word; /* Unsigned long integer */ -typedef int32_t Elf64_Sword; /* Signed integer */ -typedef uint64_t Elf64_Xword; /* Unsigned long integer */ -typedef int64_t Elf64_Sxword; /* Signed large integer */ +typedef uint64_t Elf64_Addr; /* Unsigned program address */ +typedef uint64_t Elf64_Off; /* Unsigned file offset */ +typedef uint16_t Elf64_Half; /* Unsigned medium integer */ +typedef uint32_t Elf64_Word; /* Unsigned long integer */ +typedef int32_t Elf64_Sword; /* Signed integer */ +typedef uint64_t Elf64_Xword; /* Unsigned long integer */ +typedef int64_t Elf64_Sxword; /* Signed large integer */ /* Figure 2: ELF-64 Header */ @@ -125,23 +128,23 @@ typedef struct typedef struct { - Elf64_Word p_type; /* Type of segment */ - Elf64_Word p_flags; /* Segment attributes */ - Elf64_Off p_offset; /* Offset in file */ - Elf64_Addr p_vaddr; /* Virtual address in memory */ - Elf64_Addr p_paddr; /* Reserved */ - Elf64_Word p_filesz; /* Size of segment in file */ - Elf64_Word p_memsz; /* Size of segment in memory */ - Elf64_Word p_align; /* Alignment of segment */ + Elf64_Word p_type; /* Type of segment */ + Elf64_Word p_flags; /* Segment attributes */ + Elf64_Off p_offset; /* Offset in file */ + Elf64_Addr p_vaddr; /* Virtual address in memory */ + Elf64_Addr p_paddr; /* Reserved */ + Elf64_Word p_filesz; /* Size of segment in file */ + Elf64_Word p_memsz; /* Size of segment in memory */ + Elf64_Word p_align; /* Alignment of segment */ } Elf64_Phdr; /* Figure 7. Format of a Note Section */ typedef struct { - Elf64_Word n_namesz; /* Length of the note's name. */ - Elf64_Word n_descsz; /* Length of the note's descriptor. */ - Elf64_Word n_type; /* Type of the note. */ + Elf64_Word n_namesz; /* Length of the note's name. */ + Elf64_Word n_descsz; /* Length of the note's descriptor. */ + Elf64_Word n_type; /* Type of the note. */ } Elf64_Nhdr; /* Figure 8: Dynamic Table Structure */ @@ -156,14 +159,16 @@ typedef struct } d_un; } Elf64_Dyn; -typedef Elf64_Addr Elf_Addr; -typedef Elf64_Ehdr Elf_Ehdr; -typedef Elf64_Rel Elf_Rel; -typedef Elf64_Rela Elf_Rela; -typedef Elf64_Nhdr Elf_Nhdr; -typedef Elf64_Phdr Elf_Phdr; -typedef Elf64_Sym Elf_Sym; -typedef Elf64_Shdr Elf_Shdr; -typedef Elf64_Word Elf_Word; +typedef Elf64_Addr Elf_Addr; +typedef Elf64_Ehdr Elf_Ehdr; +typedef Elf64_Rel Elf_Rel; +typedef Elf64_Rela Elf_Rela; +typedef Elf64_Nhdr Elf_Nhdr; +typedef Elf64_Phdr Elf_Phdr; +typedef Elf64_Sym Elf_Sym; +typedef Elf64_Shdr Elf_Shdr; +typedef Elf64_Off Elf_Off; +typedef Elf64_Word Elf_Word; +typedef Elf64_Dyn Elf_Dyn; #endif /* __INCLUDE_ELF64_H */ diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h index 15308b128b5f8..505972d45ec5d 100644 --- a/include/nuttx/lib/modlib.h +++ b/include/nuttx/lib/modlib.h @@ -87,14 +87,6 @@ * Public Types ****************************************************************************/ -#ifdef CONFIG_LIBC_ARCH_ELF_64BIT -typedef Elf64_Off Elf_Off; -typedef Elf64_Dyn Elf_Dyn; -#else -typedef Elf32_Off Elf_Off; -typedef Elf32_Dyn Elf_Dyn; -#endif - /* This is the type of the function that is called to uninitialize the * the loaded module. This may mean, for example, un-registering a device * driver. If the module is successfully uninitialized, its memory will be @@ -208,11 +200,10 @@ struct mod_loadinfo_s Elf_Ehdr ehdr; /* Buffered module file header */ FAR Elf_Phdr *phdr; /* Buffered module program headers */ FAR Elf_Shdr *shdr; /* Buffered module section headers */ - FAR void *exported; /* Module exports */ + FAR void *exported; /* Module exports */ uint8_t *iobuffer; /* File I/O buffer */ - uintptr_t datasec; /* ET_DYN - data area start from Phdr */ - uintptr_t segpad; /* Padding between text and data */ - + uintptr_t datasec; /* ET_DYN - data area start from Phdr */ + uintptr_t segpad; /* Padding between text and data */ uint16_t symtabidx; /* Symbol table section index */ uint16_t strtabidx; /* String table section index */ uint16_t dsymtabidx; /* Dynamic symbol table section index */ diff --git a/libs/libc/machine/risc-v/arch_elf.c b/libs/libc/machine/risc-v/arch_elf.c index ef7324ecf8bb4..96b5e1a4a1586 100644 --- a/libs/libc/machine/risc-v/arch_elf.c +++ b/libs/libc/machine/risc-v/arch_elf.c @@ -44,13 +44,9 @@ /* ELF32 and ELF64 definitions */ #ifdef CONFIG_LIBC_ARCH_ELF_64BIT -# define ARCH_ELF_TYP_STR "64" -# define ARCH_ELF_CLASS ELFCLASS64 -# define ARCH_ELF_RELTYPE ELF64_R_TYPE +# define ARCH_ELF_TYP_STR "64" #else /* !CONFIG_LIBC_ARCH_ELF_64BIT */ -# define ARCH_ELF_TYP_STR "32" -# define ARCH_ELF_CLASS ELFCLASS32 -# define ARCH_ELF_RELTYPE ELF32_R_TYPE +# define ARCH_ELF_TYP_STR "32" #endif /* CONFIG_LIBC_ARCH_ELF_64BIT */ /**************************************************************************** @@ -214,7 +210,7 @@ bool up_checkarch(const Elf_Ehdr *ehdr) /* Make sure that current objects are supported */ - if (ehdr->e_ident[EI_CLASS] != ARCH_ELF_CLASS) + if (ehdr->e_ident[EI_CLASS] != ELF_CLASS) { berr("ERROR: Need " ARCH_ELF_TYP_STR "-bit " "objects: e_ident[EI_CLASS]=%02x\n", @@ -284,7 +280,7 @@ int up_relocateadd(const Elf_Rela *rel, const Elf_Sym *sym, /* All relocations depend upon having valid symbol information */ - relotype = ARCH_ELF_RELTYPE(rel->r_info); + relotype = ELF_R_TYPE(rel->r_info); if (relotype == R_RISCV_RELAX) { @@ -585,7 +581,7 @@ int up_relocateadd(const Elf_Rela *rel, const Elf_Sym *sym, break; default: berr("ERROR: Unsupported relocation: %ld\n", - ARCH_ELF_RELTYPE(rel->r_info)); + ELF_R_TYPE(rel->r_info)); PANIC(); return -EINVAL; }