We use Linux system calls like fork()
, pthread()
, signal()
and so on in C or C++ programs and compile the program to generate executable file (a.out). Now my doubt is whether the file a.out contain the object code of all linux system calls used, or whether the executable contain only the calls to system functions and the system call functions are linked during runtime? Suppose if I move my a.out file to some other Linux operating system which implements system calls in different syntax and try to compile it there will it work?
My doubt is whether system call function definitions part of a.out file?
Asked
Active
Viewed 475 times
2

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Charan Chakravarthy
- 21
- 1
-
System calls are system calls, your code (and your executable) just invoke them (with correct parameters). If two different operating system implements the same system calls set, your program is portable, otherwise not. – gengisdave Jul 12 '15 at 12:24
-
The question makes no sense. You don't try to compile `a.out`. It is already compiled. – n. m. could be an AI Jul 12 '15 at 12:46
-
If you already have a compiled executable, it truly has *nothing* to do with syntax. – RamblingMad Jul 12 '15 at 13:04
-
Dear n.m. and coffeeandcode I have an idea that a.out is executable file and i am aware how it is generated. I just asked whether it contains object code of system calls also. Please read the post once again. Thanks for the reply – Charan Chakravarthy Jul 12 '15 at 15:56
1 Answers
4
User space binaries don't contain implementations of system calls. That would mean that any user could inject any code into kernel and take over system.
Instead they need to switch to kernel mode, by using processor interrupt or special instruction. Then processor can execute system call implementation from the kernel.
User space library, such as libc
, is usually used, which provides stubs, which convert arguments of a syscall to a proper protocol and trigger jump to kernel mode. It is usually linked dynamically, so these stubs also don't appear in executable file.

zch
- 14,931
- 2
- 41
- 49
-
-
@CharanChakravarthy, you can mark this as accepted answer if you think it solves your problem. – zch Jul 13 '15 at 09:13