1 /* This file is part of centaur.
3 * centaur is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License 2 as
5 * published by the Free Software Foundation.
7 * centaur is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with centaur. If not, see <http://www.gnu.org/licenses/>.
18 * @brief libelfu's Elfu* types.
20 * libelfu provides an abstraction of the data in ELF files
21 * to more closely model the dependencies between them, and
22 * thus to facilitate consistent editing.
25 #ifndef __LIBELFU_TYPES_H__
26 #define __LIBELFU_TYPES_H__
28 #include <sys/queue.h>
35 * ELFU model of a symbol table entry.
37 typedef struct ElfuSym {
38 /*! Offset into linked string table */
45 /*! Size of object referenced */
49 /*! Binding type (GLOBAL, LOCAL, ...) */
52 /*! Type (FUNC, SECTION, ...) */
55 /*! Always 0, currently meaningless (see ELF spec) */
59 /*! If non-null, the section referenced. */
60 struct ElfuScn *scnptr;
62 /*! If scnptr is invalid, then this is ABS, COMMON, or UNDEF. */
66 /*! Entry in a symbol table */
67 CIRCLEQ_ENTRY(ElfuSym) elem;
73 * ELFU model of a symbol table.
75 typedef struct ElfuSymtab {
76 /*! All parsed symbols */
77 CIRCLEQ_HEAD(Syms, ElfuSym) syms;
85 * ELFU model of a relocation entry.
87 typedef struct ElfuRel {
88 /*! Location to patch */
92 /*! Symbol to calculate value for */
95 /*! Relocation type (machine specific) */
99 /*! addendUsed == 0: Use addend from relocation destination (REL).
100 * addendUsed != 0: Use explicit addend (RELA). */
103 /*! Explicit addend in RELA tables */
107 /*! Element in table */
108 CIRCLEQ_ENTRY(ElfuRel) elem;
114 * ELFU model of a relocation table.
116 typedef struct ElfuReltab {
117 /*! All parsed relocation entries */
118 CIRCLEQ_HEAD(Rels, ElfuRel) rels;
128 * ELFU model of an ELF section.
130 * Several members of the SHDR are repeated in abstract form and take
131 * precedence if present. For example, if linkptr is non-NULL then
132 * it points to another section and the SHDR's numeric sh_link member
133 * is to be ignored and recomputed by the layouter.
135 typedef struct ElfuScn {
136 /*! SHDR as per ELF specification.
137 * Several values are ignored or recomputed from other members of
141 /*! malloc()ed buffer containing this section's flat data backbuffer.
142 * Present for all sections that occupy space in the file. */
146 /*! Pointer to a section, meaning dependent on sh_type.
147 * Preferred over sh_link if non-null. */
148 struct ElfuScn *linkptr;
150 /*! Pointer to a section, meaning dependent on sh_type.
151 * Preferred over sh_info if non-null. */
152 struct ElfuScn *infoptr;
155 /*! If this section is a clone of another section, then this
156 * points to that other section.
157 * Used during code injection to facilitate relocation. */
158 struct ElfuScn *oldptr;
161 /*! Translated contents of a symbol table. */
162 struct ElfuSymtab symtab;
164 /*! Translated contents of a relocation table. */
165 struct ElfuReltab reltab;
168 /*! Element linking this section into an ElfuPhdr's childScnList,
169 * or into an ElfuElf's orphanScnList. */
170 CIRCLEQ_ENTRY(ElfuScn) elemChildScn;
176 * ELFU model of an ELF PHDR.
178 typedef struct ElfuPhdr {
179 /*! PHDR as per ELF specification. */
183 /*! Sections to be shifted in file/memory together with this PHDR */
184 CIRCLEQ_HEAD(ChildScnList, ElfuScn) childScnList;
186 /*! PHDRs to be shifted in file/memory together with this PHDR */
187 CIRCLEQ_HEAD(ChildPhdrList, ElfuPhdr) childPhdrList;
190 /*! Element linking this section into an ElfuPhdr's childPhdrList */
191 CIRCLEQ_ENTRY(ElfuPhdr) elemChildPhdr;
193 /*! Element linking this section into an ElfuElf's phdrList */
194 CIRCLEQ_ENTRY(ElfuPhdr) elem;
200 * ELFU model of an ELF file header
203 /*! The ELF class -- ELFCLASS32/ELFCLASS64 */
206 /*! EHDR as per ELF specification */
210 /*! PHDRs that are not dependent on others.
211 * Usually, LOAD and GNU_STACK. */
212 CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList;
214 /*! Sections not in any PHDR, and thus not loaded at runtime.
215 * Usually .symtab, .strtab, .shstrtab, .debug_*, ... */
216 CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList;
219 /*! Pointer to ElfuScn containing .shstrtab.
220 * Parsed from EHDR for convenience. */
223 /*! Pointer to ElfuScn containing .symtab.
224 * Parsed from list of sections for convenience. */