What does "loading .so
files from memory" means to you?
If you have any *.so
file, then it is in some file system, and has a path. Then just use dlopen
on it.
If it is not a file, what is it? How did you get in memory? What exactly have you in memory? (Do you have an ELF header and ELF layout in memory?)
If you have enough information to make an ELF *.so
file, dump (i.e. write) such file into some file system (use a temporary filesystem like tmpfs
if you are concerned with disk performance). Then dlopen
that.
If you don't have enough information to make an ELF .so
file, then probably you are dynamically building code in memory. Look at what existing machine code generating infrastructure (like LLVM, GCCJIT, libjit, GNU lightning, LuaJit ....) are doing.
If you have a full functional code in memory, ensure that the memory is executable with mmap & mprotect and jump into it (e.g. using function pointer tricks).