3 * @brief libelfu's Elfu* types.
5 * libelfu provides an abstraction of the data in ELF files
6 * to more closely model the dependencies between them, and
7 * thus to facilitate consistent editing.
10 #ifndef __LIBELFU_TYPES_H__
11 #define __LIBELFU_TYPES_H__
13 #include <sys/queue.h>
20 * ELFU model of a symbol table entry.
22 typedef struct ElfuSym {
23 /*! Offset into linked string table */
30 /*! Size of object referenced */
34 /*! Binding type (GLOBAL, LOCAL, ...) */
37 /*! Type (FUNC, SECTION, ...) */
40 /*! Always 0, currently meaningless (see ELF spec) */
44 /*! If non-null, the section referenced. */
45 struct ElfuScn *scnptr;
47 /*! If scnptr is invalid, then this is ABS, COMMON, or UNDEF. */
51 /*! Entry in a symbol table */
52 CIRCLEQ_ENTRY(ElfuSym) elem;
58 * ELFU model of a symbol table.
60 typedef struct ElfuSymtab {
61 /*! All parsed symbols */
62 CIRCLEQ_HEAD(Syms, ElfuSym) syms;
70 * ELFU model of a relocation entry.
72 typedef struct ElfuRel {
73 /*! Location to patch */
77 /*! Symbol to calculate value for */
80 /*! Relocation type (machine specific) */
84 /*! addendUsed == 0: Use addend from relocation destination (REL).
85 * addendUsed != 0: Use explicit addend (RELA). */
88 /*! Explicit addend in RELA tables */
92 /*! Element in table */
93 CIRCLEQ_ENTRY(ElfuRel) elem;
99 * ELFU model of a relocation table.
101 typedef struct ElfuReltab {
102 /*! All parsed relocation entries */
103 CIRCLEQ_HEAD(Rels, ElfuRel) rels;
113 * ELFU model of an ELF section.
115 * Several members of the SHDR are repeated in abstract form and take
116 * precedence if present. For example, if linkptr is non-NULL then
117 * it points to another section and the SHDR's numeric sh_link member
118 * is to be ignored and recomputed by the layouter.
120 typedef struct ElfuScn {
121 /*! SHDR as per ELF specification.
122 * Several values are ignored or recomputed from other members of
126 /*! malloc()ed buffer containing this section's flat data backbuffer.
127 * Present for all sections that occupy space in the file. */
131 /*! Pointer to a section, meaning dependent on sh_type.
132 * Preferred over sh_link if non-null. */
133 struct ElfuScn *linkptr;
135 /*! Pointer to a section, meaning dependent on sh_type.
136 * Preferred over sh_info if non-null. */
137 struct ElfuScn *infoptr;
140 /*! If this section is a clone of another section, then this
141 * points to that other section.
142 * Used during code injection to facilitate relocation. */
143 struct ElfuScn *oldptr;
146 /*! Translated contents of a symbol table. */
147 struct ElfuSymtab symtab;
149 /*! Translated contents of a relocation table. */
150 struct ElfuReltab reltab;
153 /*! Element linking this section into an ElfuPhdr's childScnList,
154 * or into an ElfuElf's orphanScnList. */
155 CIRCLEQ_ENTRY(ElfuScn) elemChildScn;
161 * ELFU model of an ELF PHDR.
163 typedef struct ElfuPhdr {
164 /*! PHDR as per ELF specification. */
168 /*! Sections to be shifted in file/memory together with this PHDR */
169 CIRCLEQ_HEAD(ChildScnList, ElfuScn) childScnList;
171 /*! PHDRs to be shifted in file/memory together with this PHDR */
172 CIRCLEQ_HEAD(ChildPhdrList, ElfuPhdr) childPhdrList;
175 /*! Element linking this section into an ElfuPhdr's childPhdrList */
176 CIRCLEQ_ENTRY(ElfuPhdr) elemChildPhdr;
178 /*! Element linking this section into an ElfuElf's phdrList */
179 CIRCLEQ_ENTRY(ElfuPhdr) elem;
185 * ELFU model of an ELF file header
188 /*! The ELF class -- ELFCLASS32/ELFCLASS64 */
191 /*! EHDR as per ELF specification */
195 /*! PHDRs that are not dependent on others.
196 * Usually, LOAD and GNU_STACK. */
197 CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList;
199 /*! Sections not in any PHDR, and thus not loaded at runtime.
200 * Usually .symtab, .strtab, .shstrtab, .debug_*, ... */
201 CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList;
204 /*! Pointer to ElfuScn containing .shstrtab.
205 * Parsed from EHDR for convenience. */
208 /*! Pointer to ElfuScn containing .symtab.
209 * Parsed from list of sections for convenience. */