Does executable file of C++ program contain object code of system calls also

只谈情不闲聊 提交于 2019-12-24 03:29:58

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31367477/does-executable-file-of-c-program-contain-object-code-of-system-calls-also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!