VirtualBox

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

Last change on this file since 76316 was 69105, checked in by vboxsync, 7 years ago

include/iprt/: (C) year

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