summaryrefslogtreecommitdiffstats
path: root/courgette/types_elf.h
blob: eb054ee5bc5c3b6f83bebd28bdbf321824f69a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COURGETTE_ELF_TYPES_H_
#define COURGETTE_ELF_TYPES_H_

//
// This header defines various types from the ELF file spec, but no code
// related to using them.
//

typedef uint32 Elf32_Addr;  // Unsigned program address
typedef uint16 Elf32_Half;  // Unsigned medium integer
typedef uint32 Elf32_Off;  // Unsigned file offset
typedef int32 Elf32_Sword;  // Signed large integer
typedef uint32 Elf32_Word;  // Unsigned large integer


// The header at the top of the file
struct Elf32_Ehdr {
  unsigned char  e_ident[16];
  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;
};

// values for header->e_type
enum e_type_values {
  ET_NONE = 0,  // No file type
  ET_REL = 1,  // Relocatable file
  ET_EXEC = 2,  // Executable file
  ET_DYN = 3,  // Shared object file
  ET_CORE = 4,  // Core file
  ET_LOPROC = 0xff00,  // Processor-specific
  ET_HIPROC = 0xfff  // Processor-specific
};

// values for header->e_machine
enum e_machine_values {
  EM_NONE = 0,  // No machine
  EM_386 = 3,  // Intel Architecture
  EM_ARM = 40,  // ARM Architecture
  EM_x86_64 = 62,  // Intel x86-64 Architecture
  // Other values skipped
};

// A section header in the section header table
struct Elf32_Shdr {
  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;
};

// Values for the section type field in a section header
enum sh_type_values {
  SHT_NULL = 0,
  SHT_PROGBITS = 1,
  SHT_SYMTAB = 2,
  SHT_STRTAB = 3,
  SHT_RELA = 4,
  SHT_HASH = 5,
  SHT_DYNAMIC = 6,
  SHT_NOTE = 7,
  SHT_NOBITS = 8,
  SHT_REL = 9,
  SHT_SHLIB = 10,
  SHT_DYNSYM = 11,
  SHT_INIT_ARRAY = 14,
  SHT_FINI_ARRAY = 15,
  SHT_LOPROC = 0x70000000,
  SHT_HIPROC = 0x7fffffff,
  SHT_LOUSER = 0x80000000,
  SHT_HIUSER = 0xffffffff,
};

struct Elf32_Phdr {
  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;
};

// Values for the segment type field in a program segment header
enum ph_type_values {
  PT_NULL = 0,
  PT_LOAD = 1,
  PT_DYNAMIC = 2,
  PT_INTERP = 3,
  PT_NOTE = 4,
  PT_SHLIB = 5,
  PT_PHDR = 6,
  PT_LOPROC = 0x70000000,
  PT_HIPROC = 0x7fffffff
};

struct Elf32_Rel {
  Elf32_Addr    r_offset;
  Elf32_Word    r_info;
};

struct Elf32_Rela {
  Elf32_Addr    r_offset;
  Elf32_Word    r_info;
  Elf32_Sword   r_addend;
};

enum elf32_rel_386_type_values {
  R_386_NONE = 0,
  R_386_32 = 1,
  R_386_PC32 = 2,
  R_386_GOT32 = 3,
  R_386_PLT32 = 4,
  R_386_COPY = 5,
  R_386_GLOB_DAT = 6,
  R_386_JMP_SLOT = 7,
  R_386_RELATIVE = 8,
  R_386_GOTOFF = 9,
  R_386_GOTPC = 10,
  R_386_TLS_TPOFF = 14,
};

enum elf32_rel_arm_type_values {
  R_ARM_RELATIVE = 23,
};

#endif  // COURGETTE_ELF_TYPES_H_