1

I know that there many questions about ABI on here but it's still something that I don't fully understand.

Someone told me recently that when people used to write Pascal and then C became more popular, there were issues or confusion because Pascal when compiled would push function parameters on the stack in the reverse order to C. I questioned that should that not depend on the target platform rather than the program language. Is it not the ABI that would determine this? Isn't the ABI developed by the Operating System developers and not dependant on the programming language?

Sorry if the question is long. It's just something I can't get my head around. I'm trying to understand fully what goes on behind the scenes rather than just being able to write code. Thanks in advance for any help.

Engineer999
  • 3,683
  • 6
  • 33
  • 71
  • possible duplicate of [What is Application Binary Interface (ABI)?](http://stackoverflow.com/questions/2171177/what-is-application-binary-interface-abi) –  May 20 '15 at 19:47
  • Nope, the ABI is determined by the compiler used (which may actually just be conforming to the language specification). – user4520 May 20 '15 at 19:54
  • It states there that ABIs are provided by the same people designing the platform. Is there not just one ABI for the platform or many different ABIs for the different compilers? For example, on Linux if I have GCC and then a different compiler for Pascal, there will be two different ABIs? Do the ABIs come with the compiler? – Engineer999 May 20 '15 at 20:25
  • 2
    Platform-defined ABI is only for the invocation of services of that platform. Internally, each language/compiler are free to do whatever their creators like. – void_ptr May 20 '15 at 21:22
  • Note that some aspects of platform services invocations (like SEH) go beyond the direct calling code. – Marco van de Voort May 21 '15 at 13:30

3 Answers3

1

ABI is not monopoly of OS vendors. Programs may be deployed as firmware, and even OSs are collections of programs. So calling convention, that as you suggest can be considered part of ABI specification, is selected by compilation tool chain vendors for HLL (or by programmer for assembly language). For computers that are used via OSs, developers making apps require linking their programs with OS libraries. If these libraries are built with one calling convention when deployed as part of OS, then compiler switches or other such mechanisms take care for targeting the OS. So, OS vendors have a say in specifying the ABI.

Chawathe Vipul S
  • 1,636
  • 15
  • 28
0

You may have a couple of concepts unnecessarily conjoined. In it's simplest form an OS provides a framework to run programs. ABIs are concrete instances of APIs (Application Programming Interface). A IoT device might not have an OS (it may simply run a single program) but will use ABIs. Different systems and compilers will create different ABIs. The order in which parameters are passed on the stack is just one of these differences. Compilers often try to place data in on-processor registers to avoid using the stack (for performance). The stack itself is generally little more than a special register on the processor that is incremented and decremented appropriately. Other things important for ABIs are byte order (big/little endian), bitness (the size of basic data types) and who is in charge of stack housekeeping (does the caller or callee adjust the stack address). Generally, the nature of an ABI is decided mostly by what is convenient based on the architecture of the machine.

Dweeberly
  • 4,668
  • 2
  • 22
  • 41
0

The purpose of an ABI is to allow code developed using development tools (compiler/linker/etc) from different suppliers to work together. There aren't any hard and fast rules such as "ABI's are developed by operating system vendors". An ABI is just a document that can be followed or ignored.

I've seen an ABI specification from Intel for their x86 processors, and if I remember correctly they were language specific (or maybe portions of them were language specific). ABI's will usually be language specific because programming languages have different features and, and the most obvious/efficient ways to support these features will be language specific.

This blog post The history of calling conventions goes into more detail.

Stuart
  • 1,428
  • 11
  • 20