linux运行asm文件,程序启动时(asm,linux)的默认寄存器状态是什么?

小编典典

这完全取决于每个平台的ABI。既然您提到了eax,ebx让我们看看x86的情况是什么。在fs/binfmt_elf.c内部的#972行中load_elf_binary(),内核检查ABI

在程序加载时是否对寄存器值指定了任何要求:

/*

* The ABI may specify that certain registers be set up in special

* ways (on i386 %edx is the address of a DT_FINI function, for

* example. In addition, it may also specify (eg, PowerPC64 ELF)

* that the e_entry field is the address of the function descriptor

* for the startup routine, rather than the address of the startup

* routine itself. This macro performs whatever initialization to

* the regs structure is required as well as any relocations to the

* function descriptor entries when executing dynamically links apps.

*/

然后调用ELF_PLAT_INIT,这是为中的每个体系结构定义的宏arch/xxx/include/elf.h。对于x86,它执行以下操作:

#define ELF_PLAT_INIT(_r, load_addr) \

do { \

_r->bx = 0; _r->cx = 0; _r->dx = 0; \

_r->si = 0; _r->di = 0; _r->bp = 0; \

_r->ax = 0; \

} while (0)

因此,当您将静态链接的ELF二进制文件加载到Linux x86上时,您可以指望所有等于零的寄存器值。不过,这并不意味着您应该这样做。:-)

动态链接

请注意,执行 动态 链接的二进制文件实际上会在执行到达您的_start(ELF入口点)之前在您的进程中运行动态链接程序代码。

这可以并且确实在ABI的允许下在寄存器中留下垃圾。 当然,除了堆栈指针ESP / RSP和atexit挂钩EDX / RDX。

2020-06-03

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值