UbixOS V2  2.0
elf32.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _SYS_ELF32_H_
30 #define _SYS_ELF32_H_ 1
31 
32 #include <sys/elf_common.h>
33 
34 /*
35  * ELF definitions common to all 32-bit architectures.
36  */
37 
44 
46 
47 /* Non-standard class-dependent datatype used for abstraction. */
50 
51 /*
52  * ELF header.
53  */
54 
55 typedef struct {
56  unsigned char e_ident[EI_NIDENT]; /* File identification. */
57  Elf32_Half e_type; /* File type. */
58  Elf32_Half e_machine; /* Machine architecture. */
59  Elf32_Word e_version; /* ELF format version. */
60  Elf32_Addr e_entry; /* Entry point. */
61  Elf32_Off e_phoff; /* Program header file offset. */
62  Elf32_Off e_shoff; /* Section header file offset. */
63  Elf32_Word e_flags; /* Architecture-specific flags. */
64  Elf32_Half e_ehsize; /* Size of ELF header in bytes. */
65  Elf32_Half e_phentsize; /* Size of program header entry. */
66  Elf32_Half e_phnum; /* Number of program header entries. */
67  Elf32_Half e_shentsize; /* Size of section header entry. */
68  Elf32_Half e_shnum; /* Number of section header entries. */
69  Elf32_Half e_shstrndx; /* Section name strings section. */
70 } Elf32_Ehdr;
71 
72 /*
73  * Shared object information, found in SHT_MIPS_LIBLIST.
74  */
75 
76 typedef struct {
77  Elf32_Word l_name; /* The name of a shared object. */
78  Elf32_Word l_time_stamp; /* 32-bit timestamp. */
79  Elf32_Word l_checksum; /* Checksum of visible symbols, sizes. */
80  Elf32_Word l_version; /* Interface version string index. */
81  Elf32_Word l_flags; /* Flags (LL_*). */
82 } Elf32_Lib;
83 
84 /*
85  * Section header.
86  */
87 
88 typedef struct {
89  Elf32_Word sh_name; /* Section name (index into the
90  section header string table). */
91  Elf32_Word sh_type; /* Section type. */
92  Elf32_Word sh_flags; /* Section flags. */
93  Elf32_Addr sh_addr; /* Address in memory image. */
94  Elf32_Off sh_offset; /* Offset in file. */
95  Elf32_Word sh_size; /* Size in bytes. */
96  Elf32_Word sh_link; /* Index of a related section. */
97  Elf32_Word sh_info; /* Depends on section type. */
98  Elf32_Word sh_addralign; /* Alignment in bytes. */
99  Elf32_Word sh_entsize; /* Size of each entry in section. */
100 } Elf32_Shdr;
101 
102 /*
103  * Program header.
104  */
105 
106 typedef struct {
107  Elf32_Word p_type; /* Entry type. */
108  Elf32_Off p_offset; /* File offset of contents. */
109  Elf32_Addr p_vaddr; /* Virtual address in memory image. */
110  Elf32_Addr p_paddr; /* Physical address (not used). */
111  Elf32_Word p_filesz; /* Size of contents in file. */
112  Elf32_Word p_memsz; /* Size of contents in memory. */
113  Elf32_Word p_flags; /* Access permission flags. */
114  Elf32_Word p_align; /* Alignment in memory and file. */
115 } Elf32_Phdr;
116 
117 /*
118  * Dynamic structure. The ".dynamic" section contains an array of them.
119  */
120 
121 typedef struct {
122  Elf32_Sword d_tag; /* Entry type. */
123  union {
124  Elf32_Word d_val; /* Integer value. */
125  Elf32_Addr d_ptr; /* Address value. */
126  } d_un;
127 } Elf32_Dyn;
128 
129 /*
130  * Relocation entries.
131  */
132 
133 /* Relocations that don't need an addend field. */
134 typedef struct {
135  Elf32_Addr r_offset; /* Location to be relocated. */
136  Elf32_Word r_info; /* Relocation type and symbol index. */
137 } Elf32_Rel;
138 
139 /* Relocations that need an addend field. */
140 typedef struct {
141  Elf32_Addr r_offset; /* Location to be relocated. */
142  Elf32_Word r_info; /* Relocation type and symbol index. */
143  Elf32_Sword r_addend; /* Addend. */
144 } Elf32_Rela;
145 
146 /* Macros for accessing the fields of r_info. */
147 #define ELF32_R_SYM(info) ((info) >> 8)
148 #define ELF32_R_TYPE(info) ((unsigned char)(info))
149 
150 /* Macro for constructing r_info from field values. */
151 #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
152 
153 /*
154  * Note entry header
155  */
157 
158 /*
159  * Move entry
160  */
161 typedef struct {
162  Elf32_Lword m_value; /* symbol value */
163  Elf32_Word m_info; /* size + index */
164  Elf32_Word m_poffset; /* symbol offset */
165  Elf32_Half m_repeat; /* repeat count */
166  Elf32_Half m_stride; /* stride info */
167 } Elf32_Move;
168 
169 /*
170  * The macros compose and decompose values for Move.r_info
171  *
172  * sym = ELF32_M_SYM(M.m_info)
173  * size = ELF32_M_SIZE(M.m_info)
174  * M.m_info = ELF32_M_INFO(sym, size)
175  */
176 #define ELF32_M_SYM(info) ((info)>>8)
177 #define ELF32_M_SIZE(info) ((unsigned char)(info))
178 #define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))
179 
180 /*
181  * Hardware/Software capabilities entry
182  */
183 typedef struct {
184  Elf32_Word c_tag; /* how to interpret value */
185  union {
188  } c_un;
189 } Elf32_Cap;
190 
191 /*
192  * Symbol table entries.
193  */
194 
195 typedef struct {
196  Elf32_Word st_name; /* String table index of name. */
197  Elf32_Addr st_value; /* Symbol value. */
198  Elf32_Word st_size; /* Size of associated object. */
199  unsigned char st_info; /* Type and binding information. */
200  unsigned char st_other; /* Reserved (not used). */
201  Elf32_Half st_shndx; /* Section index of symbol. */
202 } Elf32_Sym;
203 
204 /* Macros for accessing the fields of st_info. */
205 #define ELF32_ST_BIND(info) ((info) >> 4)
206 #define ELF32_ST_TYPE(info) ((info) & 0xf)
207 
208 /* Macro for constructing st_info from field values. */
209 #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
210 
211 /* Macro for accessing the fields of st_other. */
212 #define ELF32_ST_VISIBILITY(oth) ((oth) & 0x3)
213 
214 /* Structures used by Sun & GNU symbol versioning. */
215 typedef struct {
223 } Elf32_Verdef;
224 
225 typedef struct {
228 } Elf32_Verdaux;
229 
230 typedef struct {
236 } Elf32_Verneed;
237 
238 typedef struct {
244 } Elf32_Vernaux;
245 
247 
248 typedef struct {
249  Elf32_Half si_boundto; /* direct bindings - symbol bound to */
250  Elf32_Half si_flags; /* per symbol flags */
251 } Elf32_Syminfo;
252 
253 typedef struct {
257 } Elf32_Chdr;
258 
259 #endif /* END _SYS_ELF32_H */
Elf32_Dyn::d_val
Elf32_Word d_val
Definition: elf32.h:124
Elf32_Hashelt
Elf32_Word Elf32_Hashelt
Definition: elf32.h:45
Elf32_Verneed::vn_file
Elf32_Word vn_file
Definition: elf32.h:233
Elf32_Shdr::sh_type
Elf32_Word sh_type
Definition: elf32.h:91
Elf32_Verneed
Definition: elf32.h:230
Elf32_Ehdr::e_version
Elf32_Word e_version
Definition: elf32.h:59
Elf32_Syminfo::si_flags
Elf32_Half si_flags
Definition: elf32.h:250
Elf32_Rela::r_offset
Elf32_Addr r_offset
Definition: elf32.h:141
Elf32_Shdr::sh_size
Elf32_Word sh_size
Definition: elf32.h:95
Elf32_Phdr::p_align
Elf32_Word p_align
Definition: elf32.h:114
Elf32_Cap::c_tag
Elf32_Word c_tag
Definition: elf32.h:184
Elf32_Dyn
Definition: elf32.h:121
Elf32_Sym::st_value
Elf32_Addr st_value
Definition: elf32.h:197
Elf32_Lib
Definition: elf32.h:76
Elf32_Ehdr::e_ehsize
Elf32_Half e_ehsize
Definition: elf32.h:64
Elf32_Nhdr
Elf_Note Elf32_Nhdr
Definition: elf32.h:156
Elf32_Vernaux::vna_name
Elf32_Word vna_name
Definition: elf32.h:242
Elf32_Rel
Definition: elf32.h:134
Elf32_Ehdr::e_phoff
Elf32_Off e_phoff
Definition: elf32.h:61
Elf32_Shdr::sh_addr
Elf32_Addr sh_addr
Definition: elf32.h:93
Elf32_Phdr::p_memsz
Elf32_Word p_memsz
Definition: elf32.h:112
Elf32_Shdr::sh_entsize
Elf32_Word sh_entsize
Definition: elf32.h:99
Elf32_Verneed::vn_cnt
Elf32_Half vn_cnt
Definition: elf32.h:232
Elf_Note
Definition: elf_common.h:45
Elf32_Chdr::ch_size
Elf32_Word ch_size
Definition: elf32.h:255
uint64_t
__uint64_t uint64_t
Definition: types.h:47
Elf32_Shdr::sh_offset
Elf32_Off sh_offset
Definition: elf32.h:94
Elf32_Verdef::vd_flags
Elf32_Half vd_flags
Definition: elf32.h:217
Elf32_Cap::c_val
Elf32_Word c_val
Definition: elf32.h:186
Elf32_Off
uint32_t Elf32_Off
Definition: elf32.h:40
Elf32_Ehdr::e_shentsize
Elf32_Half e_shentsize
Definition: elf32.h:67
Elf32_Vernaux::vna_hash
Elf32_Word vna_hash
Definition: elf32.h:239
Elf32_Vernaux
Definition: elf32.h:238
Elf32_Verdef::vd_aux
Elf32_Word vd_aux
Definition: elf32.h:221
Elf32_Sword
int32_t Elf32_Sword
Definition: elf32.h:41
Elf32_Verdef::vd_version
Elf32_Half vd_version
Definition: elf32.h:216
Elf32_Versym
Elf32_Half Elf32_Versym
Definition: elf32.h:246
Elf32_Phdr::p_type
Elf32_Word p_type
Definition: elf32.h:107
Elf32_Verdef
Definition: elf32.h:215
Elf32_Ssize
Elf32_Sword Elf32_Ssize
Definition: elf32.h:49
Elf32_Move::m_repeat
Elf32_Half m_repeat
Definition: elf32.h:165
Elf32_Move::m_value
Elf32_Lword m_value
Definition: elf32.h:162
Elf32_Syminfo
Definition: elf32.h:248
Elf32_Ehdr::e_shoff
Elf32_Off e_shoff
Definition: elf32.h:62
Elf32_Phdr::p_offset
Elf32_Off p_offset
Definition: elf32.h:108
Elf32_Ehdr::e_flags
Elf32_Word e_flags
Definition: elf32.h:63
Elf32_Lib::l_version
Elf32_Word l_version
Definition: elf32.h:80
Elf32_Phdr::p_vaddr
Elf32_Addr p_vaddr
Definition: elf32.h:109
Elf32_Move::m_info
Elf32_Word m_info
Definition: elf32.h:163
Elf32_Phdr::p_paddr
Elf32_Addr p_paddr
Definition: elf32.h:110
Elf32_Verneed::vn_next
Elf32_Word vn_next
Definition: elf32.h:235
Elf32_Lib::l_time_stamp
Elf32_Word l_time_stamp
Definition: elf32.h:78
uint16_t
__uint16_t uint16_t
Definition: types.h:45
Elf32_Shdr::sh_flags
Elf32_Word sh_flags
Definition: elf32.h:92
Elf32_Verdaux::vda_next
Elf32_Word vda_next
Definition: elf32.h:227
Elf32_Move
Definition: elf32.h:161
Elf32_Cap::c_ptr
Elf32_Addr c_ptr
Definition: elf32.h:187
Elf32_Ehdr::e_shstrndx
Elf32_Half e_shstrndx
Definition: elf32.h:69
Elf32_Sym::st_other
unsigned char st_other
Definition: elf32.h:200
Elf32_Phdr::p_filesz
Elf32_Word p_filesz
Definition: elf32.h:111
Elf32_Lib::l_checksum
Elf32_Word l_checksum
Definition: elf32.h:79
Elf32_Chdr::ch_addralign
Elf32_Word ch_addralign
Definition: elf32.h:256
Elf32_Lib::l_flags
Elf32_Word l_flags
Definition: elf32.h:81
Elf32_Verdef::vd_hash
Elf32_Word vd_hash
Definition: elf32.h:220
Elf32_Ehdr::e_entry
Elf32_Addr e_entry
Definition: elf32.h:60
Elf32_Sym::st_name
Elf32_Word st_name
Definition: elf32.h:196
Elf32_Phdr
Definition: elf32.h:106
Elf32_Vernaux::vna_next
Elf32_Word vna_next
Definition: elf32.h:243
Elf32_Size
Elf32_Word Elf32_Size
Definition: elf32.h:48
uint32_t
__uint32_t uint32_t
Definition: types.h:46
Elf32_Ehdr::e_machine
Elf32_Half e_machine
Definition: elf32.h:58
Elf32_Verdef::vd_cnt
Elf32_Half vd_cnt
Definition: elf32.h:219
Elf32_Phdr::p_flags
Elf32_Word p_flags
Definition: elf32.h:113
int32_t
__int32_t int32_t
Definition: types.h:108
Elf32_Sym::st_shndx
Elf32_Half st_shndx
Definition: elf32.h:201
Elf32_Lib::l_name
Elf32_Word l_name
Definition: elf32.h:77
Elf32_Verdaux::vda_name
Elf32_Word vda_name
Definition: elf32.h:226
Elf32_Vernaux::vna_flags
Elf32_Half vna_flags
Definition: elf32.h:240
EI_NIDENT
#define EI_NIDENT
Definition: elf_common.h:130
Elf32_Verdef::vd_next
Elf32_Word vd_next
Definition: elf32.h:222
Elf32_Shdr::sh_name
Elf32_Word sh_name
Definition: elf32.h:89
Elf32_Dyn::d_ptr
Elf32_Addr d_ptr
Definition: elf32.h:125
Elf32_Addr
uint32_t Elf32_Addr
Definition: elf32.h:38
Elf32_Verneed::vn_aux
Elf32_Word vn_aux
Definition: elf32.h:234
Elf32_Chdr::ch_type
Elf32_Word ch_type
Definition: elf32.h:254
Elf32_Syminfo::si_boundto
Elf32_Half si_boundto
Definition: elf32.h:249
Elf32_Ehdr
Definition: elf32.h:55
Elf32_Shdr
Definition: elf32.h:88
Elf32_Rela::r_info
Elf32_Word r_info
Definition: elf32.h:142
Elf32_Ehdr::e_shnum
Elf32_Half e_shnum
Definition: elf32.h:68
Elf32_Chdr
Definition: elf32.h:253
Elf32_Verneed::vn_version
Elf32_Half vn_version
Definition: elf32.h:231
elf_common.h
Elf32_Dyn::d_tag
Elf32_Sword d_tag
Definition: elf32.h:122
Elf32_Move::m_stride
Elf32_Half m_stride
Definition: elf32.h:166
Elf32_Rela::r_addend
Elf32_Sword r_addend
Definition: elf32.h:143
Elf32_Cap
Definition: elf32.h:183
Elf32_Shdr::sh_addralign
Elf32_Word sh_addralign
Definition: elf32.h:98
Elf32_Word
uint32_t Elf32_Word
Definition: elf32.h:42
Elf32_Ehdr::e_phentsize
Elf32_Half e_phentsize
Definition: elf32.h:65
Elf32_Sym::st_size
Elf32_Word st_size
Definition: elf32.h:198
Elf32_Ehdr::e_type
Elf32_Half e_type
Definition: elf32.h:57
Elf32_Move::m_poffset
Elf32_Word m_poffset
Definition: elf32.h:164
Elf32_Vernaux::vna_other
Elf32_Half vna_other
Definition: elf32.h:241
Elf32_Rela
Definition: elf32.h:140
Elf32_Sym::st_info
unsigned char st_info
Definition: elf32.h:199
Elf32_Shdr::sh_link
Elf32_Word sh_link
Definition: elf32.h:96
Elf32_Shdr::sh_info
Elf32_Word sh_info
Definition: elf32.h:97
Elf32_Verdef::vd_ndx
Elf32_Half vd_ndx
Definition: elf32.h:218
Elf32_Half
uint16_t Elf32_Half
Definition: elf32.h:39
Elf32_Sym
Definition: elf32.h:195
Elf32_Verdaux
Definition: elf32.h:225
Elf32_Lword
uint64_t Elf32_Lword
Definition: elf32.h:43
Elf32_Rel::r_info
Elf32_Word r_info
Definition: elf32.h:136
Elf32_Rel::r_offset
Elf32_Addr r_offset
Definition: elf32.h:135
Elf32_Ehdr::e_phnum
Elf32_Half e_phnum
Definition: elf32.h:66