In Automatically executed functions when loading shared libraries we read:
To have a function executed whenever the shared library is loaded or unloaded, you can mark a constructor and destructor function using GCC-specific attribute syntax:
__attribute__((constructor)) void init(void) { ... }
__attribute__((destructor)) void fini(void) { ... }
The article How exactly does __attribute__((constructor)) work? also mentions .init/.fini
.
Now, I have a .so
module (a shared object library, no source) and I want to know which function(s) are executed when the library is loaded/unloaded. I tried nm
, but it looks like these attributes are not shown in the output.
So, How do I know which function(s) are automatically executed when the shared library is loaded or unloaded?