xref: /plan9/sys/src/libmach/elf.h (revision 4439694f4201945b1468b22da393c4f0ad5bf493)
1 /*
2  *	Definitions needed for accessing ELF headers
3  */
4 typedef struct {
5 	uchar	ident[16];	/* ident bytes */
6 	ushort	type;		/* file type */
7 	ushort	machine;	/* target machine */
8 	int	version;	/* file version */
9 	ulong	elfentry;	/* start address */
10 	ulong	phoff;		/* phdr file offset */
11 	ulong	shoff;		/* shdr file offset */
12 	int	flags;		/* file flags */
13 	ushort	ehsize;		/* sizeof ehdr */
14 	ushort	phentsize;	/* sizeof phdr */
15 	ushort	phnum;		/* number phdrs */
16 	ushort	shentsize;	/* sizeof shdr */
17 	ushort	shnum;		/* number shdrs */
18 	ushort	shstrndx;	/* shdr string index */
19 } Ehdr;
20 
21 typedef struct {
22 	u8int	ident[16];	/* ident bytes */
23 	u16int	type;		/* file type */
24 	u16int	machine;	/* target machine */
25 	u32int	version;	/* file version */
26 	u64int	elfentry;	/* start address */
27 	u64int	phoff;		/* phdr file offset */
28 	u64int	shoff;		/* shdr file offset */
29 	u32int	flags;		/* file flags */
30 	u16int	ehsize;		/* sizeof ehdr */
31 	u16int	phentsize;	/* sizeof phdr */
32 	u16int	phnum;		/* number phdrs */
33 	u16int	shentsize;	/* sizeof shdr */
34 	u16int	shnum;		/* number shdrs */
35 	u16int	shstrndx;	/* shdr string index */
36 } E64hdr;
37 
38 typedef struct {
39 	int	type;		/* entry type */
40 	ulong	offset;		/* file offset */
41 	ulong	vaddr;		/* virtual address */
42 	ulong	paddr;		/* physical address */
43 	int	filesz;		/* file size */
44 	ulong	memsz;		/* memory size */
45 	int	flags;		/* entry flags */
46 	int	align;		/* memory/file alignment */
47 } Phdr;
48 
49 typedef struct {
50 	u32int	type;		/* entry type */
51 	u32int	flags;		/* entry flags */
52 	u64int	offset;		/* file offset */
53 	u64int	vaddr;		/* virtual address */
54 	u64int	paddr;		/* physical address */
55 	u64int	filesz;		/* file size */
56 	u64int	memsz;		/* memory size */
57 	u64int	align;		/* memory/file alignment */
58 } P64hdr;
59 
60 typedef struct {
61 	ulong	name;		/* section name */
62 	ulong	type;		/* SHT_... */
63 	ulong	flags;		/* SHF_... */
64 	ulong	addr;		/* virtual address */
65 	ulong	offset;		/* file offset */
66 	ulong	size;		/* section size */
67 	ulong	link;		/* misc info */
68 	ulong	info;		/* misc info */
69 	ulong	addralign;	/* memory alignment */
70 	ulong	entsize;	/* entry size if table */
71 } Shdr;
72 
73 typedef struct {
74 	u32int	name;		/* section name */
75 	u32int	type;		/* SHT_... */
76 	u64int	flags;		/* SHF_... */
77 	u64int	addr;		/* virtual address */
78 	u64int	offset;		/* file offset */
79 	u64int	size;		/* section size */
80 	u32int	link;		/* misc info */
81 	u32int	info;		/* misc info */
82 	u64int	addralign;	/* memory alignment */
83 	u64int	entsize;	/* entry size if table */
84 } S64hdr;
85 
86 enum {
87 	/* Ehdr codes */
88 	MAG0 = 0,		/* ident[] indexes */
89 	MAG1 = 1,
90 	MAG2 = 2,
91 	MAG3 = 3,
92 	CLASS = 4,
93 	DATA = 5,
94 	VERSION = 6,
95 
96 	ELFCLASSNONE = 0,	/* ident[CLASS] */
97 	ELFCLASS32 = 1,
98 	ELFCLASS64 = 2,
99 	ELFCLASSNUM = 3,
100 
101 	ELFDATANONE = 0,	/* ident[DATA] */
102 	ELFDATA2LSB = 1,
103 	ELFDATA2MSB = 2,
104 	ELFDATANUM = 3,
105 
106 	NOETYPE = 0,		/* type */
107 	REL = 1,
108 	EXEC = 2,
109 	DYN = 3,
110 	CORE = 4,
111 
112 	NONE = 0,		/* machine */
113 	M32 = 1,		/* AT&T WE 32100 */
114 	SPARC = 2,		/* Sun SPARC */
115 	I386 = 3,		/* Intel 80386 */
116 	M68K = 4,		/* Motorola 68000 */
117 	M88K = 5,		/* Motorola 88000 */
118 	I486 = 6,		/* Intel 80486 */
119 	I860 = 7,		/* Intel i860 */
120 	MIPS = 8,		/* Mips R2000 */
121 	S370 = 9,		/* Amdhal	*/
122 	MIPSR4K = 10,		/* Mips R4000 */
123 	SPARC64 = 18,		/* Sun SPARC v9 */
124 	POWER = 20,		/* PowerPC */
125 	POWER64 = 21,		/* PowerPC64 */
126 	ARM = 40,		/* ARM */
127 	AMD64 = 62,		/* Amd64 */
128 	ARM64 = 183,		/* ARM64 */
129 
130 	NO_VERSION = 0,		/* version, ident[VERSION] */
131 	CURRENT = 1,
132 
133 	/* Phdr Codes */
134 	NOPTYPE = 0,		/* type */
135 	LOAD = 1,
136 	DYNAMIC = 2,
137 	INTERP = 3,
138 	NOTE = 4,
139 	SHLIB = 5,
140 	PHDR = 6,
141 
142 	R = 0x4,		/* flags */
143 	W = 0x2,
144 	X = 0x1,
145 
146 	/* Shdr Codes */
147 	Progbits = 1,	/* section types */
148 	Strtab = 3,
149 	Nobits = 8,
150 
151 	Swrite = 1,	/* section attributes */
152 	Salloc = 2,
153 	Sexec = 4,
154 };
155 
156 #define	ELF_MAG		((0x7f<<24) | ('E'<<16) | ('L'<<8) | 'F')
157