RTLD-AUDIT(7)
โจ rtld-audit โ auditing API for the dynamic linker โจ
okay so bestie, welcome to rtld-audit, section 7 of the manual (miscellaneous info manual, if ur keeping track). this is the whole tea on how the GNU dynamic linker lets u spy on all the dynamic linking events happening in ur program. it's giving main character energy for shared libraries fr fr ๐
๐ธ SYNOPSIS ๐ธ
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <link.h>
๐ DESCRIPTION ๐
so basically, the GNU dynamic linker (aka the run-time linker, the one that does all the last-minute linking when ur program starts up) has this whole auditing API. it lets an application get notified whenever various dynamic linking events go down. and girl, it's very similar to the auditing interface that the Solaris run-time linker provides โ like, they're cousins. the constants and prototypes u need are all defined by including <link.h>.
to actually use this interface, u (the programmer, the icon, the legend) create a shared library that implements a standard set of function names. and here's the slay part: not all of the functions need to be implemented. in most cases, if ur not interested in a particular class of auditing event, u justโฆ don't implement the corresponding auditing function. no biggie. no pressure. ๐ซถ
to employ the auditing interface, the environment variable LD_AUDIT must be defined to contain a colon-separated list of shared libraries, each of which can implement (parts of) the auditing API. when an auditable event occurs, the corresponding function is invoked in each library, in the order that the libraries are listed. periodt. ๐
๐ฆ la_version() ๐ฆ
unsigned int la_version(unsigned int version);
this is the only function that MUST be defined by an auditing library. it's the initial handshake between the dynamic linker and the auditing library โ like the first "hey bestie" at the function level. when invoking this function, the dynamic linker passes, in version, the highest version of the auditing interface that the linker supports.
a typical implementation of this function simply returns the constant LAV_CURRENT, which indicates the version of <link.h> that was used to build the audit module. if the dynamic linker does not support this version of the audit interface, it will refuse to activate this audit module. and if the function returns zero, the dynamic linker also does not activate this audit module. so yeah, returning 0 is a no from the linker ๐
in order to enable backwards compatibility with older dynamic linkers, an audit module can examine the version argument and return an earlier version than LAV_CURRENT, assuming the module can adjust its implementation to match the requirements of the previous version of the audit interface. but listen โ the la_version function should not return the value of version without further checks because it could correspond to an interface that does not match the <link.h> definitions used to build the audit module. so like, do ur due diligence, okay? no cap. ๐
๐ la_objsearch() ๐
char *la_objsearch(const char *name, uintptr_t *cookie,
unsigned int flag);
the dynamic linker invokes this function to inform the auditing library that it is about to search for a shared object. the name argument is the filename or pathname that is to be searched for. cookie identifies the shared object that initiated the search. and flag is set to one of the following values:
LA_SER_ORIGโ this is the original name that is being searched for. typically, this name comes from an ELFDT_NEEDEDentry, or is the filename argument given todlopen(3).LA_SER_LIBPATHโnamewas created using a directory specified inLD_LIBRARY_PATH.LA_SER_RUNPATHโnamewas created using a directory specified in an ELFDT_RPATHorDT_RUNPATHlist.LA_SER_CONFIGโnamewas found via theldconfig(8)cache (/etc/ld.so.cache).LA_SER_DEFAULTโnamewas found via a search of one of the default directories.LA_SER_SECUREโnameis specific to a secure object (unused on Linux).
as its function result, la_objsearch() returns the pathname that the dynamic linker should use for further processing. if NULL is returned, then this pathname is ignored for further processing. and if this audit library simply intends to monitor search paths, then name should be returned. easy peasy ๐
๐ la_activity() ๐
void la_activity( uintptr_t *cookie, unsigned int flag);
the dynamic linker calls this function to inform the auditing library that link-map activity is occurring. cookie identifies the object at the head of the link map. when the dynamic linker invokes this function, flag is set to one of the following values:
LA_ACT_ADDโ new objects are being added to the link map.LA_ACT_DELETEโ objects are being removed from the link map.LA_ACT_CONSISTENTโ link-map activity has been completed: the map is once again consistent. (we love a consistent map, iconic โจ)
๐ la_objopen() ๐
unsigned int la_objopen(struct link_map *map, Lmid_t lmid,
uintptr_t *cookie);
the dynamic linker calls this function when a new shared object is loaded. the map argument is a pointer to a link-map structure that describes the object. the lmid field has one of the following values:
LM_ID_BASEโ link map is part of the initial namespace.LM_ID_NEWLMโ link map is part of a new namespace requested viadlmopen(3).
cookie is a pointer to an identifier for this object. the identifier is provided to later calls to functions in the auditing library in order to identify this object. this identifier is initialized to point to the object's link map, but the audit library can change the identifier to some other value that it may prefer to use to identify the object. customize ur vibes, bestie ๐
as its return value, la_objopen() returns a bit mask created by ORing zero or more of the following constants, which allow the auditing library to select the objects to be monitored by la_symbind*():
LA_FLG_BINDTOโ audit symbol bindings to this object.LA_FLG_BINDFROMโ audit symbol bindings from this object.
a return value of 0 from la_objopen() indicates that no symbol bindings should be audited for this object. so if u return 0, ur basically saying "not me, not today" ๐
๐ง la_objclose() ๐ง
unsigned int la_objclose(uintptr_t *cookie);
the dynamic linker invokes this function after any finalization code for the object has been executed, before the object is unloaded. the cookie argument is the identifier obtained from a previous invocation of la_objopen().
in the current implementation, the value returned by la_objclose() is ignored. so like, return whatever, it doesn't matter. go off, i guess ๐
โญ la_preinit() โญ
void la_preinit(uintptr_t *cookie);
the dynamic linker invokes this function after all shared objects have been loaded, before control is passed to the application (i.e., before calling main()). note that main() may still later dynamically load objects using dlopen(3). so like, this isn't the end of the story, but it's a big moment. the pre-main glow-up, if u will โจ
๐ la_symbind*() ๐
uintptr_t la_symbind32(Elf32_Sym *sym, unsigned int ndx,
uintptr_t *refcook, uintptr_t *defcook,
unsigned int *flags, const char *symname);
uintptr_t la_symbind64(Elf64_Sym *sym, unsigned int ndx,
uintptr_t *refcook, uintptr_t *defcook,
unsigned int *flags, const char *symname);
the dynamic linker invokes one of these functions when a symbol binding occurs between two shared objects that have been marked for auditing notification by la_objopen(). the la_symbind32() function is employed on 32-bit platforms; the la_symbind64() function is employed on 64-bit platforms. choose ur fighter based on ur architecture, bestie.
the sym argument is a pointer to a structure that provides information about the symbol being bound. the structure definition is shown in <elf.h>. among the fields of this structure, st_value indicates the address to which the symbol is bound.
the ndx argument gives the index of the symbol in the symbol table of the bound shared object.
the refcook argument identifies the shared object that is making the symbol reference; this is the same identifier that is provided to the la_objopen() function that returned LA_FLG_BINDFROM. the defcook argument identifies the shared object that defines the referenced symbol; this is the same identifier that is provided to the la_objopen() function that returned LA_FLG_BINDTO.
the symname argument points a string containing the name of the symbol.
the flags argument is a bit mask that both provides information about the symbol and can be used to modify further auditing of this PLT (Procedure Linkage Table) entry. the dynamic linker may supply the following bit values in this argument:
LA_SYMB_DLSYMโ the binding resulted from a call todlsym(3).LA_SYMB_ALTVALUEโ a previousla_symbind*()call returned an alternate value for this symbol.
by default, if the auditing library implements la_pltenter() and la_pltexit() functions (see below), then these functions are invoked, after la_symbind(), for PLT entries, each time the symbol is referenced. the following flags can be ORed into *flags to change this default behavior:
LA_SYMB_NOPLTENTERโ don't callla_pltenter()for this symbol.LA_SYMB_NOPLTEXITโ don't callla_pltexit()for this symbol.
the return value of la_symbind32() and la_symbind64() is the address to which control should be passed after the function returns. if the auditing library is simply monitoring symbol bindings, then it should return sym->st_value. a different value may be returned if the library wishes to direct control to an alternate location. do with that what u will ๐
๐ la_pltenter() ๐
the precise name and argument types for this function depend on the hardware platform. (the appropriate definition is supplied by <link.h>.) here is the definition for x86-32:
Elf32_Addr la_i86_gnu_pltenter(Elf32_Sym *sym, unsigned int ndx,
uintptr_t *refcook, uintptr_t *defcook,
La_i86_regs *regs, unsigned int *flags,
const char *symname, long *framesizep);
this function is invoked just before a PLT entry is called, between two shared objects that have been marked for binding notification.
the sym, ndx, refcook, defcook, and symname are as for la_symbind*().
the regs argument points to a structure (defined in <link.h>) containing the values of registers to be used for the call to this PLT entry.
the flags argument points to a bit mask that conveys information about, and can be used to modify subsequent auditing of, this PLT entry, as for la_symbind*().
the framesizep argument points to a long int buffer that can be used to explicitly set the frame size used for the call to this PLT entry. if different la_pltenter() invocations for this symbol return different values, then the maximum returned value is used. the la_pltexit() function is called only if this buffer is explicitly set to a suitable value.
the return value of la_pltenter() is as for la_symbind*().
๐ la_pltexit() ๐
the precise name and argument types for this function depend on the hardware platform. (the appropriate definition is supplied by <link.h>.) here is the definition for x86-32:
~ to be continued, bestie ~ ๐โจ
unsigned int la_i86_gnu_pltexit(Elf32_Sym *sym, unsigned int ndx,
uintptr_t *refcook, uintptr_t *defcook,
const La_i86_regs *inregs, La_i86_retval *outregs,
const char *symname);
Okay so this one fires when a PLT entry โ one that got made between two shared objects you marked for binding notification โ comes back home. Like, right before control hands itself back to whoever called that PLT entry. Peak "your friend is walking back to the table" energy ๐ถโโ๏ธ๐จ
The sym, ndx, refcook, defcook, and symname arguments? Same deal as la_symbind*(). No notes, bestie, it's the same crew ๐
inregsโ points at a structure (defined in<link.h>, obviously, where else ๐ญ) holding the register values used for the call to this PLT entry.outregsโ points at a structure (again,<link.h>) holding the return values for that call. And you CAN edit these โ the caller mutates them and the changes will be visible to the caller of the PLT entry. It's giving "you have the aux cord" ๐งโจ
In the current GNU implementation, the return value ofla_pltexit()is ignored. So like... it returnsunsigned intbut nobody's reading the receipts bestie, do whatever ๐
๐ VERSIONS ๐
This API is very similar to the Solaris API described in the Solaris Linker and Libraries Guide, specifically in the chapter Runtime Linker Auditing Interface. Same vibe, different house ๐ โจ
โจ STANDARDS โจ
None. That's it. That's the whole section. Not standardized, no committee claimed it, it's just doing its thing ๐
๐ NOTES ๐
Okay pookie, here's the tea on how this differs from the Solaris dynamic linker auditing API โ note these, fr fr:
- The Solaris
la_objfilter()interface is not supported by the GNU implementation. She simply is not invited ๐ - The Solaris
la_symbind32()andla_pltexit()functions do not provide asymnameargument. Ours does. We're giving more ๐ซถ - The Solaris
la_pltexit()function does not provideinregsandoutregsarguments โ but it does provide aretvalargument with the function return value. Different setup, different โจloreโจ
๐ BUGS ๐
In glibc versions up to and include 2.9, specifying more than one audit library in LD_AUDIT results in a run-time crash. Yes bestie, a whole crash. This is reported to be fixed in glibc 2.10. So if you're out here on ancient glibc running two audit libs at once... ๐ญ good luck, queen, you're gonna need it ๐ฏ๏ธ
๐ธ EXAMPLES ๐ธ
Here's a whole little audit library, bebs โ every hook, all printed out, chef's kiss ๐
#include <link.h>
#include <stdio.h>
unsigned int
la_version(unsigned int version)
{
printf("la_version(): version = %u; LAV_CURRENT = %u\n",
version, LAV_CURRENT);
return LAV_CURRENT;
}
char *
la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
{
printf("la_objsearch(): name = %s; cookie = %p", name, cookie);
printf("; flag = %s\n",
(flag == LA_SER_ORIG) ? "LA_SER_ORIG" :
(flag == LA_SER_LIBPATH) ? "LA_SER_LIBPATH" :
(flag == LA_SER_RUNPATH) ? "LA_SER_RUNPATH" :
(flag == LA_SER_DEFAULT) ? "LA_SER_DEFAULT" :
(flag == LA_SER_CONFIG) ? "LA_SER_CONFIG" :
(flag == LA_SER_SECURE) ? "LA_SER_SECURE" :
"???");
return name;
}
void
la_activity (uintptr_t *cookie, unsigned int flag)
{
printf("la_activity(): cookie = %p; flag = %s\n", cookie,
(flag == LA_ACT_CONSISTENT) ? "LA_ACT_CONSISTENT" :
(flag == LA_ACT_ADD) ? "LA_ACT_ADD" :
(flag == LA_ACT_DELETE) ? "LA_ACT_DELETE" :
"???");
}
unsigned int
la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
{
printf("la_objopen(): loading \"%s\"; lmid = %s; cookie=%p\n",
map->l_name,
(lmid == LM_ID_BASE) ? "LM_ID_BASE" :
(lmid == LM_ID_NEWLM) ? "LM_ID_NEWLM" :
"???",
cookie);
return LA_FLG_BINDTO | LA_FLG_BINDFROM;
}
unsigned int
la_objclose (uintptr_t *cookie)
{
printf("la_objclose(): %p\n", cookie);
return 0;
}
void
la_preinit(uintptr_t *cookie)
{
printf("la_preinit(): %p\n", cookie);
}
uintptr_t
la_symbind32(Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, unsigned int *flags, const char *symname)
{
printf("la_symbind32(): symname = %s; sym->st_value = %p\n",
symname, sym->st_value);
printf(" ndx = %u; flags = %#x", ndx, *flags);
printf("; refcook = %p; defcook = %p\n", refcook, defcook);
return sym->st_value;
}
uintptr_t
la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, unsigned int *flags, const char *symname)
{
printf("la_symbind64(): symname = %s; sym->st_value = %p\n",
symname, sym->st_value);
printf(" ndx = %u; flags = %#x", ndx, *flags);
printf("; refcook = %p; defcook = %p\n", refcook, defcook);
return sym->st_value;
}
Elf32_Addr
la_i86_gnu_pltenter(Elf32_Sym *sym, unsigned int ndx,
uintptr_t *refcook, uintptr_t *defcook, La_i86_regs *regs,
unsigned int *flags, const char *symname, long *framesizep)
{
printf("la_i86_gnu_pltenter(): %s (%p)\n", symname, sym->st_value);
return sym->st_value;
}
Like... look at that. Every hook, printing its little heart out. Copy it, compile it, run it, slay ๐ฆ
๐ SEE ALSO ๐
And that's a wrap on the whole page, bestie ๐ Written from the Linux man-pages release 6.20, dated 2025-05-17, and it's the RTLD-AUDIT(7) page โ go be the main character of your own dynamic linker ๐โจ๐ซถ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms