views:

746

answers:

3

Hi!

I have a 32-bit .so binary-only library and I have to generate 64-bit program that uses it. Is there a way to wrap or convert it, so it can be used with 64-bit program?

+5  A: 

No. You can't directly link to 32bit code inside of a 64bit program.

The best option is to compile a 32bit (standalone) program that can run on your 64bit platform (using ia32), and then use a form of inter-process communication to communicate to it from your 64bit program.

Reed Copsey
@Reed: Then how did Win95 manage the transition from 32bit code calling 16bit a la 'thunking' ? Was that at the assembler level to change around the stack pointer and registers?
tommieb75
The OS handled this explicitly, but there is nothing that allows this in Linux or modern 64bit Windows operating systems, so you have to use a workaround like I posted.
Reed Copsey
@Reed: Thanks for answering my question. :)
tommieb75
@Reed: what IPC mechanism would you recommend? I think that shared memory should be reasonable faster then e.g. pipes or Unix Doman Sockets.
+1  A: 

It is possible, but not without some serious magic behind the scenes and you will not like the answer. Either emulate a 32 bit CPU (no I am not kidding) or switch the main process back to 32 bit. Emulating may be slow though.

This is a proof of concept of the technique.

Then keep a table of every memory access to and from the 32 bit library and keep them in sync. It is very hard to get to a theoretical completeness, but something workable should be pretty easy, but very tedious.

In most cases, I believe two processes and then IPC between the two may actually be easiest, as suggested othwerwise.

Amigable Clark Kant
+2  A: 

For an example of using IPC to run 32-bit plugins from 64-bit code, look at the open source NSPluginWrapper.

Zan Lynx