Usermode/ld-acess - Overhaul cleanup of ELF loader
[tpg/acess2.git] / Usermode / Libraries / ld-acess.so_src / elf64.h
1 /*
2  * Acess2 Dynamic Linker
3  *
4  * elf64.h
5  */
6
7 #ifndef _ELF64_H_
8 #define _ELF64_H_
9
10 #define ELFCLASS64      2
11
12 #define EM_X86_64       62
13
14 typedef uint16_t        Elf64_Half;
15 typedef uint32_t        Elf64_Word;
16
17 typedef uint64_t        Elf64_Addr;
18 typedef uint64_t        Elf64_Off;
19 typedef uint64_t        Elf64_Xword;
20 typedef  int64_t        Elf64_Sxword;
21
22 typedef struct
23 {
24         unsigned char   e_ident[16];
25         Elf64_Half      e_type;
26         Elf64_Half      e_machine;
27         Elf64_Word      e_version;
28         Elf64_Addr      e_entry;
29         Elf64_Off       e_phoff;
30         Elf64_Off       e_shoff;
31         Elf64_Word      e_flags;
32         Elf64_Half      e_ehsize;
33         Elf64_Half      e_phentsize;
34         Elf64_Half      e_phnum;
35         Elf64_Half      e_shentsize;
36         Elf64_Half      e_shnum;
37         Elf64_Half      e_shstrndx;
38 } __attribute__((packed)) Elf64_Ehdr;
39
40 typedef struct
41 {
42         Elf64_Word      sh_name;
43         Elf64_Word      sh_type;
44         Elf64_Xword     sh_flags;
45         Elf64_Addr      sh_addr;
46         Elf64_Off       sh_offset;
47         Elf64_Xword     sh_size;
48         Elf64_Word      sh_link;
49         Elf64_Word      sh_info;
50         Elf64_Xword     sh_addralign;
51         Elf64_Xword     sh_entsize;
52 } Elf64_Shdr;
53
54 typedef struct
55 {
56         Elf64_Word      p_type;
57         Elf64_Word      p_flags;
58         Elf64_Off       p_offset;
59         Elf64_Addr      p_vaddr;
60         Elf64_Addr      p_paddr;
61         Elf64_Xword     p_filesz;
62         Elf64_Xword     p_memsz;
63         Elf64_Xword     p_align;
64 } Elf64_Phdr;
65
66 typedef struct
67 {
68         Elf64_Sxword    d_tag;
69         union {
70                 Elf64_Xword     d_val;
71                 Elf64_Addr      d_ptr;
72         };// d_un;
73 } Elf64_Dyn;
74
75 typedef struct
76 {
77         Elf64_Word      st_name;
78         uint8_t         st_info;
79         uint8_t         st_other;
80         Elf64_Half      st_shndx;
81         Elf64_Addr      st_value;
82         Elf64_Xword     st_size;
83 } Elf64_Sym;
84
85 typedef struct
86 {
87         Elf64_Addr      r_offset;
88         Elf64_Xword     r_info;
89 } Elf64_Rel;
90
91 typedef struct
92 {
93         Elf64_Addr      r_offset;
94         Elf64_Xword     r_info;
95         Elf64_Sxword    r_addend;
96 } Elf64_Rela;
97
98 #define ELF64_R_SYM(info)       ((info) >> 32)
99 #define ELF64_R_TYPE(info)      ((info) & 0xFFFFFFFF)
100 #define ELF64_ST_BIND(i)        ((i)>>4)
101 #define ELF64_ST_TYPE(i)        ((i)&0xF)
102
103 enum eElf64_RelocTypes_x86_64
104 {
105         R_X86_64_NONE,
106         R_X86_64_64,    // 64, S + A
107         R_X86_64_PC32,  // 32, S + A - P
108         R_X86_64_GOT32, // 32, G + A
109         R_X86_64_PLT32, // 32, L + A - P
110         R_X86_64_COPY,
111         R_X86_64_GLOB_DAT,      // 64, S
112         R_X86_64_JUMP_SLOT,     // 64, S
113         R_X86_64_RELATIVE,      // 64, B + A
114         // TODO: Rest
115 };
116
117 #endif
118

UCC git Repository :: git.ucc.asn.au