I very much doubt that the compiler knows that this is a system call. Most likely, something openis located in the library somewhere, and the code inside the library calls the corresponding kernel interface.
The assembly output from a simple program:
#include <stdio.h>
int main (void) {
int fd = open("xyz");
return 0;
}
(unnecessary bits are deleted):
main:
pushl %ebp ; stack frame setup.
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $.LC0, (%esp) ; Store file name address.
call open ; call the library function.
movl %eax, 28(%esp) ; save returned file descriptor.
movl $0, %eax ; return 0 error code.
leave ; stack frame teardown.
ret
.LC0:
.string "xyz" ; file name to open.
, , open. , . int 80 sysenter, , ( - YMMV).
libc - , .
:
, , , C (libc), glibc. .
, , . API .
" " "syscall" C, , . ( ) (.. CALL ISA). ( , ). , fork execve GLIBC, fork execve.
__open glibc 2.9 io/open.c weakref 'ed open. :
nm /usr/lib/libc.a | egrep 'W __open$|W open$'
:
00000000 W __open
00000000 W open