C ++程序的可执行文件是否还包含系统调用的目标代码 [英] Does executable file of C++ program contain object code of system calls also

查看:96
本文介绍了C ++程序的可执行文件是否还包含系统调用的目标代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Linux系统调用,例如 fork() pthread() signal ()等在 C 或C ++程序中进行编译,以生成可执行文件(a.out)。现在,我的疑问是文件a.out是否包含所使用的所有linux系统调用的目标代码,或者可执行文件是否仅包含对系统函数的调用,并且系统调用函数在运行时链接?假设我将a.out文件移动到其他Linux操作系统中,该文件以不同的语法实现系统调用并尝试对其进行编译,那么它将起作用吗?
我的疑问是系统调用函数定义是否是a.out文件的一部分?

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?

推荐答案

用户空间二进制文件不包含系统调用的实现。那意味着任何用户都可以将任何代码注入内核并接管系统。

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.

通常使用用户空间库,例如 libc ,提供存根,这些存根将syscall的参数转换为适当的协议并触发跳转到内核模式。它通常是动态链接的,因此这些存根也不会出现在可执行文件中。

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.

这篇关于C ++程序的可执行文件是否还包含系统调用的目标代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆