I'm loading a dylib from an OSX executable using dlopen. I would like the dylib to resolve it's symbols by binding back with the original executable. Is this possible?
Note that the main executable will always have a known name, i.e. I don't need to dynamically tell the dylib what to bind back to.
To be clear, I have
X: OSX executable
D: OSX dylib
- Run X.
- X calls dlopen (at some point in time) to open D.
- D has undefined symbols which should be resolved against X.
- OSX automatically binds undefined symbols in D against X before static constructors in D are run.
N.B. The last part about static ctrs is crucial.
I basically want an LC_LOAD_DYLIB load command referencing back to the original binary.
EDIT
I'm pretty sure I can work around the issue by adding an intermediate dylib E. Then I can do:
- Run X.
- X calls dlopen (at some point in time) to open E.
- E initialises some proxy symbols then calls dlopen to open D.
- D's undefined symbols resolve against E's proxy symbols.
- E implements it's proxy symbols (manually) using X.
Bit annoying if that's the only way to do this though.