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
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-10-24 18:46:12 +02:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-24 20:22:15 +02:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-10-24 18:46:12 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-07-08 17:46:46 +02:00
|
|
|
#define ELF_CLASS ELFCLASS32
|
|
|
|
|
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
|
|
|
|
2023-07-12 19:37:56 +02:00
|
|
|
/* Generic macro to abstract ELF32/ELF64 type/bind */
|
|
|
|
|
|
|
|
#define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
|
|
|
|
#define ELF_ST_BIND(a) ELF32_ST_BIND(a)
|
|
|
|
|
2012-10-24 20:22:15 +02:00
|
|
|
/* Definitions for Elf32_Rel*::r_info */
|
|
|
|
|
2023-07-08 17:46:46 +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
|
|
|
|
2023-07-08 17:46:46 +02:00
|
|
|
#define ELF_R_SYM(i) ELF32_R_SYM(i)
|
|
|
|
#define ELF_R_TYPE(i) ELF32_R_TYPE(i)
|
2012-10-24 20:22:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Figure 4.2: 32-Bit Data Types */
|
|
|
|
|
2023-07-08 17:46:46 +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
|
|
|
|
{
|
2023-07-08 17:46:46 +02:00
|
|
|
Elf32_Addr r_offset;
|
|
|
|
Elf32_Word r_info;
|
2012-10-24 20:22:15 +02:00
|
|
|
} Elf32_Rel;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2023-07-08 17:46:46 +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
|
|
|
|
{
|
2023-07-08 17:46:46 +02:00
|
|
|
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;
|
2012-10-24 20:22:15 +02:00
|
|
|
} Elf32_Phdr;
|
|
|
|
|
2021-11-17 16:28:21 +01:00
|
|
|
/* Figure 5-7: Note Information */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2023-07-08 17:46:46 +02:00
|
|
|
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. */
|
2021-11-17 16:28:21 +01:00
|
|
|
} Elf32_Nhdr;
|
|
|
|
|
2012-10-24 20:22:15 +02:00
|
|
|
/* Figure 5-9: Dynamic Structure */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2023-07-08 17:46:46 +02:00
|
|
|
Elf32_Sword d_tag;
|
2012-10-24 20:22:15 +02:00
|
|
|
union
|
|
|
|
{
|
2023-07-08 17:46:46 +02:00
|
|
|
Elf32_Word d_val;
|
|
|
|
Elf32_Addr d_ptr;
|
2012-10-24 20:22:15 +02:00
|
|
|
} d_un;
|
|
|
|
} Elf32_Dyn;
|
|
|
|
|
2023-07-08 17:46:46 +02:00
|
|
|
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;
|
2012-10-24 20:22:15 +02:00
|
|
|
|
2012-10-26 04:42:39 +02:00
|
|
|
#endif /* __INCLUDE_ELF32_H */
|