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 February 22, 2018 35.Dt DLVSYM 3 36.Os 37.Sh NAME 38.Nm dlvsym 39.Nd shared object symbol lookup by version function 40.Sh LIBRARY 41This function is not in a library. 42It is included in every dynamically linked program automatically. 43.Sh SYNOPSIS 44.In dlfcn.h 45.Ft "void *" 46.Fn dlvsym "void * restrict handle" "const char * restrict name" "const char * restrict version" 47.Sh DESCRIPTION 48The 49.Fn dlvsym 50function 51does the same as 52.Xr dlsym 3 53but takes a version string as an additional argument. 54Both the name and 55the version must match in order for the symbol to be resolved. 56.Sh NOTES 57ELF executables need to be linked 58using the 59.Fl export-dynamic 60option to 61.Xr ld 1 62for symbols defined in the executable to become visible to 63.Fn dlvsym . 64.Sh RETURN VALUES 65The 66.Fn dlvsym 67function 68returns the address of the symbol unless the symbol can not be found. 69In this case, it returns a null pointer and sets an error condition 70which may be queried with 71.Fn dlerror . 72.Sh EXAMPLES 73The following program will obtain a pointer to the gcc library __adsvsi3 74function using dlvsym specified to version GCC_3.0, and then it will use it 75to print out the sum of 500 + 325. 76.Bd -literal 77#include <dlfcn.h> 78#include <stdlib.h> 79#include <stdio.h> 80 81int 82main (int argc, char *argv[]) 83{ 84 void *handle; 85 int (*func_sum)(int a, int b); 86 87 /* open the dports shared gcc410 library */ 88 handle = dlopen("/usr/local/lib/gcc410/libgcc_s.so", RTLD_LAZY); 89 if (!handle) { 90 fprintf (stderr, "%s\en", dlerror ()); 91 exit (EXIT_FAILURE); 92 } 93 94 /* get pointer to integer sum function */ 95 func_sum = dlvsym (handle, "__addvsi3", "GCC_3.0"); 96 if (func_sum == NULL) { 97 fprintf (stderr, "function %s version %s not found\en", 98 "__addvsi3", "GCC_3.0"); 99 dlclose (handle); 100 exit (EXIT_FAILURE); 101 } 102 103 /* Calculate and display the sum of 500 + 325 */ 104 printf ("500 + 325 = %d\en", func_sum((int)500, (int)325)); 105 dlclose (handle); 106 107 exit(EXIT_SUCCESS); 108} 109.Ed 110.Sh SEE ALSO 111.Xr rtld 1 , 112.Xr dlfcn 3 , 113.Xr dlsym 3 114.Sh HISTORY 115The 116.Nm 117function first appeared in 118.Dx 2.11 . 119