Possible Duplicate:
dlopen from memory?
I've seen this for Windows' DLL files, being loaded from a memory buffer, but I cant find it anywhere for Linux, and "ld" source code is the most complex code I've ever seen. So:
Is there any example of loading .so files from memory? Even a simple one that I can finish? I just don't know where to start, even though I've read most of the ELF specifications it's still mysterious to me.
These files are normally stored in /lib/ or /usr/lib/.
so file is a binary file used as a native library on Android. Normally it's a part of an Android application. If you want to see its content, you need to open it as a binary file in a binary (hex) viewer. In any case you won't see much there, but hex code.
A . a file is a static library, while a . so file is a shared object dynamic library similar to a DLL on Windows.
DLLs and SOs are fundamentally different formats, so in short, no, you can't load a DLL on Linux or an SO on Windows.
You're looking at the source code of a wrong thing: ld
doesn't do program and library loading. Instead, you should look at the source code of dlopen
and dlsym
functions found in libc. Also, you should look at the source of the dynamic linker: ld-linux.so (the true name varies with the platform; execute ldd /bin/ls
to find out where the dynamic linker resides).
ELF parsing isn't difficult, but it requires attention to detail and understanding of assembly code for the particular CPU; you need also ABI specification for your platform (and it's different for 32- and 64-bit linux, and is also different between CPUs.)
If you just need to load object files from memory at run-time (i.e., it doesn't have to be a SO), you can look at X11 project: they have implemented a module system which, basically, loads object code at some address and relocates it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With