2012-10-24 18:46:12 +02:00
|
|
|
/****************************************************************************
|
2012-10-26 04:42:39 +02:00
|
|
|
* include/elf32.h
|
2012-10-24 18:46:12 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
2012-10-24 20:22:15 +02:00
|
|
|
* Reference: System V Application Binary Interface, Edition 4.1, March 18,
|
|
|
|
* 1997, The Santa Cruz Operation, Inc.
|
|
|
|
*
|
2012-10-24 18:46:12 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-10-26 04:42:39 +02:00
|
|
|
#ifndef __INCLUDE_ELF32_H
|
|
|
|
#define __INCLUDE_ELF32_H
|
2012-10-24 18:46:12 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2012-10-24 20:22:15 +02:00
|
|
|
#include <stdint.h>
|
2020-02-08 00:10:23 +01:00
|
|
|
#include <elf.h>
|
2012-10-24 20:22:15 +02:00
|
|
|
|
2012-10-24 18:46:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-10-26 00:10:56 +02:00
|
|
|
#define ELF32_ST_BIND(i) ((i) >> 4)
|
|
|
|
#define ELF32_ST_TYPE(i) ((i) & 0xf)
|
|
|
|
#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))
|
2012-10-24 20:22:15 +02:00
|
|
|
|
|
|
|
/* Definitions for Elf32_Rel*::r_info */
|
|
|
|
|
2012-10-26 00:10:56 +02:00
|
|
|
#define ELF32_R_SYM(i) ((i) >> 8)
|
|
|
|
#define ELF32_R_TYPE(i) ((i) & 0xff)
|
|
|
|
#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))
|
2012-10-24 20:22:15 +02:00
|
|
|
|
2020-02-08 00:10:23 +01:00
|
|
|
#define ELF_R_SYM(i) ELF32_R_SYM(i)
|
2012-10-24 20:22:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Figure 4.2: 32-Bit Data Types */
|
|
|
|
|
2012-10-25 18:18:20 +02:00
|
|
|
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 */
|
2012-10-24 20:22:15 +02:00
|
|
|
|
|
|
|
/* Figure 4-3: ELF Header */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned char e_ident[EI_NIDENT];
|
2012-10-25 18:18:20 +02:00
|
|
|
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;
|
2012-10-24 20:22:15 +02:00
|
|
|
} Elf32_Ehdr;
|
|
|
|
|
|
|
|
/* Figure 4-8: Section Header */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-25 18:18:20 +02:00
|
|
|
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;
|
2012-10-24 20:22:15 +02:00
|
|
|
} Elf32_Shdr;
|
|
|
|
|
|
|
|
/* Figure 4-15: Symbol Table Entry */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-25 18:18:20 +02:00
|
|
|
Elf32_Word st_name;
|
|
|
|
Elf32_Addr st_value;
|
|
|
|
Elf32_Word st_size;
|
2012-10-24 20:22:15 +02:00
|
|
|
unsigned char st_info;
|
|
|
|
unsigned char st_other;
|
2012-10-25 18:18:20 +02:00
|
|
|
Elf32_Half st_shndx;
|
2012-10-24 20:22:15 +02:00
|
|
|
} Elf32_Sym;
|
|
|
|
|
|
|
|
/* Figure 4-19: Relocation Entries */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-25 18:18:20 +02:00
|
|
|
Elf32_Addr r_offset;
|
|
|
|
Elf32_Word r_info;
|
2012-10-24 20:22:15 +02:00
|
|
|
} Elf32_Rel;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-25 18:18:20 +02:00
|
|
|
Elf32_Addr r_offset;
|
|
|
|
Elf32_Word r_info;
|
|
|
|
Elf32_Sword r_addend;
|
2012-10-24 20:22:15 +02:00
|
|
|
} 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;
|
|
|
|
|
2020-02-08 00:10:23 +01:00
|
|
|
typedef Elf32_Ehdr Elf_Ehdr;
|
|
|
|
typedef Elf32_Rel Elf_Rel;
|
|
|
|
typedef Elf32_Rela Elf_Rela;
|
|
|
|
typedef Elf32_Sym Elf_Sym;
|
|
|
|
typedef Elf32_Shdr Elf_Shdr;
|
|
|
|
typedef Elf32_Word Elf_Word;
|
2012-10-24 20:22:15 +02:00
|
|
|
|
2012-10-26 04:42:39 +02:00
|
|
|
#endif /* __INCLUDE_ELF32_H */
|