Is there any difference between executable binary files between distributions?

后端 未结 5 1127
甜味超标
甜味超标 2021-02-08 11:23

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

If yes, what are the main differences? Or does that mean w

相关标签:
5条回答
  • 2021-02-08 12:04

    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).

    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.)

    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.

    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 on Alpha has support for loading Intel binaries, which are run via the em86 emulator.

    It's possible to register binfmt_misc for executables of other architectures, to be run with 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 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.

    0 讨论(0)
  • 2021-02-08 12:11

    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.

    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.

    Furthermore, programs written in Java can be run on other operating systems like MS Windows and 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.

    0 讨论(0)
  • 2021-02-08 12:15

    Almost all linux program files use the ELF standard.

    0 讨论(0)
  • 2021-02-08 12:23

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

    1. different cpu arch use different instruction set.
    2. 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.
    3. 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.

    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.

    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.

    0 讨论(0)
  • 2021-02-08 12:29

    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).

    0 讨论(0)
提交回复
热议问题