How to achieve symbol versioning

6.2k views Asked by At

I want to achieve something like below :

I have multiple versions of a library. I dynamically load the latest version of the library using dlopen(). Then I want to see if a particular function (along with similar return type and argument list) exists in that version. If it does then open it else fall back to the previous version to check the same.

I've seen some posts on "version scripts" but am unable to use it. Also I think searching the symbol table will not be a solution as it only checks for function name there.

1

There are 1 answers

0
linuxbuild On

Good explanation of symbol versioning is here. You need a dlvsym() function from GNU extension to search for a symbol by name and version:

#define _GNU_SOURCE
#include <dlfcn.h>
void *dlvsym(void *handle, char *symbol, char *version);

The function dlvsym() does the same as dlsym() but takes a version string as an additional argument. Note: C++ symbol names should be passed to dlvsym() in mangled form containing argument list. Unfortunately, GCC mangled name (unlike MSVC) doesn't contain a return type.

For more info see "dlopen(3) - Linux man page".