1 |
1624 |
jcastillo |
/* ELF support for BFD.
|
2 |
|
|
Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
Written by Fred Fish @ Cygnus Support, from information published
|
5 |
|
|
in "UNIX System V Release 4, Programmers Guide: ANSI C and
|
6 |
|
|
Programming Support Tools".
|
7 |
|
|
|
8 |
|
|
This file is part of BFD, the Binary File Descriptor library.
|
9 |
|
|
|
10 |
|
|
This program is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
This program is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with this program; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* This file is part of ELF support for BFD, and contains the portions
|
26 |
|
|
that describe how ELF is represented internally in the BFD library.
|
27 |
|
|
I.E. it describes the in-memory representation of ELF. It requires
|
28 |
|
|
the elf-common.h file which contains the portions that are common to
|
29 |
|
|
both the internal and external representations. */
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/* NOTE that these structures are not kept in the same order as they appear
|
33 |
|
|
in the object file. In some cases they've been reordered for more optimal
|
34 |
|
|
packing under various circumstances. */
|
35 |
|
|
|
36 |
|
|
/* ELF Header */
|
37 |
|
|
|
38 |
|
|
#define EI_NIDENT 16 /* Size of e_ident[] */
|
39 |
|
|
|
40 |
|
|
typedef struct elf_internal_ehdr {
|
41 |
|
|
unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
|
42 |
|
|
bfd_vma e_entry; /* Entry point virtual address */
|
43 |
|
|
bfd_signed_vma e_phoff; /* Program header table file offset */
|
44 |
|
|
bfd_signed_vma e_shoff; /* Section header table file offset */
|
45 |
|
|
unsigned long e_version; /* Identifies object file version */
|
46 |
|
|
unsigned long e_flags; /* Processor-specific flags */
|
47 |
|
|
unsigned short e_type; /* Identifies object file type */
|
48 |
|
|
unsigned short e_machine; /* Specifies required architecture */
|
49 |
|
|
unsigned short e_ehsize; /* ELF header size in bytes */
|
50 |
|
|
unsigned short e_phentsize; /* Program header table entry size */
|
51 |
|
|
unsigned short e_phnum; /* Program header table entry count */
|
52 |
|
|
unsigned short e_shentsize; /* Section header table entry size */
|
53 |
|
|
unsigned short e_shnum; /* Section header table entry count */
|
54 |
|
|
unsigned short e_shstrndx; /* Section header string table index */
|
55 |
|
|
} Elf_Internal_Ehdr;
|
56 |
|
|
|
57 |
|
|
#define elf32_internal_ehdr elf_internal_ehdr
|
58 |
|
|
#define Elf32_Internal_Ehdr Elf_Internal_Ehdr
|
59 |
|
|
#define elf64_internal_ehdr elf_internal_ehdr
|
60 |
|
|
#define Elf64_Internal_Ehdr Elf_Internal_Ehdr
|
61 |
|
|
|
62 |
|
|
/* Program header */
|
63 |
|
|
|
64 |
|
|
struct elf_internal_phdr {
|
65 |
|
|
unsigned long p_type; /* Identifies program segment type */
|
66 |
|
|
unsigned long p_flags; /* Segment flags */
|
67 |
|
|
bfd_vma p_offset; /* Segment file offset */
|
68 |
|
|
bfd_vma p_vaddr; /* Segment virtual address */
|
69 |
|
|
bfd_vma p_paddr; /* Segment physical address */
|
70 |
|
|
bfd_vma p_filesz; /* Segment size in file */
|
71 |
|
|
bfd_vma p_memsz; /* Segment size in memory */
|
72 |
|
|
bfd_vma p_align; /* Segment alignment, file & memory */
|
73 |
|
|
};
|
74 |
|
|
|
75 |
|
|
typedef struct elf_internal_phdr Elf_Internal_Phdr;
|
76 |
|
|
#define elf32_internal_phdr elf_internal_phdr
|
77 |
|
|
#define Elf32_Internal_Phdr Elf_Internal_Phdr
|
78 |
|
|
#define elf64_internal_phdr elf_internal_phdr
|
79 |
|
|
#define Elf64_Internal_Phdr Elf_Internal_Phdr
|
80 |
|
|
|
81 |
|
|
/* Section header */
|
82 |
|
|
|
83 |
|
|
typedef struct elf_internal_shdr {
|
84 |
|
|
unsigned int sh_name; /* Section name, index in string tbl */
|
85 |
|
|
unsigned int sh_type; /* Type of section */
|
86 |
|
|
bfd_vma sh_flags; /* Miscellaneous section attributes */
|
87 |
|
|
bfd_vma sh_addr; /* Section virtual addr at execution */
|
88 |
|
|
bfd_size_type sh_size; /* Size of section in bytes */
|
89 |
|
|
bfd_size_type sh_entsize; /* Entry size if section holds table */
|
90 |
|
|
unsigned long sh_link; /* Index of another section */
|
91 |
|
|
unsigned long sh_info; /* Additional section information */
|
92 |
|
|
file_ptr sh_offset; /* Section file offset */
|
93 |
|
|
unsigned int sh_addralign; /* Section alignment */
|
94 |
|
|
|
95 |
|
|
/* The internal rep also has some cached info associated with it. */
|
96 |
|
|
asection * bfd_section; /* Associated BFD section. */
|
97 |
|
|
PTR contents; /* Section contents. */
|
98 |
|
|
} Elf_Internal_Shdr;
|
99 |
|
|
|
100 |
|
|
#define elf32_internal_shdr elf_internal_shdr
|
101 |
|
|
#define Elf32_Internal_Shdr Elf_Internal_Shdr
|
102 |
|
|
#define elf64_internal_shdr elf_internal_shdr
|
103 |
|
|
#define Elf64_Internal_Shdr Elf_Internal_Shdr
|
104 |
|
|
|
105 |
|
|
/* Symbol table entry */
|
106 |
|
|
|
107 |
|
|
struct elf_internal_sym {
|
108 |
|
|
bfd_vma st_value; /* Value of the symbol */
|
109 |
|
|
bfd_vma st_size; /* Associated symbol size */
|
110 |
|
|
unsigned long st_name; /* Symbol name, index in string tbl */
|
111 |
|
|
unsigned char st_info; /* Type and binding attributes */
|
112 |
|
|
unsigned char st_other; /* No defined meaning, 0 */
|
113 |
|
|
unsigned short st_shndx; /* Associated section index */
|
114 |
|
|
};
|
115 |
|
|
|
116 |
|
|
typedef struct elf_internal_sym Elf_Internal_Sym;
|
117 |
|
|
|
118 |
|
|
#define elf32_internal_sym elf_internal_sym
|
119 |
|
|
#define elf64_internal_sym elf_internal_sym
|
120 |
|
|
#define Elf32_Internal_Sym Elf_Internal_Sym
|
121 |
|
|
#define Elf64_Internal_Sym Elf_Internal_Sym
|
122 |
|
|
|
123 |
|
|
/* Note segments */
|
124 |
|
|
|
125 |
|
|
typedef struct elf_internal_note {
|
126 |
|
|
unsigned long namesz; /* Size of entry's owner string */
|
127 |
|
|
unsigned long descsz; /* Size of the note descriptor */
|
128 |
|
|
unsigned long type; /* Interpretation of the descriptor */
|
129 |
|
|
char name[1]; /* Start of the name+desc data */
|
130 |
|
|
} Elf_Internal_Note;
|
131 |
|
|
#define Elf32_Internal_Note Elf_Internal_Note
|
132 |
|
|
#define elf32_internal_note elf_internal_note
|
133 |
|
|
|
134 |
|
|
/* Relocation Entries */
|
135 |
|
|
|
136 |
|
|
typedef struct elf_internal_rel {
|
137 |
|
|
bfd_vma r_offset; /* Location at which to apply the action */
|
138 |
|
|
/* This needs to support 64-bit values in elf64. */
|
139 |
|
|
bfd_vma r_info; /* index and type of relocation */
|
140 |
|
|
} Elf_Internal_Rel;
|
141 |
|
|
|
142 |
|
|
#define elf32_internal_rel elf_internal_rel
|
143 |
|
|
#define Elf32_Internal_Rel Elf_Internal_Rel
|
144 |
|
|
#define elf64_internal_rel elf_internal_rel
|
145 |
|
|
#define Elf64_Internal_Rel Elf_Internal_Rel
|
146 |
|
|
|
147 |
|
|
typedef struct elf_internal_rela {
|
148 |
|
|
bfd_vma r_offset; /* Location at which to apply the action */
|
149 |
|
|
bfd_vma r_info; /* Index and Type of relocation */
|
150 |
|
|
bfd_signed_vma r_addend; /* Constant addend used to compute value */
|
151 |
|
|
} Elf_Internal_Rela;
|
152 |
|
|
|
153 |
|
|
#define elf32_internal_rela elf_internal_rela
|
154 |
|
|
#define elf64_internal_rela elf_internal_rela
|
155 |
|
|
#define Elf32_Internal_Rela Elf_Internal_Rela
|
156 |
|
|
#define Elf64_Internal_Rela Elf_Internal_Rela
|
157 |
|
|
|
158 |
|
|
/* dynamic section structure */
|
159 |
|
|
|
160 |
|
|
typedef struct elf_internal_dyn {
|
161 |
|
|
/* This needs to support 64-bit values in elf64. */
|
162 |
|
|
bfd_vma d_tag; /* entry tag value */
|
163 |
|
|
union {
|
164 |
|
|
/* This needs to support 64-bit values in elf64. */
|
165 |
|
|
bfd_vma d_val;
|
166 |
|
|
bfd_vma d_ptr;
|
167 |
|
|
} d_un;
|
168 |
|
|
} Elf_Internal_Dyn;
|
169 |
|
|
|
170 |
|
|
#define elf32_internal_dyn elf_internal_dyn
|
171 |
|
|
#define elf64_internal_dyn elf_internal_dyn
|
172 |
|
|
#define Elf32_Internal_Dyn Elf_Internal_Dyn
|
173 |
|
|
#define Elf64_Internal_Dyn Elf_Internal_Dyn
|