Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does go's compiler "gc" use a different calling convention than C?

Tags:

go

cdecl

C uses the cdecl, which I've looked into and called with from assembly. It feels well enough, so why break the compatibility? Why was another convention needed?

like image 573
galva Avatar asked Mar 31 '13 22:03

galva


People also ask

What calling convention does GCC use?

In Linux, GCC sets the de facto standard for calling conventions. Since GCC version 4.5, the stack must be aligned to a 16-byte boundary when calling a function (previous versions only required a 4-byte alignment). A version of cdecl is described in System V ABI for i386 systems.

What is a calling convention in C?

Calling conventions specify how arguments are passed to a function, how return values are passed back out of a function, how the function is called, and how the function manages the stack and its stack frame. In short, the calling convention specifies how a function call in C or C++ is converted into assembly language.


1 Answers

Because there's no advantage in having the same calling convention. Go code and C code cannot call each other directly even when the calling convention would be the same because Go uses split stacks.

OTOH, it makes sense in gccgo, as gcc supports C split stacks for some architectures. And, IIRC, there the calling convention is because of that compatible. (More details here.)

Disclaimer: I didn't ever actually used gccgo.

like image 169
zzzz Avatar answered Oct 21 '22 18:10

zzzz