I was reading this Frida release page and noticed it made the following reference:
Short of writing the whole agent in C, one could go ahead and build a native library, and load it using Module.load(). This works but means it has to be compiled for every single architecture, deployed to the target, etc.
The CModule feature is fantastic for Frida-centric actions, but it would be nice to load generic shared-objects into the target process. CModule appears to be written for performance optimization within Stalker and related code. Any attempt to do something "extra" results in something like this will result in compile-time (at runtime, by the embedded TinyCC) errors such as:
Compilation failed: In file included from module.c:3:\nmodule.c:3: error: include file 'dlfcn.h' not found"
^ Attempt at writing a CModule stub that dlopen'd a shared object from disk.
But the comment by Ole in the link above alludes to this being possible, though I can't find any references other than the NodeJS C++ Addons features that are, of course, specific to NodeJS.