Page 1 of 1

Interposing without DYLD_INSERT_LIBRARIES

PostPosted: Tue Mar 18, 2014 10:13 pm
by mcg
I've created an interpose library that wraps some of Apple's BLAS and LAPACK functions to translate them from an F2C calling format to a GFORTRAN calling format. When I test it using DYLD_INSERT_LIBRARIES, it works great.

Now what I'd like to do is use this interposition permanently---that is, by linking this code into the main program in some way, so that DYLD_INSERT_LIBRARIES does not need to be set. I've tried adding the object code into the main program, and also linking it as a dynamic library (before -framework vecLib, of course), but the interposing is not happening. How would I accomplish this? Is there a way to invoke dyld's own interposition code, or do I have to do it manually?

Re: Interposing without DYLD_INSERT_LIBRARIES

PostPosted: Sat Apr 26, 2014 2:21 am
by morpheus
Much belated a reply, I know, but it slipped my mind:

To get around DYLD_INSERT_LIBRARIES, you can edit the Mach-O and inject a load command that will form a new dependency on the injected lib. It's a feature that has been around in tool for a while by now. Try it and let me know if it works for you

J

Re: Interposing without DYLD_INSERT_LIBRARIES

PostPosted: Sat May 17, 2014 1:04 pm
by MaxBrein
Hi there.

I got the same problem, working on editing the Mach-O and injecting a load command that will form a new dependency.

Could you help me with a Jtool example of adding a new dynamic lib dependency ?

Re: Interposing without DYLD_INSERT_LIBRARIES

PostPosted: Fri Aug 01, 2014 1:03 pm
by ericgorr
Administrator wrote:Much belated a reply, I know, but it slipped my mind:
To get around DYLD_INSERT_LIBRARIES, you can edit the Mach-O and inject a load command that will form a new dependency on the injected lib. It's a feature that has been around in tool for a while by now. Try it and let me know if it works for you


How would you go about editing a Mach-O file to inject the load command?

Is there a mach-o editor out there?
Would one load the mach-o into a hex editor?
Write code which understands the mach-o file format to perform the insertion?

Any further details on how exactly one would best go about editing the mach-o file would be of interest.

Thank you.

Re: Interposing without DYLD_INSERT_LIBRARIES

PostPosted: Fri Aug 01, 2014 2:17 pm
by mcg
I must confess that I did not try the Administrator's solution---because it's above my skill level. :-) One of the hazards of modern search engines is that, while it's easy to find solutions, there is no guarantee the solution offered will be simple enough to use. It is clear I'd have a lot more to learn before I can do what I was asking.

I ended up writing my code in such a way that I could build interpose and non-interpose versions of my library. Here is the library I came up with. Honestly, if there were a simple way to code up dynamic symbol replacement in the non-interpose case, I'd still prefer that. I think it results in a simpler solution to this particular challenge.