Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux dlopen : how to make loading lib manager

Tags:

c++

linux

dlopen

I have the same code compiled with different arch options (FMV does not work as the functions return sse and i can't change "default" to something with sse) How can i make a meta-library that at load time checks the cpu capability and load the corresponding lib? (without any dlsym machinery)?

like image 964
Adrian Sevcenco Avatar asked Oct 17 '22 00:10

Adrian Sevcenco


1 Answers

One way to achieve what you want is to link against dummy wrapper library which checks CPU capabilities at startup, loads matching shared library and then forwards all function calls to their implementations in this shared library.

Such dummy library may be implemented by hand or generated via custom script. Or you can use Implib.so to generate it automatically:

$ implib-gen.py --dlopen-callback=load_mylib mylib_avx.so

You'll need to implement load_mylib (to analyze CPUID and dlopen appropriate implementation) and link your app with generated files.

like image 145
yugr Avatar answered Oct 21 '22 01:10

yugr