Tom Taylor
Tom Taylor

Reputation: 3560

What is the difference between ABI and CPU architecture type?

Got confused with ABI and CPU architecture type, by googling I could find this link

https://developer.android.com/ndk/guides/android_mk#target_arch_abi

From which I understood that ABI is the interface which could support (or mapped to) multiple cpu instruction type. CPU architectural types x86, arm32, arm64 types which we speak about are CPU categories and ABI is the interface which the Android provides us to interact with these CPU types. Please correct me if I'm wrong.

Why this interface is needed primarily? And is it possible to compile the same c/c++ code to different architecture types?

Upvotes: 3

Views: 1441

Answers (1)

Margaret Bloom
Margaret Bloom

Reputation: 44116

The ABI standardises how the CPU resources are used and how the a programming language types map into the untyped CPU instructions and memory layouts.
For example, an ABI specifies how the registers are used during a function call, or the layout of a C++ object.
The ISA of a CPU gives the programmer quite a freedom, the ABI is a low-level convention similar to the API convention.

As the ABI is tied to the CPU architecture, different CPUs cannot have the same ABI. However, the term ABI is not absolutely defined: an ABI is a specification and it is entirely possible to write a generic one.
One such example is the Itanium C++ ABI which is reused, with minor addenda, as a base for the C++ ABI in other architectures.

Finally, as there is not a single choice of conventions given a CPU architecture, everyone can write and propose its ABI for that architecture.
It's not rare to have more than one ABI for a CPU, however this freedom is reserved for the people compiling the OS and/or the system libraries.
The end user must conform to the ABI set in place by the OS/Libraries or their binary won't talk the same, low-level, language as the rest of the their system.

Upvotes: 4

Related Questions