I'm trying to build a service/daemon that facilitates 'applets' being run within its process envelope. The service exposes functionality through a library that these applets invoke. Most importantly, the requirement here is the need for these applets to all run within the same process boundary as the service itself. The applet also needs to register itself against the service on boot.
I would like to design the service such that it can be built independently of these applets, as well as to not have any code in it that specifically is aware of these applets.
One option here is to build the applets as shared libraries (.so), have them all be placed on the target filesystem at a particular folder that is searched by the service on boot, loading all .so's in that folder dynamically through dl_open
. By tagging an init-function __attribute__((constructor))
in the applet itself, the applet gains the ability to register itself with the service at init time.
Is there a static/link-time version of this? I've dabbled with the suggestion here, but am not able to prevent the compiler from optimizing out the global function registry object that is being exported by each applet. Using -Wl,--whole-archive
doesn't work either since it complains of multiple definition of functions provided by the service/daemon library when linking two or more such applet libraries.