Is this the time involved in combining library globals shared between plugins loaded with dlopen?

I have a C ++ program that binds at runtime to, say, mylib.so. then the same program uses dlopen () / dlsym () to load a function from myplugin.so, a dynamic library, which in turn has dependencies on mylib.so.

My question is: will the program AND function in the plugin receive the same global variables defined in mydlib.so in the same area of ​​memory that is reserved for the program, or will each be assigned a different, unbound copy in its own memory? if the latter is the default behavior, is it possible to change this?

Thanks in advance =)!

+5
source share
1 answer

The globals in the main program that does dlopenshould be visible to dynamically loaded code. However, the best advice I've seen so far (especially if you ever wanted to have even vaguely portable code) should only pass function calls through the link delimiter and not export any variables in any direction. It is also best if there is an API for the downloaded code to register interesting parts of my API with the loader (for example, “This is how I provide this SPI for drawing foobars on baz”), since this is a much more reasonable way to make callbacks, and not just knock everything together.

[EDIT]: , , . , , , SPI API, , .so, . , , , (, , - ).

+1

All Articles