diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2004-08-11 19:14:57 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2004-08-11 19:14:57 +0000 |
commit | 790e0511d8b6629c85ac959d63eac9fe4c7caacc (patch) | |
tree | a773d637df2fb3bf669f7ff2c16983fc3344e417 /share | |
parent | fec58ae8c4bc4002d602ce897ee4f88767e23679 (diff) |
add dladdr() support and add some 'standard' dlsym() support.
ok millert miod pval, grumble deraadt
Diffstat (limited to 'share')
-rw-r--r-- | share/man/man3/Makefile | 4 | ||||
-rw-r--r-- | share/man/man3/dlfcn.3 | 97 |
2 files changed, 98 insertions, 3 deletions
diff --git a/share/man/man3/Makefile b/share/man/man3/Makefile index 2b21a0ba101..dc959f06457 100644 --- a/share/man/man3/Makefile +++ b/share/man/man3/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2004/02/09 19:21:51 espie Exp $ +# $OpenBSD: Makefile,v 1.16 2004/08/11 19:14:56 drahn Exp $ # @(#)Makefile 8.2 (Berkeley) 12/13/93 MAN= assert.3 bitstring.3 dlfcn.3 end.3 intro.3 queue.3 stdarg.3 \ @@ -49,7 +49,7 @@ MLINKS+=queue.3 SLIST_ENTRY.3 queue.3 SLIST_HEAD.3 \ MLINKS+=stdarg.3 varargs.3 stdarg.3 va_arg.3 stdarg.3 va_end.3 MLINKS+=stdarg.3 va_start.3 stdarg.3 va_copy.3 MLINKS+=dlfcn.3 dlopen.3 dlfcn.3 dlclose.3 dlfcn.3 dlsym.3 dlfcn.3 dlctl.3 \ - dlfcn.3 dlerror.3 + dlfcn.3 dlerror.3 dlfcn.3 dladdr.3 MLINKS+=tree.3 SPLAY_PROTOTYPE.3 tree.3 SPLAY_GENERATE.3 \ tree.3 SPLAY_ENTRY.3 tree.3 SPLAY_HEAD.3 \ tree.3 SPLAY_INITIALIZER.3 tree.3 SPLAY_ROOT.3 \ diff --git a/share/man/man3/dlfcn.3 b/share/man/man3/dlfcn.3 index 4a03872ad84..48747a3a3f2 100644 --- a/share/man/man3/dlfcn.3 +++ b/share/man/man3/dlfcn.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dlfcn.3,v 1.15 2003/09/25 21:56:20 millert Exp $ +.\" $OpenBSD: dlfcn.3,v 1.16 2004/08/11 19:14:56 drahn Exp $ .\" $NetBSD: dlfcn.3,v 1.3 1996/01/09 19:43:34 pk Exp $ .\" .\" Copyright (c) 1995 Paul Kranenburg @@ -36,6 +36,7 @@ .Nm dlopen , .Nm dlclose , .Nm dlsym , +.Nm dladdr , .Nm dlctl , .Nm dlerror .Nd dynamic link interface @@ -48,6 +49,8 @@ .Ft "void *" .Fn dlsym "void *handle" "const char *symbol" .Ft "int" +.Fn dladdr "const void *addr" "Dl_info *info" +.Ft "int" .Fn dlctl "void *handle" "int cmd" "void *data" .Ft "const char *" .Fn dlerror "void" @@ -75,6 +78,8 @@ argument can either be an absolute pathname or it can be of the form in which case the same library search rules apply that are used for .Dq intrinsic shared library searches. +A null pointer supplied for path is interpreted as a reference to the main +executable of the process. The second argument currently has no effect, but should be set to .Dv DL_LAZY for future compatibility. @@ -111,6 +116,96 @@ If the symbol cannot be resolved, .Dv NULL is returned. .Pp +If +.Fn dlsym +is called with the special +.Fa handle +.Dv NULL , +it is interpreted as a reference to the executable or shared object +from which the call is being made. +Thus a shared object can reference its own symbols. +.Pp +If +.Fn dlsym +is called with the special +.Fa handle +.Dv RTLD_DEFAULT , +all the shared objects will be searched in the order they were loaded. +.Pp +If +.Fn dlsym +is called with the special +.Fa handle +.Dv RTLD_NEXT , +then the search for the symbol is limited to the shared objects +which were loaded after the one issuing the call to +.Fn dlsym . +Thus, if the function is called from the main program, all +the shared libraries are searched. +If it is called from a shared library, all subsequent shared +libraries are searched. +.Pp +If +.Fn dlsym +is called with the special +.Fa handle +.Dv RTLD_SELF , +then the search for the symbol is limited to the shared object +issuing the call to +.Fn dlsym +and those shared objects which were loaded after it. +.Pp +.Fn dladdr +queries the dynamic linker for information about the shared object +containing the address +.Fa addr . +The information is returned in the structure specified by +.Fa info . +The structure contains at least the following members: +.Bl -tag -width "XXXconst char *dli_fname" +.It Li "const char *dli_fname" +The pathname of the shared object containing the address +.Fa addr . +.It Li "void *dli_fbase" +The base address at which the shared object is mapped into the +address space of the calling process. +.It Li "const char *dli_sname" +The name of the nearest run-time symbol with a address less than or +equal to +.Fa addr . +.Pp +If no symbol with a suitable address is found, both this field and +.Va dli_saddr +are set to +.Dv NULL . +.It Li "void *dli_saddr" +The address of the symbol returned in +.Va dli_sname . +.El +.Pp +If a mapped shared object containing +.Fa addr +cannot be found, +.Fn dladdr +returns 0. +In that case, a message detailing the failure can be retrieved by +calling +.Fn dlerror . +On success, a non-zero value is returned. Note: both strings pointed +at by +.Va dli_fname +and +.Va dli_sname +reside in memory private to the run-time linker module and should not +be modified by the caller. +.Pp +In dynamically linked programs, the address of a global function will +point to its program linkage table entry, rather than to the entry +point of the function itself. +This causes most global functions to appear to be defined within the +main executable, rather than in the shared libraries where the actual +code resides. +.Pp .Fn dlctl provides an interface similar to .Xr ioctl 2 |