[lsb-discuss] Does the standard “Function Calling Sequence” described in Sys V ABI specs (both i386 and AMD64) also applies to the static C functions?

Remus Clearwater remus.clearwater at gmail.com
Fri Dec 28 11:53:32 UTC 2018


I am sure that the standard "Function Calling Sequence" described in Sys V
ABI
specs (both i386 and AMD64) constraints the calling of those extern
functions in
a C library, but does it constraints the calling of those static functions
too?

Here is an example:

```c
$cat abi.c

#include<stdio.h>
typedef void (*ret_function_t)(int,int);
ret_function_t gl_fp = NULL;
static void prnt(int i, int j){
    printf("hi from static prnt:%d:%d\n", i, j);
}
void api_1(int i){
    gl_fp = prnt;
    printf("hi from extern api_1:%d\n", i);
}
ret_function_t api_2(void){
    return gl_fp;
}

$cat abi_main.c

#include<stdio.h>
typedef void (*ret_function_t)(int,int);
extern void api_1(int i);
extern ret_function_t api_2(void);

int main(){
    api_1(1111);
    api_2()(2222, 3333);
}

$gcc abi_main.c abi.c -o abi_test

$./abi_test
hi from extern api_1:1111
hi from static prnt:2222:3333
```

The function calling sequence (including registers usage, stack frame,
parameters
passing, variable arguments...) details are defined in the Sys V ABI when
abi_main.c
call the api_1 and api_2 since they are extern, but what about the calling
of the static
function prnt which been defined in abi.c? Does it belong to the ABI
standard or to the
compiler to decide?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfoundation.org/pipermail/lsb-discuss/attachments/20181228/466b4714/attachment.html>


More information about the lsb-discuss mailing list