Skip to main content

libloading/os/unix/
consts.rs

1use core::ffi::c_int;
2
3/// Perform lazy binding.
4///
5/// Relocations shall be performed at an implementation-defined time, ranging from the time
6/// of the [`Library::open`] call until the first reference to a given symbol occurs.
7/// Specifying `RTLD_LAZY` should improve performance on implementations supporting dynamic
8/// symbol binding since a process might not reference all of the symbols in an executable
9/// object file. And, for systems supporting dynamic symbol resolution for normal process
10/// execution, this behaviour mimics the normal handling of process execution.
11///
12/// Conflicts with [`RTLD_NOW`].
13///
14/// [`Library::open`]: crate::os::unix::Library::open
15pub const RTLD_LAZY: c_int = posix::RTLD_LAZY;
16
17/// Perform eager binding.
18///
19/// All necessary relocations shall be performed when the executable object file is first
20/// loaded. This may waste some processing if relocations are performed for symbols
21/// that are never referenced. This behaviour may be useful for applications that need to
22/// know that all symbols referenced during execution will be available before
23/// [`Library::open`] returns.
24///
25/// Conflicts with [`RTLD_LAZY`].
26///
27/// [`Library::open`]: crate::os::unix::Library::open
28pub const RTLD_NOW: c_int = posix::RTLD_NOW;
29
30/// Make loaded symbols available for resolution globally.
31///
32/// The executable object file's symbols shall be made available for relocation processing of any
33/// other executable object file. In addition, calls to [`Library::get`] on `Library` obtained from
34/// [`Library::this`] allows executable object files loaded with this mode to be searched.
35///
36/// [`Library::this`]: crate::os::unix::Library::this
37/// [`Library::get`]: crate::os::unix::Library::get
38pub const RTLD_GLOBAL: c_int = posix::RTLD_GLOBAL;
39
40/// Load symbols into an isolated namespace.
41///
42/// The executable object file's symbols shall not be made available for relocation processing of
43/// any other executable object file. This mode of operation is most appropriate for e.g. plugins.
44pub const RTLD_LOCAL: c_int = posix::RTLD_LOCAL;
45
46#[cfg(all(libloading_docs, not(unix)))]
47mod posix {
48    use super::c_int;
49    pub(super) const RTLD_LAZY: c_int = !0;
50    pub(super) const RTLD_NOW: c_int = !0;
51    pub(super) const RTLD_GLOBAL: c_int = !0;
52    pub(super) const RTLD_LOCAL: c_int = !0;
53}
54
55#[cfg(any(not(libloading_docs), unix))]
56mod posix {
57    use cfg_if::cfg_if;
58    use super::c_int;
59    cfg_if! {
60        if #[cfg(target_os = "haiku")] {
61            pub(super) const RTLD_LAZY: c_int = 0;
62        } else if #[cfg(target_os = "aix")] {
63            pub(super) const RTLD_LAZY: c_int = 4;
64        } else if #[cfg(any(
65            target_os = "linux",
66            target_os = "android",
67            target_os = "emscripten",
68
69            target_os = "macos",
70            target_os = "ios",
71            target_os = "tvos",
72            target_os = "visionos",
73            target_os = "watchos",
74
75            target_os = "freebsd",
76            target_os = "dragonfly",
77            target_os = "openbsd",
78            target_os = "netbsd",
79
80            target_os = "solaris",
81            target_os = "illumos",
82
83            target_env = "uclibc",
84            target_env = "newlib",
85
86            target_os = "fuchsia",
87            target_os = "redox",
88            target_os = "nto",
89            target_os = "hurd",
90            target_os = "cygwin",
91        ))] {
92            pub(super) const RTLD_LAZY: c_int = 1;
93        } else {
94            compile_error!(
95                "Target has no known `RTLD_LAZY` value. Please submit an issue or PR adding it."
96            );
97        }
98    }
99
100    cfg_if! {
101        if #[cfg(target_os = "haiku")] {
102            pub(super) const RTLD_NOW: c_int = 1;
103        } else if #[cfg(any(
104            target_os = "linux",
105            all(target_os = "android", target_pointer_width = "64"),
106            target_os = "emscripten",
107
108            target_os = "macos",
109            target_os = "ios",
110            target_os = "tvos",
111            target_os = "visionos",
112            target_os = "watchos",
113
114            target_os = "freebsd",
115            target_os = "dragonfly",
116            target_os = "openbsd",
117            target_os = "netbsd",
118
119            target_os = "aix",
120            target_os = "solaris",
121            target_os = "illumos",
122
123            target_env = "uclibc",
124            target_env = "newlib",
125
126            target_os = "fuchsia",
127            target_os = "redox",
128            target_os = "nto",
129            target_os = "hurd",
130            target_os = "cygwin",
131        ))] {
132            pub(super) const RTLD_NOW: c_int = 2;
133        } else if #[cfg(all(target_os = "android",target_pointer_width = "32"))] {
134            pub(super) const RTLD_NOW: c_int = 0;
135        } else {
136            compile_error!(
137                "Target has no known `RTLD_NOW` value. Please submit an issue or PR adding it."
138            );
139        }
140    }
141
142    cfg_if! {
143        if #[cfg(any(
144            target_os = "haiku",
145            all(target_os = "android",target_pointer_width = "32"),
146        ))] {
147            pub(super) const RTLD_GLOBAL: c_int = 2;
148        } else if #[cfg(target_os = "aix")] {
149            pub(super) const RTLD_GLOBAL: c_int = 0x10000;
150        } else if #[cfg(any(
151            target_env = "uclibc",
152            all(target_os = "linux", target_arch = "mips"),
153            all(target_os = "linux", target_arch = "mips64"),
154            target_os = "cygwin",
155        ))] {
156            pub(super) const RTLD_GLOBAL: c_int = 4;
157        } else if #[cfg(any(
158            target_os = "macos",
159            target_os = "ios",
160            target_os = "tvos",
161            target_os = "visionos",
162            target_os = "watchos",
163        ))] {
164            pub(super) const RTLD_GLOBAL: c_int = 8;
165        } else if #[cfg(any(
166            target_os = "linux",
167            all(target_os = "android", target_pointer_width = "64"),
168            target_os = "emscripten",
169
170            target_os = "freebsd",
171            target_os = "dragonfly",
172            target_os = "openbsd",
173            target_os = "netbsd",
174
175            target_os = "solaris",
176            target_os = "illumos",
177
178            target_env = "newlib",
179
180            target_os = "fuchsia",
181            target_os = "redox",
182            target_os = "nto",
183            target_os = "hurd",
184        ))] {
185            pub(super) const RTLD_GLOBAL: c_int = 0x100;
186        } else {
187            compile_error!(
188                "Target has no known `RTLD_GLOBAL` value. Please submit an issue or PR adding it."
189            );
190        }
191    }
192
193    cfg_if! {
194        if #[cfg(any(
195           target_os = "netbsd",
196           target_os = "nto",
197        ))] {
198            pub(super) const RTLD_LOCAL: c_int = 0x200;
199        } else if #[cfg(target_os = "aix")] {
200            pub(super) const RTLD_LOCAL: c_int = 0x80000;
201        } else if #[cfg(any(
202            target_os = "macos",
203            target_os = "ios",
204            target_os = "tvos",
205            target_os = "visionos",
206            target_os = "watchos",
207        ))] {
208            pub(super) const RTLD_LOCAL: c_int = 4;
209        } else if #[cfg(any(
210            target_os = "linux",
211            target_os = "android",
212            target_os = "emscripten",
213
214            target_os = "freebsd",
215            target_os = "dragonfly",
216            target_os = "openbsd",
217
218            target_os = "haiku",
219
220            target_os = "solaris",
221            target_os = "illumos",
222
223            target_env = "uclibc",
224            target_env = "newlib",
225
226            target_os = "fuchsia",
227            target_os = "redox",
228            target_os = "hurd",
229            target_os = "cygwin",
230        ))] {
231            pub(super) const RTLD_LOCAL: c_int = 0;
232        } else {
233            compile_error!(
234                "Target has no known `RTLD_LOCAL` value. Please submit an issue or PR adding it."
235            );
236        }
237    }
238}
239
240// Other constants that exist but are not bound because they are platform-specific (non-posix)
241// extensions. Some of these constants are only relevant to `dlsym` or `dlmopen` calls.
242//
243// RTLD_CONFGEN
244// RTLD_DEFAULT
245// RTLD_DI_CONFIGADDR
246// RTLD_DI_LINKMAP
247// RTLD_DI_LMID
248// RTLD_DI_ORIGIN
249// RTLD_DI_PROFILENAME
250// RTLD_DI_PROFILEOUT
251// RTLD_DI_SERINFO
252// RTLD_DI_SERINFOSIZE
253// RTLD_DI_TLS_DATA
254// RTLD_DI_TLS_MODID
255// RTLD_FIRST
256// RTLD_GROUP
257// RTLD_NEXT
258// RTLD_PARENT
259// RTLD_PROBE
260// RTLD_SELF
261// RTLD_WORLD
262// RTLD_NODELETE
263// RTLD_NOLOAD
264// RTLD_DEEPBIND