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