What are the memory semantics of dladdr()
?
#define _GNU_SOURCE
#include <dlfcn.h>
int dladdr(void *addr, Dl_info *info);
typedef struct {
const char *dli_fname; /* Pathname of shared object that contains address */
void *dli_fbase; /* Base address at which shared object is loaded */
const char *dli_sname; /* Name of symbol whose definition overlaps addr */
void *dli_saddr; /* Exact address of symbol named in dli_sname */
} Dl_info;
From reading the man page, it's unclear whether dli_fname
:
I suppose the same question applies to dli_sname
, but I suspect that indeed points to a constant string (the symbol itself).
Is the user responsible for deleting dli_fname
returned by dladdr()
?
These strings are valid until the object is unloaded via dlclose
(either directly or indirectly).
The const char *
conveys that the string must not be freed by the dladdr
caller because free
expects a void *
, not a const void *
.