1 |
1624 |
jcastillo |
/* ELF support for BFD.
|
2 |
|
|
Copyright (C) 1991, 1992 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 externally by the BFD library.
|
27 |
|
|
I.E. it describes the in-file 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 |
|
|
/* The 64-bit stuff is kind of random. Perhaps someone will publish a
|
32 |
|
|
spec someday. */
|
33 |
|
|
|
34 |
|
|
/* ELF Header (32-bit implementations) */
|
35 |
|
|
|
36 |
|
|
typedef struct {
|
37 |
|
|
unsigned char e_ident[16]; /* ELF "magic number" */
|
38 |
|
|
unsigned char e_type[2]; /* Identifies object file type */
|
39 |
|
|
unsigned char e_machine[2]; /* Specifies required architecture */
|
40 |
|
|
unsigned char e_version[4]; /* Identifies object file version */
|
41 |
|
|
unsigned char e_entry[4]; /* Entry point virtual address */
|
42 |
|
|
unsigned char e_phoff[4]; /* Program header table file offset */
|
43 |
|
|
unsigned char e_shoff[4]; /* Section header table file offset */
|
44 |
|
|
unsigned char e_flags[4]; /* Processor-specific flags */
|
45 |
|
|
unsigned char e_ehsize[2]; /* ELF header size in bytes */
|
46 |
|
|
unsigned char e_phentsize[2]; /* Program header table entry size */
|
47 |
|
|
unsigned char e_phnum[2]; /* Program header table entry count */
|
48 |
|
|
unsigned char e_shentsize[2]; /* Section header table entry size */
|
49 |
|
|
unsigned char e_shnum[2]; /* Section header table entry count */
|
50 |
|
|
unsigned char e_shstrndx[2]; /* Section header string table index */
|
51 |
|
|
} Elf32_External_Ehdr;
|
52 |
|
|
|
53 |
|
|
typedef struct {
|
54 |
|
|
unsigned char e_ident[16]; /* ELF "magic number" */
|
55 |
|
|
unsigned char e_type[2]; /* Identifies object file type */
|
56 |
|
|
unsigned char e_machine[2]; /* Specifies required architecture */
|
57 |
|
|
unsigned char e_version[4]; /* Identifies object file version */
|
58 |
|
|
unsigned char e_entry[8]; /* Entry point virtual address */
|
59 |
|
|
unsigned char e_phoff[8]; /* Program header table file offset */
|
60 |
|
|
unsigned char e_shoff[8]; /* Section header table file offset */
|
61 |
|
|
unsigned char e_flags[4]; /* Processor-specific flags */
|
62 |
|
|
unsigned char e_ehsize[2]; /* ELF header size in bytes */
|
63 |
|
|
unsigned char e_phentsize[2]; /* Program header table entry size */
|
64 |
|
|
unsigned char e_phnum[2]; /* Program header table entry count */
|
65 |
|
|
unsigned char e_shentsize[2]; /* Section header table entry size */
|
66 |
|
|
unsigned char e_shnum[2]; /* Section header table entry count */
|
67 |
|
|
unsigned char e_shstrndx[2]; /* Section header string table index */
|
68 |
|
|
} Elf64_External_Ehdr;
|
69 |
|
|
|
70 |
|
|
/* Program header */
|
71 |
|
|
|
72 |
|
|
typedef struct {
|
73 |
|
|
unsigned char p_type[4]; /* Identifies program segment type */
|
74 |
|
|
unsigned char p_offset[4]; /* Segment file offset */
|
75 |
|
|
unsigned char p_vaddr[4]; /* Segment virtual address */
|
76 |
|
|
unsigned char p_paddr[4]; /* Segment physical address */
|
77 |
|
|
unsigned char p_filesz[4]; /* Segment size in file */
|
78 |
|
|
unsigned char p_memsz[4]; /* Segment size in memory */
|
79 |
|
|
unsigned char p_flags[4]; /* Segment flags */
|
80 |
|
|
unsigned char p_align[4]; /* Segment alignment, file & memory */
|
81 |
|
|
} Elf32_External_Phdr;
|
82 |
|
|
|
83 |
|
|
typedef struct {
|
84 |
|
|
unsigned char p_type[4]; /* Identifies program segment type */
|
85 |
|
|
unsigned char p_flags[4]; /* Segment flags */
|
86 |
|
|
unsigned char p_offset[8]; /* Segment file offset */
|
87 |
|
|
unsigned char p_vaddr[8]; /* Segment virtual address */
|
88 |
|
|
unsigned char p_paddr[8]; /* Segment physical address */
|
89 |
|
|
unsigned char p_filesz[8]; /* Segment size in file */
|
90 |
|
|
unsigned char p_memsz[8]; /* Segment size in memory */
|
91 |
|
|
unsigned char p_align[8]; /* Segment alignment, file & memory */
|
92 |
|
|
} Elf64_External_Phdr;
|
93 |
|
|
|
94 |
|
|
/* Section header */
|
95 |
|
|
|
96 |
|
|
typedef struct {
|
97 |
|
|
unsigned char sh_name[4]; /* Section name, index in string tbl */
|
98 |
|
|
unsigned char sh_type[4]; /* Type of section */
|
99 |
|
|
unsigned char sh_flags[4]; /* Miscellaneous section attributes */
|
100 |
|
|
unsigned char sh_addr[4]; /* Section virtual addr at execution */
|
101 |
|
|
unsigned char sh_offset[4]; /* Section file offset */
|
102 |
|
|
unsigned char sh_size[4]; /* Size of section in bytes */
|
103 |
|
|
unsigned char sh_link[4]; /* Index of another section */
|
104 |
|
|
unsigned char sh_info[4]; /* Additional section information */
|
105 |
|
|
unsigned char sh_addralign[4]; /* Section alignment */
|
106 |
|
|
unsigned char sh_entsize[4]; /* Entry size if section holds table */
|
107 |
|
|
} Elf32_External_Shdr;
|
108 |
|
|
|
109 |
|
|
typedef struct {
|
110 |
|
|
unsigned char sh_name[4]; /* Section name, index in string tbl */
|
111 |
|
|
unsigned char sh_type[4]; /* Type of section */
|
112 |
|
|
unsigned char sh_flags[8]; /* Miscellaneous section attributes */
|
113 |
|
|
unsigned char sh_addr[8]; /* Section virtual addr at execution */
|
114 |
|
|
unsigned char sh_offset[8]; /* Section file offset */
|
115 |
|
|
unsigned char sh_size[8]; /* Size of section in bytes */
|
116 |
|
|
unsigned char sh_link[4]; /* Index of another section */
|
117 |
|
|
unsigned char sh_info[4]; /* Additional section information */
|
118 |
|
|
unsigned char sh_addralign[8]; /* Section alignment */
|
119 |
|
|
unsigned char sh_entsize[8]; /* Entry size if section holds table */
|
120 |
|
|
} Elf64_External_Shdr;
|
121 |
|
|
|
122 |
|
|
/* Symbol table entry */
|
123 |
|
|
|
124 |
|
|
typedef struct {
|
125 |
|
|
unsigned char st_name[4]; /* Symbol name, index in string tbl */
|
126 |
|
|
unsigned char st_value[4]; /* Value of the symbol */
|
127 |
|
|
unsigned char st_size[4]; /* Associated symbol size */
|
128 |
|
|
unsigned char st_info[1]; /* Type and binding attributes */
|
129 |
|
|
unsigned char st_other[1]; /* No defined meaning, 0 */
|
130 |
|
|
unsigned char st_shndx[2]; /* Associated section index */
|
131 |
|
|
} Elf32_External_Sym;
|
132 |
|
|
|
133 |
|
|
typedef struct {
|
134 |
|
|
unsigned char st_name[4]; /* Symbol name, index in string tbl */
|
135 |
|
|
unsigned char st_info[1]; /* Type and binding attributes */
|
136 |
|
|
unsigned char st_other[1]; /* No defined meaning, 0 */
|
137 |
|
|
unsigned char st_shndx[2]; /* Associated section index */
|
138 |
|
|
unsigned char st_value[8]; /* Value of the symbol */
|
139 |
|
|
unsigned char st_size[8]; /* Associated symbol size */
|
140 |
|
|
} Elf64_External_Sym;
|
141 |
|
|
|
142 |
|
|
/* Note segments */
|
143 |
|
|
|
144 |
|
|
typedef struct {
|
145 |
|
|
unsigned char namesz[4]; /* Size of entry's owner string */
|
146 |
|
|
unsigned char descsz[4]; /* Size of the note descriptor */
|
147 |
|
|
unsigned char type[4]; /* Interpretation of the descriptor */
|
148 |
|
|
char name[1]; /* Start of the name+desc data */
|
149 |
|
|
} Elf_External_Note;
|
150 |
|
|
|
151 |
|
|
/* Relocation Entries */
|
152 |
|
|
typedef struct {
|
153 |
|
|
unsigned char r_offset[4]; /* Location at which to apply the action */
|
154 |
|
|
unsigned char r_info[4]; /* index and type of relocation */
|
155 |
|
|
} Elf32_External_Rel;
|
156 |
|
|
|
157 |
|
|
typedef struct {
|
158 |
|
|
unsigned char r_offset[4]; /* Location at which to apply the action */
|
159 |
|
|
unsigned char r_info[4]; /* index and type of relocation */
|
160 |
|
|
unsigned char r_addend[4]; /* Constant addend used to compute value */
|
161 |
|
|
} Elf32_External_Rela;
|
162 |
|
|
|
163 |
|
|
typedef struct {
|
164 |
|
|
unsigned char r_offset[8]; /* Location at which to apply the action */
|
165 |
|
|
unsigned char r_info[8]; /* index and type of relocation */
|
166 |
|
|
} Elf64_External_Rel;
|
167 |
|
|
|
168 |
|
|
typedef struct {
|
169 |
|
|
unsigned char r_offset[8]; /* Location at which to apply the action */
|
170 |
|
|
unsigned char r_info[8]; /* index and type of relocation */
|
171 |
|
|
unsigned char r_addend[8]; /* Constant addend used to compute value */
|
172 |
|
|
} Elf64_External_Rela;
|
173 |
|
|
|
174 |
|
|
/* dynamic section structure */
|
175 |
|
|
|
176 |
|
|
typedef struct {
|
177 |
|
|
unsigned char d_tag[4]; /* entry tag value */
|
178 |
|
|
union {
|
179 |
|
|
unsigned char d_val[4];
|
180 |
|
|
unsigned char d_ptr[4];
|
181 |
|
|
} d_un;
|
182 |
|
|
} Elf32_External_Dyn;
|
183 |
|
|
|
184 |
|
|
typedef struct {
|
185 |
|
|
unsigned char d_tag[8]; /* entry tag value */
|
186 |
|
|
union {
|
187 |
|
|
unsigned char d_val[8];
|
188 |
|
|
unsigned char d_ptr[8];
|
189 |
|
|
} d_un;
|
190 |
|
|
} Elf64_External_Dyn;
|