Interposing without DYLD_INSERT_LIBRARIES

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Interposing without DYLD_INSERT_LIBRARIES

Postby mcg » Tue Mar 18, 2014 10:13 pm

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?
mcg
 
Posts: 2
Joined: Tue Mar 18, 2014 10:07 pm

Re: Interposing without DYLD_INSERT_LIBRARIES

Postby morpheus » Sat Apr 26, 2014 2:21 am

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
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Re: Interposing without DYLD_INSERT_LIBRARIES

Postby MaxBrein » Sat May 17, 2014 1:04 pm

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 ?
MaxBrein
 
Posts: 5
Joined: Sat May 17, 2014 12:48 pm

Re: Interposing without DYLD_INSERT_LIBRARIES

Postby ericgorr » Fri Aug 01, 2014 1:03 pm

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.
ericgorr
 
Posts: 3
Joined: Fri Aug 01, 2014 12:56 pm

Re: Interposing without DYLD_INSERT_LIBRARIES

Postby mcg » Fri Aug 01, 2014 2:17 pm

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.
mcg
 
Posts: 2
Joined: Tue Mar 18, 2014 10:07 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 4 guests