1 | /* $Id: elf32.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - ELF 32-bit header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef IPRT_INCLUDED_formats_elf32_h
|
---|
28 | #define IPRT_INCLUDED_formats_elf32_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/assertcompile.h>
|
---|
34 | #include "elf-common.h"
|
---|
35 |
|
---|
36 | /*
|
---|
37 | * ELF 32 standard types.
|
---|
38 | */
|
---|
39 | typedef uint32_t Elf32_Addr;
|
---|
40 | typedef uint16_t Elf32_Half;
|
---|
41 | typedef uint32_t Elf32_Off;
|
---|
42 | typedef int32_t Elf32_Sword;
|
---|
43 | typedef uint32_t Elf32_Word;
|
---|
44 |
|
---|
45 | /*
|
---|
46 | * Ensure type size correctness in accordance to .
|
---|
47 | * Portable Format Specification (for ELF), Version 1.1, fig 1-2. .
|
---|
48 | */
|
---|
49 | AssertCompileSize(Elf32_Addr, 4);
|
---|
50 | AssertCompileSize(Elf32_Half, 2);
|
---|
51 | AssertCompileSize(Elf32_Off, 4);
|
---|
52 | AssertCompileSize(Elf32_Sword, 4);
|
---|
53 | AssertCompileSize(Elf32_Word, 4);
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * ELF 32 non-standard types for convenience.
|
---|
57 | */
|
---|
58 | typedef Elf32_Word Elf32_Size;
|
---|
59 | typedef Elf32_Word Elf32_Hashelt;
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * ELF header.
|
---|
63 | */
|
---|
64 | typedef struct
|
---|
65 | {
|
---|
66 | unsigned char e_ident[16]; /* ELF identification. */
|
---|
67 | Elf32_Half e_type; /* Object file type. */
|
---|
68 | Elf32_Half e_machine; /* Machine type. */
|
---|
69 | Elf32_Word e_version; /* Object file version. */
|
---|
70 | Elf32_Addr e_entry; /* Entry point address. */
|
---|
71 | Elf32_Off e_phoff; /* Program header offset. */
|
---|
72 | Elf32_Off e_shoff; /* Section header offset. */
|
---|
73 | Elf32_Word e_flags; /* Processor-specific flags. */
|
---|
74 | Elf32_Half e_ehsize; /* ELF header size. */
|
---|
75 | Elf32_Half e_phentsize; /* Size of program header entries. */
|
---|
76 | Elf32_Half e_phnum; /* Number of program headers. */
|
---|
77 | Elf32_Half e_shentsize; /* Size of section header entries. */
|
---|
78 | Elf32_Half e_shnum; /* Number of section headers. */
|
---|
79 | Elf32_Half e_shstrndx; /* Section name string table index. */
|
---|
80 | } Elf32_Ehdr;
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * Section header.
|
---|
84 | */
|
---|
85 | typedef struct
|
---|
86 | {
|
---|
87 | Elf32_Word sh_name; /* Section name. */
|
---|
88 | Elf32_Word sh_type; /* Section type. */
|
---|
89 | Elf32_Word sh_flags; /* Section attributes. */
|
---|
90 | Elf32_Addr sh_addr; /* Virtual address in memory. */
|
---|
91 | Elf32_Off sh_offset; /* Offset in file. */
|
---|
92 | Elf32_Word sh_size; /* Size of section. */
|
---|
93 | Elf32_Word sh_link; /* Link to other section. */
|
---|
94 | Elf32_Word sh_info; /* Miscellaneous information. */
|
---|
95 | Elf32_Word sh_addralign; /* Address alignment boundary. */
|
---|
96 | Elf32_Word sh_entsize; /* Size of entries, if section has table. */
|
---|
97 | } Elf32_Shdr;
|
---|
98 |
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * Program header.
|
---|
102 | */
|
---|
103 | typedef struct
|
---|
104 | {
|
---|
105 | Elf32_Word p_type; /* Type of segment. */
|
---|
106 | Elf32_Off p_offset; /* Offset in file. */
|
---|
107 | Elf32_Addr p_vaddr; /* Virtual address in memory. */
|
---|
108 | Elf32_Addr p_paddr; /* Physical address (reserved). */
|
---|
109 | Elf32_Word p_filesz; /* Size of segment in file. */
|
---|
110 | Elf32_Word p_memsz; /* Size of segment in memory. */
|
---|
111 | Elf32_Word p_flags; /* Segment attributes. */
|
---|
112 | Elf32_Word p_align; /* Alignment of segment. */
|
---|
113 | } Elf32_Phdr;
|
---|
114 |
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * Note header.
|
---|
118 | */
|
---|
119 | typedef struct
|
---|
120 | {
|
---|
121 | Elf32_Word n_namesz; /* Length of note's name. */
|
---|
122 | Elf32_Word n_descsz; /* Length of note's description. */
|
---|
123 | Elf32_Word n_type; /* Type of note. */
|
---|
124 | } Elf32_Nhdr;
|
---|
125 |
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * Symbol table entry.
|
---|
129 | */
|
---|
130 | typedef struct
|
---|
131 | {
|
---|
132 | Elf32_Word st_name; /* Symbol name. */
|
---|
133 | Elf32_Addr st_value; /* Symbol value. */
|
---|
134 | Elf32_Word st_size; /* Size associated with symbol. */
|
---|
135 | unsigned char st_info; /* Type and binding attributes. */
|
---|
136 | unsigned char st_other; /* Reserved. */
|
---|
137 | Elf32_Half st_shndx; /* Section header table index. */
|
---|
138 | } Elf32_Sym;
|
---|
139 |
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Relocations.
|
---|
143 | */
|
---|
144 | typedef struct
|
---|
145 | {
|
---|
146 | Elf32_Addr r_offset; /* Location to be relocated. */
|
---|
147 | Elf32_Word r_info; /* Symbol index and type of relocation. */
|
---|
148 | } Elf32_Rel;
|
---|
149 |
|
---|
150 | typedef struct
|
---|
151 | {
|
---|
152 | Elf32_Addr r_offset; /* Location to be relocated. */
|
---|
153 | Elf32_Word r_info; /* Symbol index and type of relocation. */
|
---|
154 | Elf32_Sword r_addend; /* Constant part of expression. */
|
---|
155 | } Elf32_Rela;
|
---|
156 |
|
---|
157 | /*
|
---|
158 | * Dynamic section entry.
|
---|
159 | * ".dynamic" section contains an array of this.
|
---|
160 | */
|
---|
161 | typedef struct
|
---|
162 | {
|
---|
163 | Elf32_Sword d_tag; /* Type of entry. */
|
---|
164 | union
|
---|
165 | {
|
---|
166 | Elf32_Word d_val; /* Integer value. */
|
---|
167 | Elf32_Addr d_ptr; /* Virtual address value. */
|
---|
168 | } d_un;
|
---|
169 | } Elf32_Dyn;
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * Helper macros.
|
---|
173 | */
|
---|
174 | /** The symbol's type. */
|
---|
175 | #define ELF32_ST_TYPE(info) ((info) & 0xF)
|
---|
176 | /** The symbol's binding. */
|
---|
177 | #define ELF32_ST_BIND(info) ((info) >> 4)
|
---|
178 | /** Make st_info. given binding and type. */
|
---|
179 | #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
|
---|
180 |
|
---|
181 | /** Relocation type. */
|
---|
182 | #define ELF32_R_TYPE(info) ((unsigned char)(info))
|
---|
183 | /** Relocation symbol index. */
|
---|
184 | #define ELF32_R_SYM(info) ((info) >> 8)
|
---|
185 | /** Make r_info given the symbol index and type. */
|
---|
186 | #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
|
---|
187 |
|
---|
188 |
|
---|
189 | #endif /* !IPRT_INCLUDED_formats_elf32_h */
|
---|
190 |
|
---|