发行版之间的可执行二进制文件有什么不同吗?

时间:2022-08-29 22:57:03

As all Linux distributions use the same kernel, is there any difference between their executable binary files?

由于所有Linux发行版都使用相同的内核,它们的可执行二进制文件之间有什么区别吗?

If yes, what are the main differences? Or does that mean we can build a universal linux executable file?

如果有,主要的区别是什么?或者这是否意味着我们可以构建一个通用的linux可执行文件?

5 个解决方案

#1


12  

All Linux distributions use the same binary format ELF, but there is still some differences:

所有Linux发行版都使用相同的二进制格式ELF,但是仍然有一些不同之处:

  1. different cpu arch use different instruction set.
  2. 不同的cpu拱使用不同的指令集。
  3. the same cpu arch may use different ABI, ABI defines how to use the register file, how to call/return a routine. Different ABI can not work together.
  4. 同一个cpu拱可以使用不同的ABI, ABI定义了如何使用注册文件,如何调用/返回一个例程。不同的ABI不能协同工作。
  5. Even on same arch, same ABI, this still does not mean we can copy one binary file in a distribution to another. Since most binary files are not statically linked, so they depends on the libraries under the distribution, which means different distribution may use different versions or different compilation configuration of libraries.
  6. 即使在相同的arch、相同的ABI上,这也并不意味着我们可以将一个二进制文件复制到另一个发行版中。由于大多数二进制文件都不是静态链接的,所以它们依赖于分布的库,这意味着不同的发行版可以使用不同的版本或不同的库编译配置。

So if you want your program to run on all distribution, you may have to statically link a version that depends on the kernel's syscall only, even this you can only run a specified arch.

因此,如果您希望您的程序在所有发行版上运行,您可能必须静态地链接一个依赖于内核的syscall的版本,即使是这样,您也只能运行指定的arch。

If you really want to run a program on any arch, then you have to compile binaries for all arches, and use a shell script to start up the right one.

如果您真的想在任何arch上运行一个程序,那么您必须为所有的arch编译二进制文件,并使用一个shell脚本来启动正确的一个。

#2


12  

All Linux ports (that is, the Linux kernel on different processors) use ELF as the file format for executables and libraries. A specific ELF binary is labeled with a single architecture/OS on which it can run (although some OSes have compatibility to run ELF binaries from other OSes).

所有Linux端口(即不同处理器上的Linux内核)都使用ELF作为可执行文件和库的文件格式。一个特定的ELF二进制被标记为可以在其上运行的单个架构/操作系统(尽管有些操作系统具有从其他操作系统运行ELF二进制文件的兼容性)。

Most ports have support for the older a.out format. (Some processors are new enough that there have never existed any a.out executables for them.)

大多数端口都支持旧的a。格式。(有些处理器足够新颖,从来就不存在a。可执行文件。)

Some ports support other executable file formats as well; for example, the PA-RISC port has support for HP-UX's old SOM executables, and the μcLinux (nonmmu) ports support their own FLAT format.

一些端口还支持其他可执行文件格式;例如,PA-RISC端口支持hp - ux的旧SOM的可执行文件,和μcLinux(nonmmu)端口支持自己的平面格式。

Linux also has binfmt_misc, which allows userspace to register handlers for arbitrary binary formats. Some distributions take advantage of this to be able to execute Windows, .NET, or Java applications -- it's really still launching an interpreter, but it's completely transparent to the user.

Linux也有binfmt_misc,它允许用户空间为任意二进制格式注册处理程序。一些发行版利用这一点来执行Windows、. net或Java应用程序——它实际上仍在启动解释器,但对用户来说是完全透明的。


Linux on Alpha has support for loading Intel binaries, which are run via the em86 emulator.

Linux on Alpha支持加载Intel二进制文件,这些二进制文件通过em86模拟器运行。

It's possible to register binfmt_misc for executables of other architectures, to be run with qemu-user.

可以为其他体系结构的可执行文件注册binfmt_misc,并与qemu-user一起运行。

In theory, one could create a new format -- perhaps register a new "architecture" in ELF -- for fat binaries. Then the kernel binfmt loader would have to be taught about this new format, and you wouldn't want to miss the the ld-linux.so dynamic linker and the whole build toolchain. There's been little interest in such a feature, and as far as I know, nobody is working on anything like it.

理论上,我们可以为胖的二进制文件创建一种新的格式——也许在ELF中注册一个新的“架构”。然后,必须向内核binfmt加载程序介绍这种新格式,您不会希望错过ld-linux。动态链接器和整个构建工具链。人们对这种功能兴趣不大,据我所知,没有人做过类似的工作。

#3


1  

Almost all linux program files use the ELF standard.

几乎所有的linux程序文件都使用ELF标准。

#4


1  

Old Unixes also used COFF format. You may still find executables from times of yore in this format. Linux still has support for it (I don't know if it's compiled in current distros, though).

旧的Unixes也使用COFF格式。您仍然可以在这种格式中找到以前的可执行文件。Linux仍然支持它(我不知道它是否用当前发行版编译)。

#5


1  

If you want to create a program that runs an all Linux distributions, you can consider using scripting languages (like Python and Perl) or a platform independent programming language like Java.

如果您想创建一个运行所有Linux发行版的程序,您可以考虑使用脚本语言(如Python和Perl)或平*立的编程语言(如Java)。

Programs written in scripting languages are complied at execution time, which means they are always compiled to match the platform they are executed on, and, hence, should always work (given that the libraries are set up properly).

使用脚本语言编写的程序在执行时得到遵从,这意味着它们总是被编译以匹配它们所执行的平台,因此应该始终工作(考虑到库的设置是正确的)。

Programs written in Java, on the other hand, are compiled before distributing them, but can be executed on any Linux distribution as long as it has a Java VM installed.

另一方面,用Java编写的程序在分发之前进行编译,但是只要安装了Java VM,就可以在任何Linux发行版上执行。

Furthermore, programs written in Java can be run on other operating systems like MS Windows and Mac OS.

此外,用Java编写的程序可以在MS Windows和Mac OS等其他操作系统上运行。

The same is true for many programs written in Python and Perl; however, whether a Python or Perl program will work on another operating system depends on what libraries are used by that program and whether these libraries are available on the other operating systems.

许多用Python和Perl编写的程序也是如此;但是,Python或Perl程序是否将在另一个操作系统上工作,取决于该程序使用的库以及这些库在其他操作系统上是否可用。

#1


12  

All Linux distributions use the same binary format ELF, but there is still some differences:

所有Linux发行版都使用相同的二进制格式ELF,但是仍然有一些不同之处:

  1. different cpu arch use different instruction set.
  2. 不同的cpu拱使用不同的指令集。
  3. the same cpu arch may use different ABI, ABI defines how to use the register file, how to call/return a routine. Different ABI can not work together.
  4. 同一个cpu拱可以使用不同的ABI, ABI定义了如何使用注册文件,如何调用/返回一个例程。不同的ABI不能协同工作。
  5. Even on same arch, same ABI, this still does not mean we can copy one binary file in a distribution to another. Since most binary files are not statically linked, so they depends on the libraries under the distribution, which means different distribution may use different versions or different compilation configuration of libraries.
  6. 即使在相同的arch、相同的ABI上,这也并不意味着我们可以将一个二进制文件复制到另一个发行版中。由于大多数二进制文件都不是静态链接的,所以它们依赖于分布的库,这意味着不同的发行版可以使用不同的版本或不同的库编译配置。

So if you want your program to run on all distribution, you may have to statically link a version that depends on the kernel's syscall only, even this you can only run a specified arch.

因此,如果您希望您的程序在所有发行版上运行,您可能必须静态地链接一个依赖于内核的syscall的版本,即使是这样,您也只能运行指定的arch。

If you really want to run a program on any arch, then you have to compile binaries for all arches, and use a shell script to start up the right one.

如果您真的想在任何arch上运行一个程序,那么您必须为所有的arch编译二进制文件,并使用一个shell脚本来启动正确的一个。

#2


12  

All Linux ports (that is, the Linux kernel on different processors) use ELF as the file format for executables and libraries. A specific ELF binary is labeled with a single architecture/OS on which it can run (although some OSes have compatibility to run ELF binaries from other OSes).

所有Linux端口(即不同处理器上的Linux内核)都使用ELF作为可执行文件和库的文件格式。一个特定的ELF二进制被标记为可以在其上运行的单个架构/操作系统(尽管有些操作系统具有从其他操作系统运行ELF二进制文件的兼容性)。

Most ports have support for the older a.out format. (Some processors are new enough that there have never existed any a.out executables for them.)

大多数端口都支持旧的a。格式。(有些处理器足够新颖,从来就不存在a。可执行文件。)

Some ports support other executable file formats as well; for example, the PA-RISC port has support for HP-UX's old SOM executables, and the μcLinux (nonmmu) ports support their own FLAT format.

一些端口还支持其他可执行文件格式;例如,PA-RISC端口支持hp - ux的旧SOM的可执行文件,和μcLinux(nonmmu)端口支持自己的平面格式。

Linux also has binfmt_misc, which allows userspace to register handlers for arbitrary binary formats. Some distributions take advantage of this to be able to execute Windows, .NET, or Java applications -- it's really still launching an interpreter, but it's completely transparent to the user.

Linux也有binfmt_misc,它允许用户空间为任意二进制格式注册处理程序。一些发行版利用这一点来执行Windows、. net或Java应用程序——它实际上仍在启动解释器,但对用户来说是完全透明的。


Linux on Alpha has support for loading Intel binaries, which are run via the em86 emulator.

Linux on Alpha支持加载Intel二进制文件,这些二进制文件通过em86模拟器运行。

It's possible to register binfmt_misc for executables of other architectures, to be run with qemu-user.

可以为其他体系结构的可执行文件注册binfmt_misc,并与qemu-user一起运行。

In theory, one could create a new format -- perhaps register a new "architecture" in ELF -- for fat binaries. Then the kernel binfmt loader would have to be taught about this new format, and you wouldn't want to miss the the ld-linux.so dynamic linker and the whole build toolchain. There's been little interest in such a feature, and as far as I know, nobody is working on anything like it.

理论上,我们可以为胖的二进制文件创建一种新的格式——也许在ELF中注册一个新的“架构”。然后,必须向内核binfmt加载程序介绍这种新格式,您不会希望错过ld-linux。动态链接器和整个构建工具链。人们对这种功能兴趣不大,据我所知,没有人做过类似的工作。

#3


1  

Almost all linux program files use the ELF standard.

几乎所有的linux程序文件都使用ELF标准。

#4


1  

Old Unixes also used COFF format. You may still find executables from times of yore in this format. Linux still has support for it (I don't know if it's compiled in current distros, though).

旧的Unixes也使用COFF格式。您仍然可以在这种格式中找到以前的可执行文件。Linux仍然支持它(我不知道它是否用当前发行版编译)。

#5


1  

If you want to create a program that runs an all Linux distributions, you can consider using scripting languages (like Python and Perl) or a platform independent programming language like Java.

如果您想创建一个运行所有Linux发行版的程序,您可以考虑使用脚本语言(如Python和Perl)或平*立的编程语言(如Java)。

Programs written in scripting languages are complied at execution time, which means they are always compiled to match the platform they are executed on, and, hence, should always work (given that the libraries are set up properly).

使用脚本语言编写的程序在执行时得到遵从,这意味着它们总是被编译以匹配它们所执行的平台,因此应该始终工作(考虑到库的设置是正确的)。

Programs written in Java, on the other hand, are compiled before distributing them, but can be executed on any Linux distribution as long as it has a Java VM installed.

另一方面,用Java编写的程序在分发之前进行编译,但是只要安装了Java VM,就可以在任何Linux发行版上执行。

Furthermore, programs written in Java can be run on other operating systems like MS Windows and Mac OS.

此外,用Java编写的程序可以在MS Windows和Mac OS等其他操作系统上运行。

The same is true for many programs written in Python and Perl; however, whether a Python or Perl program will work on another operating system depends on what libraries are used by that program and whether these libraries are available on the other operating systems.

许多用Python和Perl编写的程序也是如此;但是,Python或Perl程序是否将在另一个操作系统上工作,取决于该程序使用的库以及这些库在其他操作系统上是否可用。