Assume we have a very small embedded system consisting only of the linux kernel and a single statically linked binary run as init. We want the binary to be able to dynamically load external plugins in runtime.
Is it possible on linux? Dlopen only works with shared libraries and dynamic linking cause static binaries don’t export any symbols to the outside world, so is there any other way to do it?
You can dlopen a shared library from a statically linked binary when using
glibc. If you need your plugin to reference symbols from the main executable, you would have to pass in pointers to them into the plugin, similar to this.You could also write your own module loader. The Linux kernel does this, and so does
Xorg.