Linking 32-bit library to 64-bit program

32,079

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
32,079
Deepthi
Author by

Deepthi

They say I get a badge for filling all of this form in.

Updated on July 09, 2022

Comments

  • Deepthi
    Deepthi almost 2 years

    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?

  • t0mm13b
    t0mm13b over 14 years
    @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?
  • Reed Copsey
    Reed Copsey over 14 years
    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.
  • t0mm13b
    t0mm13b over 14 years
    @Reed: Thanks for answering my question. :)
  • Admin
    Admin over 14 years
    @Reed: what IPC mechanism would you recommend? I think that shared memory should be reasonable faster then e.g. pipes or Unix Doman Sockets.
  • hookenz
    hookenz about 12 years
    Well that's a shame. Thunking was a very useful technique and allowed you to be able to call 16bit dll's from 32bit apps, or in one case that I had I needed to call a 32bit dll from a 16bit app. It's unfortuante that the modern OS's don't provide that capability for 32/64bit code. I guess there is a reason for it... maybe complexity.
  • phuclv
    phuclv over 10 years
    x86_64 use a different calling convention than x86, as well as different number of regiters (double) makes it harder to link the 2 architectures all together