VirtualBox

source: vbox/trunk/include/iprt/formats/elf64.h@ 62409

Last change on this file since 62409 was 58636, checked in by vboxsync, 9 years ago

include/iprt/format/elf*: copied from Runtime/include/internal/ldrELF*.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: elf64.h 58636 2015-11-10 12:54:50Z vboxsync $ */
2/** @file
3 * IPRT - ELF 64-bit header.
4 */
5
6/*
7 * Copyright (C) 2010-2015 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_formats_elf64_h
28#define ___iprt_formats_elf64_h
29
30#include <iprt/assert.h>
31
32#include "elf-common.h"
33
34/*
35 * ELF 64 standard types.
36 */
37typedef uint64_t Elf64_Addr;
38typedef uint64_t Elf64_Off;
39typedef uint16_t Elf64_Half;
40typedef uint32_t Elf64_Word;
41typedef int32_t Elf64_Sword;
42typedef uint64_t Elf64_Xword;
43typedef int64_t Elf64_Sxword;
44
45/*
46 * Ensure type size correctness in accordance to ELF-64 Object File Format, Version 1.5 Draft 2, p2.
47 */
48AssertCompileSize(Elf64_Addr, 8);
49AssertCompileSize(Elf64_Off, 8);
50AssertCompileSize(Elf64_Half, 2);
51AssertCompileSize(Elf64_Word, 4);
52AssertCompileSize(Elf64_Sword, 4);
53AssertCompileSize(Elf64_Xword, 8);
54AssertCompileSize(Elf64_Sxword, 8);
55
56/*
57 * ELF 64 non-standard types for convenience.
58 */
59typedef Elf64_Xword Elf64_Size;
60typedef Elf64_Word Elf64_Hashelt;
61
62/*
63 * ELF Header.
64 */
65typedef struct
66{
67 unsigned char e_ident[16]; /* ELF identification. */
68 Elf64_Half e_type; /* Object file type. */
69 Elf64_Half e_machine; /* Machine type. */
70 Elf64_Word e_version; /* Object file version. */
71 Elf64_Addr e_entry; /* Entry point address. */
72 Elf64_Off e_phoff; /* Program header offset. */
73 Elf64_Off e_shoff; /* Section header offset. */
74 Elf64_Word e_flags; /* Processor-specific flags. */
75 Elf64_Half e_ehsize; /* ELF header size. */
76 Elf64_Half e_phentsize; /* Size of program header entry. */
77 Elf64_Half e_phnum; /* Number of program header entries. */
78 Elf64_Half e_shentsize; /* Size of section header entry. */
79 Elf64_Half e_shnum; /* Number of section header entries. */
80 Elf64_Half e_shstrndx; /* Section name string table index. */
81} Elf64_Ehdr;
82
83/*
84 * Section header.
85 */
86typedef struct
87{
88 Elf64_Word sh_name; /* Section name. */
89 Elf64_Word sh_type; /* Section type. */
90 Elf64_Xword sh_flags; /* Section attributes. */
91 Elf64_Addr sh_addr; /* Virtual address in memory. */
92 Elf64_Off sh_offset; /* Offset in file. */
93 Elf64_Xword sh_size; /* Size of section. */
94 Elf64_Word sh_link; /* Link to other section. */
95 Elf64_Word sh_info; /* Miscellaneous information. */
96 Elf64_Xword sh_addralign; /* Address alignment boundary. */
97 Elf64_Xword sh_entsize; /* Size of entries, if section has table. */
98} Elf64_Shdr;
99
100/*
101 * Program header.
102 */
103typedef struct
104{
105 Elf64_Word p_type; /* Type of segment. */
106 Elf64_Word p_flags; /* Segment attributes. */
107 Elf64_Off p_offset; /* Offset in file. */
108 Elf64_Addr p_vaddr; /* Virtual address in memory. */
109 Elf64_Addr p_paddr; /* Physical address (reserved). */
110 Elf64_Xword p_filesz; /* Size of segment in file. */
111 Elf64_Xword p_memsz; /* Size of segment in memory. */
112 Elf64_Xword p_align; /* Alignment of segment. */
113} Elf64_Phdr;
114
115/*
116 * Note header.
117 */
118typedef struct
119{
120 Elf64_Word n_namesz; /* Length of note's name. */
121 Elf64_Word n_descsz; /* Length of note's description. */
122 Elf64_Word n_type; /* Type of note. */
123} Elf64_Nhdr;
124
125/*
126 * Symbol table entry.
127 */
128typedef struct
129{
130 Elf64_Word st_name; /* Symbol name. */
131 unsigned char st_info; /* Type and binding attributes. */
132 unsigned char st_other; /* Reserved. */
133 Elf64_Half st_shndx; /* Section header table index. */
134 Elf64_Addr st_value; /* Symbol value. */
135 Elf64_Xword st_size; /* Size associated with symbol. */
136} Elf64_Sym;
137
138/*
139 * Relocations.
140 */
141typedef struct
142{
143 Elf64_Addr r_offset; /* Location to be relocated. */
144 Elf64_Xword r_info; /* Symbol index and type of relocation. */
145} Elf64_Rel;
146
147typedef struct
148{
149 Elf64_Addr r_offset; /* Location to be relocated. */
150 Elf64_Xword r_info; /* Symbol index and type of relocation. */
151 Elf64_Sxword r_addend; /* Constant part of expression. */
152} Elf64_Rela;
153
154/*
155 * Dynamic section entry.
156 * ".dynamic" section contains an array of this.
157 */
158typedef struct
159{
160 Elf64_Sxword d_tag; /* Type of entry. */
161 union
162 {
163 Elf64_Xword d_val; /* Integer value. */
164 Elf64_Addr d_ptr; /* Virtual address value. */
165 } d_un;
166} Elf64_Dyn;
167
168/*
169 * Helper macros.
170 */
171/** The symbol's type. */
172#define ELF64_ST_TYPE(info) ((info) & 0xF)
173/** The symbol's binding. */
174#define ELF64_ST_BIND(info) ((info) >> 4)
175/** Make st_info. given binding and type. */
176#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
177
178/** Relocation type. */
179#define ELF64_R_TYPE(info) ((unsigned char)(info))
180/** Relocation symbol index. */
181#define ELF64_R_SYM(info) ((info) >> 32)
182/** Make r_info given the symbol index and type. */
183#define ELF64_R_INFO(sym, type) (((sym) << 32) + (unsigned char)(type))
184
185
186#endif
187
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette