Skip to content
Advertisement

linux dlopen : how to make loading lib manager

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)?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement