在Linux(gcc)中混合使用32位和64位库 [英] Mixing 32 and 64-bit Libraries in Linux (gcc)

查看:2649
本文介绍了在Linux(gcc)中混合使用32位和64位库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为Linux(使用gcc)构建的仅32位二进制C.Sso(由供应商提供),我需要链接到一个64位C / C ++应用程序(我正在开发)。有没有办法从我的应用程序访问这个库?



我知道需要注意处理.so中的函数的参数和指针,而我知道很久以前它被认为基本上不可能(例如后)。我希望情况发生了变化。

解决方案

可能可以将一些汇编代码粘合到一起来转换函数参数并从一个模块返回值到另一个模块,并翻转处理器模式。它可能会破解链接器,因此它不会仅仅是无视它(或者破解.so文件,因此链接器不知道)。你必须教导64位动态链接器如何进行32位重定位,等等,然后继续。



但是,会发生什么当你点击32位范围之外的指针时?那么,如果32位代码在64位地址上加载,会发生什么?现在内核必须被教会在低内存地址中加载这个 64位程序,而这首先破坏了64位。



然后,您必须安排该库与32位libc链接,但在一个项目中有两个libc可能已损坏。也许32位库可以使用64位libc?但是,现在,这不仅仅是函数参数,您必须担心:系统类型的大小都是错误的。嗯,内核可能对32位和64位进程的系统调用有不同的响应。不好。

(而且,我甚至不确定甚至可以在没有内核帮助的情况下在32位和64位ISA之间切换) / p>

不,我敢肯定,这已经足够接近不可能,没有人愿意做这项工作。而且,随着世界越来越64位和32位变得越来越少,而且越来越少有趣,情况越来越少可能改变,而不是更多。



IPC选项听起来不太有趣。如果我是你,我会严重质疑为什么我的新项目必须是64位。


I have a 32-bit binary-only C .so (provided by a vendor) built for Linux (using gcc), that I need to link to a 64-bit C/C++ application (which I am developing). Is there any way to access this library from my application?

I know there will need to be care taken to handle arguments and pointers to functions inside the .so, and I know that long ago it was deemed basically impossible (like this post). I'm hoping the situation has changed.

解决方案

It might be possible to hack together some assembler glue code to translate the function parameters and return values from one module to the other, and flip the processor mode. It might be possible to hack the linker so it doesn't just reject it out of hand (or hack the .so file so the linker doesn't know). And you'd have to teach the 64-bit dynamic linker how to do 32-bit relocations, and so on, and on, and on.

But, what happens when you hit a pointer outside the 32-bit range? Come to that, what would happen if the 32-bit code got loaded at a 64-bit address? Now the kernel would have to be taught to load this 64-bit program in low memory addresses, which rather defeats the point of making it 64-bit in the first place.

Then you'd have to arrange for that library to link against the 32-bit libc, but having two libc in one project is probably broken. Maybe the 32-bit library could use the 64-bit libc? But, now that's not just function parameters you have to worry about: the system types are all the wrong size. Hmmm, and the kernel probably responds differently to syscalls from 32-bit and 64-bit processes. Not good.

(And, I'm not even sure it's even possible to switch between the 32-bit and 64-bit ISA without assistance from the kernel?)

No, I'm pretty sure this is close enough to impossible that nobody wants to do the work. And, with the world going increasingly 64-bit and 32-bit getting less, and less interesting, the situation is getting less likely to change, not more so.

The IPC option doesn't sound like much fun. If I were you I'd be seriously questioning why my new project has to be 64-bit.

这篇关于在Linux(gcc)中混合使用32位和64位库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆