2

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
  1. Run X.
  2. X calls dlopen (at some point in time) to open D.
  3. D has undefined symbols which should be resolved against X.
  4. 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:

  1. Run X.
  2. X calls dlopen (at some point in time) to open E.
  3. E initialises some proxy symbols then calls dlopen to open D.
  4. D's undefined symbols resolve against E's proxy symbols.
  5. E implements it's proxy symbols (manually) using X.

Bit annoying if that's the only way to do this though.

Andrew Parker
  • 1,425
  • 2
  • 20
  • 28

0 Answers0