The OpenD Programming Language

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