Merge branch 'vendor/TCPDUMP'
[dragonfly.git] / lib / libc / gen / dlvsym.3
1 .\" This source code is a product of Sun Microsystems, Inc. and is provided
2 .\" for unrestricted use provided that this legend is included on all tape
3 .\" media and as a part of the software program in whole or part.  Users
4 .\" may copy or modify this source code without charge, but are not authorized
5 .\" to license or distribute it to anyone else except as part of a product or
6 .\" program developed by the user.
7 .\"
8 .\" THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC.
9 .\" SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY
10 .\" OF SUCH SOURCE CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT
11 .\" EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  SUN MICROSYSTEMS, INC. DISCLAIMS
12 .\" ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED
13 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN
14 .\" NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT,
15 .\" INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
16 .\" FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY.
17 .\"
18 .\" This source code is provided with no support and without any obligation on
19 .\" the part of Sun Microsystems, Inc. to assist in its use, correction,
20 .\" modification or enhancement.
21 .\"
22 .\" SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
23 .\" INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS
24 .\" SOURCE CODE OR ANY PART THEREOF.
25 .\"
26 .\" Sun Microsystems, Inc.
27 .\" 2550 Garcia Avenue
28 .\" Mountain View, California 94043
29 .\"
30 .\" Copyright (c) 1991 Sun Microsystems, Inc.
31 .\"
32 .\" $FreeBSD: src/lib/libc/gen/dlopen.3 211397 2010-08-16 15:18:30Z joel $
33 .\"
34 .Dd April 28, 2011
35 .Dt DLVSYM 3
36 .Os
37 .Sh NAME
38 .Nm dlsym
39 .Nd shared object symbol lookup by version function
40 .Sh LIBRARY
41 This function is not in a library.
42 It is included in every dynamically linked program automatically.
43 .Sh SYNOPSIS
44 .In dlfcn.h
45 .Ft void *
46 .Fn dlsym "void *handle" "const char *name" "const char *version"
47 .Ft "void *"
48 .Fn dlvsym "void *handle" "const char *name" "const char *version"
49 .Sh DESCRIPTION
50 The
51 .Fn dlvsym
52 function
53 does the same as
54 .Fn dlsym
55 but takes a version string as an additional argument.  Both the name and
56 the version must match in order for the symbol to be resolved.
57 .Sh NOTES
58 ELF executables need to be linked
59 using the
60 .Fl export-dynamic
61 option to
62 .Xr ld 1
63 for symbols defined in the executable to become visible to
64 .Fn dlvsym .
65 .Sh RETURN VALUE
66 The
67 .Fn dlvsym
68 function
69 returns the address of the symbol unless the symbol can not be found.
70 In this case, it returns a null pointer and sets an error condition
71 which may be queried with
72 .Fn dlerror .
73 .Sh EXAMPLE
74 The following program will obtain a pointer to the gcc library __adsvsi3
75 function using dlvsym specified to version GCC_3.0, and then it will use it
76 to print out the sum of 500 + 325.
77 .Bd -literal
78 #include <dlfcn.h>
79 #include <stdlib.h>
80 #include <stdio.h>
81
82 int
83 main (int argc, char *argv[])
84 {
85     void       *handle;
86     int        (*func_sum)(int a, int b);
87
88     /* open the pkgsrc shared gcc library  */
89     handle = dlopen("/usr/pkg/lib/libgcc_s.so", RTLD_LAZY);
90     if (!handle) {
91        fprintf (stderr, "%s\en", dlerror ());
92        exit (EXIT_FAILURE);
93     }
94
95     /* get pointer to integer sum function */
96     func_sum = dlvsym (handle, "__addvsi3", "GCC_3.0");
97     if (func_sum == NULL) {
98        fprintf (stderr, "function %s version %s not found\en",
99                 "__addvsi3", "GCC_3.0");
100        dlclose (handle);
101        exit (EXIT_FAILURE);
102     }
103
104     /* Calculate and display the sum of 500 + 325 */
105     printf ("500 + 325 = %d\en", func_sum((int)500, (int)325));
106     dlclose (handle);
107
108     exit(EXIT_SUCCESS);
109 }
110 .Ed
111 .Sh SEE ALSO
112 .Xr rtld 1 ,
113 .Xr dlfcn 3 ,
114 .Xr dlsym 3 ,
115 .Xr dlvsym 3
116 .Sh HISTORY
117 The
118 .Nm
119 function first appeared in
120 .Dx 2.11 .