Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve symbol versioning

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.

like image 384
Pein Avatar asked Feb 16 '11 10:02

Pein


1 Answers

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".

like image 64
linuxbuild Avatar answered Sep 26 '22 23:09

linuxbuild