Dynamic loading v0.1.0
RTLD_LAZY
pub const RTLD_LAZY: int32 = 1;
RTLD_LAZY: resolve a function symbol the first time it is called rather than at load.
RTLD_NOW
pub const RTLD_NOW: int32 = 2;
RTLD_NOW: resolve every symbol before dlopen returns.
RTLD_LOCAL
pub const RTLD_LOCAL: int32 = 4;
RTLD_LOCAL: keep this object's symbols to itself, which is Darwin's default.
Darwin numbers this 4 and RTLD_GLOBAL 8, where both Linux and FreeBSD use 0 and 256. Carrying either value
between packages selects the opposite of what was meant.
RTLD_GLOBAL
pub const RTLD_GLOBAL: int32 = 8;
RTLD_GLOBAL: make this object's symbols available to objects loaded afterwards.
SystemLib
pub const SystemLib = "libSystem.B.dylib";
The library every Darwin interface is reached through.
A single dynamic library re-exporting libc, libm, libpthread and the rest; there is no separate libc.dylib to
link on Apple platforms.
dlopen
pub extern func dlopen(
filename: *char8,
flags: int32
) -> *var opaque
Loads a shared object and returns a handle to it, or null on failure.
A name without a slash is resolved by the loader's own search rules, and one with a slash as a path. A second
call for an object already loaded returns the same handle and raises its reference count rather than loading
it twice. Failure is reported through dlerror, not errno.
See also: https://keith.github.io/xcode-man-pages/dlopen.3.html
Parameters
| Name | Type | Description |
|---|---|---|
filename | *char8 | a NUL-terminated name or path, or null for the main program |
flags | int32 | RTLD_LAZY or RTLD_NOW, combined with the other RTLD_* flags |
Returns: a handle for dlsym and dlclose, or null with the reason in dlerror
dlsym
pub extern func dlsym(
handle: *var opaque,
symbol: *char8
) -> *var opaque
Finds a symbol in a loaded object and returns its address, or null.
A null return is ambiguous, since a symbol whose address is legitimately zero exists. Clear dlerror by calling
it, then call this, then read dlerror again to tell the two apart.
See also: https://keith.github.io/xcode-man-pages/dlsym.3.html
Parameters
| Name | Type | Description |
|---|---|---|
handle | *var opaque | a handle from dlopen |
symbol | *char8 | the NUL-terminated symbol name |
Returns: the symbol's address, or null
dlclose
pub extern func dlclose(handle: *var opaque) -> int32
Drops one reference to a loaded object, unloading it when the last one goes.
Every address obtained from the object through dlsym becomes invalid once it is actually unloaded, which this
gives no way to observe.
See also: https://keith.github.io/xcode-man-pages/dlclose.3.html
Parameters
| Name | Type | Description |
|---|---|---|
handle | *var opaque | a handle from dlopen |
Returns: zero on success, and non-zero with the reason in dlerror
dlerror
pub extern func dlerror() -> *char8
Reports the most recent loader error and clears it, or returns null when there is none. The message points at storage the loader owns and a later call may reuse. Reading it clears the error, so two calls in a row report the second as no error at all.
See also: https://keith.github.io/xcode-man-pages/dlerror.3.html
Returns: a NUL-terminated message, or null