1 /**
2 * D header file for GNU/Linux
3 *
4 * $(LINK2 http://sourceware.org/git/?p=glibc.git;a=blob;f=elf/link.h, glibc elf/link.h)
5 */
6 module core.sys.linux.link;
7
8 version (linux):
9 extern (C):
10 nothrow:
11 @system:
12
13 version (ARM) version = ARM_Any;
14 version (AArch64) version = ARM_Any;
15 version (HPPA) version = HPPA_Any;
16 version (MIPS32) version = MIPS_Any;
17 version (MIPS64) version = MIPS_Any;
18 version (PPC) version = PPC_Any;
19 version (PPC64) version = PPC_Any;
20 version (RISCV32) version = RISCV_Any;
21 version (RISCV64) version = RISCV_Any;
22 version (S390) version = IBMZ_Any;
23 version (SPARC) version = SPARC_Any;
24 version (SPARC64) version = SPARC_Any;
25 version (SystemZ) version = IBMZ_Any;
26 version (X86) version = X86_Any;
27 version (X86_64) version = X86_Any;
28
29 import core.stdc.stdint : uintptr_t, uint32_t, uint64_t;
30 import core.sys.linux.config : __WORDSIZE;
31 import core.sys.linux.dlfcn : Lmid_t;
32 import core.sys.linux.elf;
33
34 // <bits/elfclass.h>
version(Android)35 version (Android)
36 {
37 alias __WORDSIZE __ELF_NATIVE_CLASS;
38 version (D_LP64)
39 alias uint64_t Elf_Symndx;
40 else
41 alias uint32_t Elf_Symndx;
42 }
version(X86_Any)43 else version (X86_Any)
44 {
45 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
46 alias __WORDSIZE __ELF_NATIVE_CLASS;
47 alias uint32_t Elf_Symndx;
48 }
version(HPPA_Any)49 else version (HPPA_Any)
50 {
51 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
52 alias __WORDSIZE __ELF_NATIVE_CLASS;
53 alias uint32_t Elf_Symndx;
54 }
version(MIPS_Any)55 else version (MIPS_Any)
56 {
57 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
58 alias __WORDSIZE __ELF_NATIVE_CLASS;
59 alias uint32_t Elf_Symndx;
60 }
version(PPC_Any)61 else version (PPC_Any)
62 {
63 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
64 alias __WORDSIZE __ELF_NATIVE_CLASS;
65 alias uint32_t Elf_Symndx;
66 }
version(ARM_Any)67 else version (ARM_Any)
68 {
69 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
70 alias __WORDSIZE __ELF_NATIVE_CLASS;
71 alias uint32_t Elf_Symndx;
72 }
version(RISCV_Any)73 else version (RISCV_Any)
74 {
75 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
76 alias __WORDSIZE __ELF_NATIVE_CLASS;
77 alias uint32_t Elf_Symndx;
78 }
version(SPARC_Any)79 else version (SPARC_Any)
80 {
81 // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
82 alias __WORDSIZE __ELF_NATIVE_CLASS;
83 alias uint32_t Elf_Symndx;
84 }
version(IBMZ_Any)85 else version (IBMZ_Any)
86 {
87 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/s390/bits/elfclass.h
88 alias __WORDSIZE __ELF_NATIVE_CLASS;
89 static if (__WORDSIZE == 64)
90 alias uint64_t Elf_Symndx;
91 else
92 alias uint32_t Elf_Symndx;
93 }
94 else
95 static assert(0, "unimplemented");
96 // <bits/elfclass.h>
97
ElfW(string type)98 template ElfW(string type)
99 {
100 mixin("alias Elf"~__ELF_NATIVE_CLASS.stringof~"_"~type~" ElfW;");
101 }
102
103 enum
104 {
105 RT_CONSISTENT,
106 RT_ADD,
107 RT_DELETE,
108 }
109
110 struct r_debug
111 {
112 int r_version;
113 link_map* r_map;
114 ElfW!"Addr" r_brk;
115 typeof(RT_CONSISTENT) r_state;
116 ElfW!"Addr" r_ldbase;
117 }
118
119 extern r_debug _r_debug;
120 extern ElfW!"Dyn"* _DYNAMIC;
121
122 struct link_map
123 {
124 ElfW!"Addr" l_addr;
125 char* l_name;
126 ElfW!"Dyn"* l_ld;
127 link_map* l_next, l_prev;
128 }
129
130 enum
131 {
132 LA_ACT_CONSISTENT,
133 LA_ACT_ADD,
134 LA_ACT_DELETE,
135 }
136
137 enum
138 {
139 LA_SER_ORIG = 0x01,
140 LA_SER_LIBPATH = 0x02,
141 LA_SER_RUNPATH = 0x04,
142 LA_SER_CONFIG = 0x08,
143 LA_SER_DEFAULT = 0x40,
144 LA_SER_SECURE = 0x80,
145 }
146
147
148 enum
149 {
150 LA_FLG_BINDTO = 0x01,
151 LA_FLG_BINDFROM = 0x02,
152 }
153
154
155 enum
156 {
157 LA_SYMB_NOPLTENTER = 0x01,
158 LA_SYMB_NOPLTEXIT = 0x02,
159 LA_SYMB_STRUCTCALL = 0x04,
160 LA_SYMB_DLSYM = 0x08,
161 LA_SYMB_ALTVALUE = 0x10,
162 }
163
164 struct dl_phdr_info
165 {
166 ElfW!"Addr" dlpi_addr;
167 const(char)* dlpi_name;
168 const(ElfW!"Phdr")* dlpi_phdr;
169 ElfW!"Half" dlpi_phnum;
170
171 // check the SIZE argument of the dl_iterate_phdr callback whether
172 // the following members are available
173 ulong dlpi_adds;
174 ulong dlpi_subs;
175
176 size_t dlpi_tls_modid;
177 void *dlpi_tls_data;
178 }
179
180 private alias extern(C) int function(dl_phdr_info*, size_t, void *) dl_iterate_phdr_cb;
181 private alias extern(C) int function(dl_phdr_info*, size_t, void *) @nogc dl_iterate_phdr_cb_ngc;
182 extern int dl_iterate_phdr(dl_iterate_phdr_cb __callback, void*__data);
183 extern int dl_iterate_phdr(dl_iterate_phdr_cb_ngc __callback, void*__data) @nogc;
184
185 // ld.so auditing interfaces prototypes have to be defined by the auditing DSO.
186 extern uint la_version(uint __version);
187 extern void la_activity(uintptr_t *__cookie, uint __flag);
188 extern char* la_objsearch(const(char)* __name, uintptr_t* __cookie,
189 uint __flag);
190 extern uint la_objopen(link_map* __map, Lmid_t __lmid,
191 uintptr_t* __cookie);
192 extern void la_preinit(uintptr_t* __cookie);
193 extern uintptr_t la_symbind32(Elf32_Sym* __sym, uint __ndx,
194 uintptr_t* __refcook, uintptr_t* __defcook,
195 uint *__flags, const(char)* __symname);
196 extern uintptr_t la_symbind64(Elf64_Sym* __sym, uint __ndx,
197 uintptr_t* __refcook, uintptr_t* __defcook,
198 uint* __flags, const(char)* __symname);
199 extern uint la_objclose(uintptr_t *__cookie);
200