123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- #ifndef _ELF_H
- #define _ELF_H
- #ifndef __ASSEMBLER__
- #include "compiler.h"
- typedef uint32_t Elf32_Addr;
- typedef uint32_t Elf32_Off;
- typedef int32_t Elf32_Sword;
- typedef uint32_t Elf32_Word;
- typedef uint16_t Elf32_Half;
- typedef uint64_t Elf64_Addr;
- typedef uint16_t Elf64_Half;
- typedef int16_t Elf64_SHalf;
- typedef uint64_t Elf64_Off;
- typedef int32_t Elf64_Sword;
- typedef uint32_t Elf64_Word;
- typedef uint64_t Elf64_Xword;
- typedef int64_t Elf64_Sxword;
- #define EI_MAG0 0
- #define EI_MAG1 1
- #define EI_MAG2 2
- #define EI_MAG3 3
- #define EI_CLASS 4
- #define EI_DATA 5
- #define EI_VERSION 6
- #define EI_OSABI 7
- #define EI_ABIVERSION 8
- #define EI_PAD 9
- #define EI_NIDENT 16
- #define ELFMAG0 0x7f
- #define ELFMAG1 'E'
- #define ELFMAG2 'L'
- #define ELFMAG3 'F'
- #define ELFMAG "\177ELF"
- #define SELFMAG 4
- #define ELFCLASSNONE 0
- #define ELFCLASS32 1
- #define ELFCLASS64 2
- #define ELFCLASSNUM 3
- #define ELFDATANONE 0
- #define ELFDATA2LSB 1
- #define ELFDATA2MSB 2
- #define ELFDATANUM 3
- #define ELFOSABI_NONE 0
- #define ELFOSABI_HPUX 1
- #define ELFOSABI_NETBSD 2
- #define ELFOSABI_LINUX 3
- #define ELFOSABI_SOLARIS 6
- #define ELFOSABI_AIX 7
- #define ELFOSABI_IRIX 8
- #define ELFOSABI_FREEBSD 9
- #define ELFOSABI_TRU64 10
- #define ELFOSABI_MODESTO 11
- #define ELFOSABI_OPENBSD 12
- #define ELFABIVERSION 0
- #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
- (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
- (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
- (ehdr).e_ident[EI_MAG3] == ELFMAG3)
- typedef struct elfhdr{
- 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;
- #define ET_NONE 0
- #define ET_REL 1
- #define ET_EXEC 2
- #define ET_DYN 3
- #define ET_CORE 4
- #define ET_NUM 5
- #define ET_LOOS 0xfe00
- #define ET_HIOS 0xfeff
- #define ET_LOPROC 0xff00
- #define ET_HIPROC 0xffff
- #define EM_NONE 0
- #define EM_M32 1
- #define EM_SPARC 2
- #define EM_386 3
- #define EM_68K 4
- #define EM_88K 5
- #if 0
- #define EM_486 6
- #endif
- #define EM_860 7
- #define EM_MIPS 8
- #define EM_S370 9
- #define EM_MIPS_RS4_BE 10
- #if 0
- #define EM_SPARC64 11
- #endif
- #define EM_PARISC 15
- #define EM_VPP500 17
- #define EM_SPARC32PLUS 18
- #define EM_960 19
- #define EM_PPC 20
- #define EM_PPC64 21
- #define EM_S390 22
- #define EM_V800 36
- #define EM_FR20 37
- #define EM_RH32 38
- #define EM_RCE 39
- #define EM_ARM 40
- #define EM_ALPHA 41
- #define EM_SH 42
- #define EM_SPARCV9 43
- #define EM_TRICORE 44
- #define EM_ARC 45
- #define EM_H8_300 46
- #define EM_H8_300H 47
- #define EM_H8S 48
- #define EM_H8_500 49
- #define EM_IA_64 50
- #define EM_MIPS_X 51
- #define EM_COLDFIRE 52
- #define EM_68HC12 53
- #define EM_MMA 54
- #define EM_PCP 55
- #define EM_NCPU 56
- #define EM_NDR1 57
- #define EM_STARCORE 58
- #define EM_ME16 59
- #define EM_ST100 60
- #define EM_TINYJ 61
- #define EM_X86_64 62
- #define EM_PDSP 63
- #define EM_FX66 66
- #define EM_ST9PLUS 67
- #define EM_ST7 68
- #define EM_68HC16 69
- #define EM_68HC11 70
- #define EM_68HC08 71
- #define EM_68HC05 72
- #define EM_SVX 73
- #define EM_ST19 74
- #define EM_VAX 75
- #define EM_CHRIS 76
- #define EM_JAVELIN 77
- #define EM_FIREPATH 78
- #define EM_ZSP 79
- #define EM_MMIX 80
- #define EM_HUANY 81
- #define EM_PRISM 82
- #define EM_AVR 83
- #define EM_FR30 84
- #define EM_D10V 85
- #define EM_D30V 86
- #define EM_V850 87
- #define EM_M32R 88
- #define EM_MN10300 89
- #define EM_MN10200 90
- #define EM_PJ 91
- #define EM_NUM 92
- #define EV_NONE 0
- #define EV_CURRENT 1
- #define EV_NUM 2
- 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;
- #define SHN_UNDEF 0
- #define SHN_LORESERVE 0xff00
- #define SHN_LOPROC 0xff00
- #define SHN_HIPROC 0xff1f
- #define SHN_LOOS 0xff20
- #define SHN_HIOS 0xff3f
- #define SHN_ABS 0xfff1
- #define SHN_COMMON 0xfff2
- #define SHN_XINDEX 0xffff
- #define SHN_HIRESERVE 0xffff
- #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_INIT_ARRAY 14
- #define SHT_FINI_ARRAY 15
- #define SHT_PREINIT_ARRAY 16
- #define SHT_GROUP 17
- #define SHT_SYMTAB_SHNDX 18
- #define SHT_NUM 19
- #define SHT_LOOS 0x60000000
- #define SHT_HIOS 0x6fffffff
- #define SHT_LOPROC 0x70000000
- #define SHT_HIPROC 0x7fffffff
- #define SHT_LOUSER 0x80000000
- #define SHT_HIUSER 0xffffffff
- #define ELF_BSS ".bss"
- #define ELF_COMMENT ".comment"
- #define ELF_DATA ".data"
- #define ELF_DATA1 ".data1"
- #define ELF_DEBUG ".debug"
- #define ELF_DYNAMIC ".dynamic"
- #define ELF_DYNSTR ".dynstr"
- #define ELF_DYNSYM ".dynsym"
- #define ELF_FINI ".fini"
- #define ELF_FINI_ARRAY ".fini_array"
- #define ELF_GOT ".got"
- #define ELF_HASH ".hash"
- #define ELF_INIT ".init"
- #define ELF_INIT_ARRAY ".init_array"
- #define ELF_INTERP ".interp"
- #define ELF_LINE ".line"
- #define ELF_NOTE ".note"
- #define ELF_PLT ".plt"
- #define ELF_PREINIT_ARRAY ".preinit_array"
- #define ELF_REL_DATA ".rel.data"
- #define ELF_REL_FINI ".rel.fini"
- #define ELF_REL_INIT ".rel.init"
- #define ELF_REL_DYN ".rel.dyn"
- #define ELF_REL_RODATA ".rel.rodata"
- #define ELF_REL_TEXT ".rel.text"
- #define ELF_RODATA ".rodata"
- #define ELF_RODATA1 ".rodata1"
- #define ELF_SHSTRTAB ".shstrtab"
- #define ELF_STRTAB ".strtab"
- #define ELF_SYMTAB ".symtab"
- #define ELF_SYMTAB_SHNDX ".symtab_shndx"
- #define ELF_TBSS ".tbss"
- #define ELF_TDATA ".tdata"
- #define ELF_TDATA1 ".tdata1"
- #define ELF_TEXT ".text"
- #define SHF_WRITE 0x1
- #define SHF_ALLOC 0x2
- #define SHF_EXECINSTR 0x4
- #define SHF_MERGE 0x10
- #define SHF_STRINGS 0x20
- #define SHF_INFO_LINK 0x40
- #define SHF_LINK_ORDER 0x80
- #define SHF_OS_NONCONFORMING 0x100
- #define SHF_GROUP 0x200
- #define SHF_TLS 0x400
- #define SHF_MASKOS 0x0ff00000
- #define SHF_MASKPROC 0xf0000000
-
- #define GRP_COMDAT 0x1
- #define GRP_MASKOS 0x0ff00000
- #define GRP_MASKPROC 0xf0000000
- typedef struct elf32_sym {
- 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;
- #define STN_UNDEF 0
- #define ELF32_ST_BIND(x) ((x) >> 4)
- #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
- #define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
- #define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
- #define STB_LOCAL 0
- #define STB_GLOBAL 1
- #define STB_WEAK 2
- #define STB_NUM 3
- #define STB_LOOS 10
- #define STB_HIOS 12
- #define STB_LOPROC 13
- #define STB_HIPROC 15
- #define STT_NOTYPE 0
- #define STT_OBJECT 1
- #define STT_FUNC 2
- #define STT_SECTION 3
- #define STT_FILE 4
- #define STT_NUM 5
- #define STT_TLS 6
- #define STT_LOOS 10
- #define STT_HIOS 12
- #define STT_LOPROC 13
- #define STT_HIPROC 15
- #define STV_DEFAULT 0
- #define STV_INTERNAL 1
- #define STV_HIDDEN 2
- #define STV_PROTECTED 3
- 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;
- typedef struct {
- Elf64_Addr r_offset;
- Elf64_Xword r_info;
- } Elf64_Rel;
- typedef struct {
- Elf64_Addr r_offset;
- Elf64_Xword r_info;
- Elf64_Sxword r_addend;
- } Elf64_Rela;
- #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))
- 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;
- #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_TLS 7
- #define PT_NUM 8
- #define PT_LOOS 0x60000000
- #define PT_HIOS 0x6fffffff
- #define PT_LOPROC 0x70000000
- #define PT_HIPROC 0x7fffffff
- #define PF_X 0x1
- #define PF_W 0x2
- #define PF_R 0x4
- #define PF_MASKOS 0x0ff00000
- #define PF_MASKPROC 0xf0000000
-
- typedef struct
- {
- Elf32_Sword d_tag;
- union
- {
- Elf32_Word d_val;
- Elf32_Addr d_ptr;
- } d_un;
- } Elf32_Dyn;
- extern Elf32_Dyn _DYNAMIC[];
- typedef struct {
- Elf64_Sxword d_tag;
- union {
- Elf64_Xword d_val;
- Elf64_Addr d_ptr;
- } d_un;
- } Elf64_Dyn;
- #define ELF64_R_SYM(i) ((i) >> 32)
- #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
- #define DT_NULL 0
- #define DT_NEEDED 1
- #define DT_PLTRELSZ 2
- #define DT_PLTGOT 3
- #define DT_HASH 4
- #define DT_STRTAB 5
- #define DT_SYMTAB 6
- #define DT_RELA 7
- #define DT_RELASZ 8
- #define DT_RELAENT 9
- #define DT_STRSZ 10
- #define DT_SYMENT 11
- #define DT_INIT 12
- #define DT_FINI 13
- #define DT_SONAME 14
- #define DT_RPATH 15
- #define DT_SYMBOLIC 16
- #define DT_REL 17
- #define DT_RELSZ 18
- #define DT_RELENT 19
- #define DT_PLTREL 20
- #define DT_DEBUG 21
- #define DT_TEXTREL 22
- #define DT_JMPREL 23
- #define DT_BIND_NOW 24
- #define DT_INIT_ARRAY 25
- #define DT_FINI_ARRAY 26
- #define DT_INIT_ARRAYSZ 27
- #define DT_FINI_ARRAYSZ 28
- #define DT_RUNPATH 29
- #define DT_FLAGS 30
- #define DT_ENCODING 32
- #define DT_PREINIT_ARRAY 32
- #define DT_PREINIT_ARRAYSZ 33
- #define DT_NUM 34
- #define DT_LOOS 0x60000000
- #define DT_HIOS 0x6fffffff
- #define DT_LOPROC 0x70000000
- #define DT_HIPROC 0x7fffffff
- #define DF_ORIGIN 0x01
- #define DF_SYMBOLIC 0x02
- #define DF_TEXTREL 0x04
- #define DF_BIND_NOW 0x08
- #define DF_STATIC_TLS 0x10
- unsigned long elf_hash(const unsigned char *name);
- #define ELF_TARG_VER 1
- #endif
- #define EF_PPC_EMB 0x80000000
- #define EF_PPC_RELOCATABLE 0x00010000
- #define EF_PPC_RELOCATABLE_LIB 0x00008000
- #define R_PPC_NONE 0
- #define R_PPC_ADDR32 1
- #define R_PPC_ADDR24 2
- #define R_PPC_ADDR16 3
- #define R_PPC_ADDR16_LO 4
- #define R_PPC_ADDR16_HI 5
- #define R_PPC_ADDR16_HA 6
- #define R_PPC_ADDR14 7
- #define R_PPC_ADDR14_BRTAKEN 8
- #define R_PPC_ADDR14_BRNTAKEN 9
- #define R_PPC_REL24 10
- #define R_PPC_REL14 11
- #define R_PPC_REL14_BRTAKEN 12
- #define R_PPC_REL14_BRNTAKEN 13
- #define R_PPC_GOT16 14
- #define R_PPC_GOT16_LO 15
- #define R_PPC_GOT16_HI 16
- #define R_PPC_GOT16_HA 17
- #define R_PPC_PLTREL24 18
- #define R_PPC_COPY 19
- #define R_PPC_GLOB_DAT 20
- #define R_PPC_JMP_SLOT 21
- #define R_PPC_RELATIVE 22
- #define R_PPC_LOCAL24PC 23
- #define R_PPC_UADDR32 24
- #define R_PPC_UADDR16 25
- #define R_PPC_REL32 26
- #define R_PPC_PLT32 27
- #define R_PPC_PLTREL32 28
- #define R_PPC_PLT16_LO 29
- #define R_PPC_PLT16_HI 30
- #define R_PPC_PLT16_HA 31
- #define R_PPC_SDAREL16 32
- #define R_PPC_SECTOFF 33
- #define R_PPC_SECTOFF_LO 34
- #define R_PPC_SECTOFF_HI 35
- #define R_PPC_SECTOFF_HA 36
- #define R_PPC_NUM 37
- #define R_PPC_EMB_NADDR32 101
- #define R_PPC_EMB_NADDR16 102
- #define R_PPC_EMB_NADDR16_LO 103
- #define R_PPC_EMB_NADDR16_HI 104
- #define R_PPC_EMB_NADDR16_HA 105
- #define R_PPC_EMB_SDAI16 106
- #define R_PPC_EMB_SDA2I16 107
- #define R_PPC_EMB_SDA2REL 108
- #define R_PPC_EMB_SDA21 109
- #define R_PPC_EMB_MRKREF 110
- #define R_PPC_EMB_RELSEC16 111
- #define R_PPC_EMB_RELST_LO 112
- #define R_PPC_EMB_RELST_HI 113
- #define R_PPC_EMB_RELST_HA 114
- #define R_PPC_EMB_BIT_FLD 115
- #define R_PPC_EMB_RELSDA 116
- #define R_PPC_DIAB_SDA21_LO 180
- #define R_PPC_DIAB_SDA21_HI 181
- #define R_PPC_DIAB_SDA21_HA 182
- #define R_PPC_DIAB_RELSDA_LO 183
- #define R_PPC_DIAB_RELSDA_HI 184
- #define R_PPC_DIAB_RELSDA_HA 185
- #define R_PPC_TOC16 255
-
- #define R_ARM_NONE 0
- #define R_ARM_RELATIVE 23
- #define R_AARCH64_NONE 0
- #define R_AARCH64_RELATIVE 1027
- #ifndef __ASSEMBLER__
- int valid_elf_image(unsigned long addr);
- #endif
- #endif
|