Home

RTLDNEXT

RTLD_NEXT is a special handle defined in the dynamic linking interface (dlfcn.h) that can be passed to the symbol resolution function dlsym to locate the next occurrence of a symbol after the current object in the shared object dependency chain. It is primarily used to implement function interposition in shared libraries, allowing a library to wrap or override a symbol provided by lower layers and then delegate to the original version.

Usage and behavior: include <dlfcn.h>. When implementing a replacement for a library function, obtain the address

Comparison with other handles: RTLD_NEXT is distinct from RTLD_DEFAULT, which asks the linker to search all

Limitations and portability: RTLD_NEXT is a GNU extension and is available on platforms with glibc or compatible

See also: dlfcn.h, dlsym, RTLD_DEFAULT.

of
the
next
symbol
by
calling
dlsym(RTLD_NEXT,
"function_name").
You
can
then
call
through
to
that
address,
typically
after
performing
any
pre-
or
post-processing.
For
example,
a
wrapped
open
function
might
resolve
the
original
as
int
(*real_open)(const
char*,
int,
mode_t)
=
dlsym(RTLD_NEXT,
"open");
and
then
call
real_open
with
the
appropriate
arguments.
RTLD_NEXT
ensures
the
search
skips
the
current
object,
referencing
the
next
definition
in
the
chain
rather
than
the
one
in
the
same
object.
available
objects
for
a
symbol,
and
from
using
an
explicit
handle
obtained
via
dlopen.
RTLD_NEXT
is
specifically
for
walking
the
link
chain
in
interposition
scenarios.
dynamic
linkers.
Its
behavior
is
not
defined
for
static
linking
or
outside
the
dynamic
loader
context,
and
its
availability
may
vary
across
non-ELF
or
non-GNU
systems.
Developers
should
check
platform
documentation
when
portability
is
a
concern.