虚拟化技术与跨平台兼容性

虚拟化:

1 .硬件级 VMware/VirtualPC

2. 编程语言级 JVM .NET/CIL

3. 程序库级 wine

 

兼容性:

A library is binary compatible, if a program linked dynamically to a former version of the library continues running with newer versions of the library without the need to recompile.

If a program needs to be recompiled to run with a new version of library but doesn't require any further modifications, the library is source compatible.

Binary compatibility saves a lot of trouble. It makes it much easier to distribute software for a certain platform. Without ensuring binary compatibility between releases, people will be forced to provide statically linked binaries. Static binaries are bad because they

  • waste resources (especially memory)
  • don't allow the program to benefit from bugfixes or extensions in the libraries

 

1. 源码级 QT程序(不同系统版本提供同名API) glibc和uclibc

2. 二进制级 JVM

 

ABI(ApplicationBinaryInterface)

应用二进制接口,描述了应用程序和操作系统之间,一个应用和它的库之间,或者应用的组成部分之间的低层接口。ABI不同于应用程序接口(API),API定义了源代码和库之间的接口,因此同样的代码可以在支持这个API的任何系统中编译,然而ABI允许编译好的目标代码在使用兼容ABI的系统中无需改动就能运行。

 

ABI是二进制映像的“生产者”即编译/连接工具和使用者即映像装入/启动手段之间的一组约定。而我们一般 所说的二进制映像格式,实际上并不仅仅是指字面意义上的、类似于数据结构定义那样的“格式”,还包括了跟映像装入过程有关的其它约定。所以,二进制映像格式是ABI的主体。

 

以下转自陈硕http://www.cppblog.com/Solstice/archive/2011/03/09/141401.aspx 

如果以 shared library 方式提供函数库,那么头文件和库文件不能轻易修改,否则容易破坏已有的二进制可执行文件,或者其他用到这个 shared library 的 library。操作系统的 system call 可以看成 Kernel 与 User space 的 interface,kernel 在这个意义下也可以当成 shared library,你可以把内核从 2.6.30 升级到 2.6.35,而不需要重新编译所有用户态的程序。

 

所谓“二进制兼容性”指的就是在升级(也可能是 bug fix)库文件的时候,不必重新编译使用这个库的可执行文件或使用这个库的其他库文件,程序的功能不被破坏。

 

C/C++ 通过头文件暴露出动态库的使用方法,这个“使用方法”主要是给编译器看的,编译器会据此生成二进制代码,然后在运行的时候通过装载器(loader)把可执行文件和动态库绑到一起。如何判断一个改动是不是二进制兼容,主要就是看头文件暴露的这份“使用说明”能否与新版本的动态库的实际使用方法兼容。因为新的库必然有新的头文件,但是现有的二进制可执行文件还是按旧的头文件来调用动态库。

解决办法:

(1)采用静态链接 这个是王道。在分布式系统这,采用静态链接也带来部署上的好处,只要把可执行文件放到机器上就行运行,不用考虑它依赖的 libraries。

(2)通过动态库的版本管理来控制兼容性 《程序员的自我修养》里边讲过 .so 文件的命名与二进制兼容性相关的话题,值得一读。

java是如何应对的:Java 实际上把 C/C++ 的 linking 这一步骤推迟到 class loading 的时候来做。

同一版本的QT运行于不同系统是源码兼容,不同版本的兼容是二进制级的(Binary compatibility means that you can safely

distribute your Qt programs dynamically linked to the Qt library. If the users of your program have a newer version of the

Qt dynamic library installed (or later upgrade to one), your program will still work. This can save much time, network, disk,

and memory resources and administration work, for both you and the users of your Qt-based programs.

 

猜你喜欢

转载自lanxinyuchs.iteye.com/blog/1041071