xref: /PHP-8.0/ext/opcache/jit/zend_elf.h (revision 6322b6ff)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend JIT                                                             |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Dmitry Stogov <dmitry@php.net>                              |
16    |          Xinchen Hui <laruence@php.net>                              |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef ZEND_ELF
21 #define ZEND_ELF
22 
23 #if SIZEOF_SIZE_T == 8
24 # define ELF64
25 #else
26 # undef ELF64
27 #endif
28 
29 typedef struct _zend_elf_header {
30 	uint8_t   emagic[4];
31 	uint8_t   eclass;
32 	uint8_t   eendian;
33 	uint8_t   eversion;
34 	uint8_t   eosabi;
35 	uint8_t   eabiversion;
36 	uint8_t   epad[7];
37 	uint16_t  type;
38 	uint16_t  machine;
39 	uint32_t  version;
40 	uintptr_t entry;
41 	uintptr_t phofs;
42 	uintptr_t shofs;
43 	uint32_t  flags;
44 	uint16_t  ehsize;
45 	uint16_t  phentsize;
46 	uint16_t  phnum;
47 	uint16_t  shentsize;
48 	uint16_t  shnum;
49 	uint16_t  shstridx;
50 } zend_elf_header;
51 
52 typedef struct zend_elf_sectheader {
53 	uint32_t  name;
54 	uint32_t  type;
55 	uintptr_t flags;
56 	uintptr_t addr;
57 	uintptr_t ofs;
58 	uintptr_t size;
59 	uint32_t  link;
60 	uint32_t  info;
61 	uintptr_t align;
62 	uintptr_t entsize;
63 } zend_elf_sectheader;
64 
65 #define ELFSECT_IDX_ABS     0xfff1
66 
67 enum {
68 	ELFSECT_TYPE_PROGBITS = 1,
69 	ELFSECT_TYPE_SYMTAB = 2,
70 	ELFSECT_TYPE_STRTAB = 3,
71 	ELFSECT_TYPE_NOBITS = 8,
72 	ELFSECT_TYPE_DYNSYM = 11,
73 };
74 
75 #define ELFSECT_FLAGS_WRITE (1 << 0)
76 #define ELFSECT_FLAGS_ALLOC (1 << 1)
77 #define ELFSECT_FLAGS_EXEC  (1 << 2)
78 #define ELFSECT_FLAGS_TLS   (1 << 10)
79 
80 typedef struct zend_elf_symbol {
81 #ifdef ELF64
82 	uint32_t  name;
83 	uint8_t   info;
84 	uint8_t   other;
85 	uint16_t  sectidx;
86 	uintptr_t value;
87 	uint64_t  size;
88 #else
89 	uint32_t  name;
90 	uintptr_t value;
91 	uint32_t  size;
92 	uint8_t   info;
93 	uint8_t   other;
94 	uint16_t  sectidx;
95 #endif
96 } zend_elf_symbol;
97 
98 #define ELFSYM_BIND(info)       ((info) >> 4)
99 #define ELFSYM_TYPE(info)       ((info) & 0xf)
100 #define ELFSYM_INFO(bind, type) (((bind) << 4) | (type))
101 
102 enum {
103 	ELFSYM_TYPE_DATA = 2,
104 	ELFSYM_TYPE_FUNC = 2,
105 	ELFSYM_TYPE_FILE = 4,
106 };
107 
108 enum {
109 	ELFSYM_BIND_LOCAL  = 0,
110 	ELFSYM_BIND_GLOBAL = 1,
111 };
112 
113 void zend_elf_load_symbols(void);
114 
115 #endif
116