About the ABI compatibility of Linux applications

Source: Internet
Author: User

About the ABI compatibility of Linux applications
Background

A problem encountered in recent work is that multiple systems run on different versions of the kernel, ARM chips of different architectures, and whether upper-layer business programs can be restored in binary format (shared images ).

Based on your understanding of Linux, can glibc be forward compatible at the ABI level. Can the whole system do this? This reminds me of my analysis and thinking.

What is ABI compatibility dependent on?

Imagine which components of a program are involved in the compilation and linking process from the source code to the final binary code:

  • Kernel Export user-mode header files
  • Gcc compiler, static. o/. a provided by gcc, and dynamic library provided by it (such as libgcc_s.so)
  • Glibc
  • Third-party open source Library

It is necessary to analyze whether each group can achieve binary compatibility and how to achieve it. Next, I will use a mind map to analyze whether the components can meet the ABI compatibility requirements.

The Mind Map above segments all the components I think of and covers every detail. Of course, there will be some details that I did not think. The following describes less common components:

  • Kernel export header file: Cross-compiling toolchain is a common task in embedded systems. To build a toolchain, use the export file exported by the kernel. This is the basic type and data structure agreed by the kernel state and the user, such as common time_t and pid_t types. All user-state software uses it as the cornerstone.
  • Glibc version mechanism: glibc uses version numbers for most symbols. In later versions of glibc, due to changes in POSIX/LSB standards or function interfaces, it creates another new version of the symbol, but the original version still exists, and the semantics and parameters remain unchanged. This mechanism ensures the forward compatibility of ABI (note that backward compatibility cannot be guaranteed)

From the analysis, most of the software can be forward compatible. This is why the program can still run normally after the program is copied from one mechanism to another.

Linux standard Base (LSB)

Oh, is that a coincidence? Or something: All Linux programs run on all machines. I also asked this question to find some information.
I 'd like to hear about the POSIX specification and the Linux Standard Base (LSB) specification. At first, I thought LSB was an API specification rather than an ABI specification. When I went deep into the analysis, I found that it is an ABI specification, which solves two problems:

  • Programs running on release Linux A can run on release Linux B.
  • Applications can run on current machines and on new systems and machines in the future.

Recently, the Linux Foundation launched the LSB project to ensure that Linux publishers can be compatible with each other and forward. Solve the portability and compatibility of Linux applications.

LSB is actually the definition of a set of ABI interfaces. It standardizes the binary interfaces of types, macros, variables, and functions required by the runtime environment.

So what is restricted by LSB? That is, the LSB specification has a wide range of constraints. At the beginning, I thought there were only some key components such as kernel and glibc. In fact, when you open the LSB official website, you will find that it is all-encompassing, from the command, ELF, glibc interface, to the desktop, script language, and so on.

Who should comply with LSB specifications

There is no doubt that kernel and glibc should all comply with LSB standards. This is not the case. LSB wants Linux releases (such as RedHat, SUSE, and Ubuntu) to comply with LSB, So it provides LSB test kits and LSB authentication services.

Then, the Kernel and glibc really do not need to consider LSB. The answer is no. The entire kernel/glibc and well-known Linux components are developed in an open-source manner. The technology in it is no longer a secret, and engineers from major companies are involved, all companies want these software to comply with the LSB, so that all software can be easily integrated together, rather than making great efforts to integrate the business. Therefore, all software will try to comply with the LSB specification, but it cannot be ruled out that there are one or two exceptions.

Glibc is one of the most widely used components I know. I found some compatibility analysis on the Internet and found that glibc cannot guarantee forward compatibility of 100%. Not fully compatible occurs in 2.16.0 and 2.13. This compatibility is sufficient for general software.

Backward compatibility

So Can Linux achieve backward compatibility? The answer is no, because LSB cannot be backward compatible.

The problem arises. What if I need to be backward compatible? Assume that the following scenarios exist:

Many servers are Ubuntu 7.04, which was counted as eight years ago. At the same time, there will also be 12.04 servers used, with a small number. However, the 12.04 compiler is newer and supports many security functions. The architect's appeal is: whether the development and compilation can be performed based on the runtime environment of version 12.04, And the generated service program can run on both servers 7.04 and 12.04 at the same time.

Possible solutions:

 
 
  • Find the software running on the Ubuntu 7.04 and 12.04 servers. For the compliant LSB version, the service program can only call the interfaces fully compatible with the two LSB
  • When programming and linking a service program, you can specify the LSB standard used by the Program (LSB of Ubuntu 7.04 ).

For the first method, I personally think it is feasible, but there are many constraints. Method 2 unknown feasible, further analysis

This is a question about backward compatibility. It is not actually backward compatible and relies entirely on forward compatibility.

Postscript

Compatibility is not something I am familiar with, but I have encountered problems at work and made a preliminary analysis. I hope to record my thoughts through blog. One day, I will share with you my in-depth experience on this knowledge. Correct the content if it is incorrect or misleading. Thank you!

On March 11, a typhoon struck Shanghai chanhong

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.