在32位GCC C程序内嵌64位汇编 [英] Inline 64bit Assembly in 32bit GCC C Program
问题描述
我编译一个32位二进制,但要嵌入一些64位汇编在里面。
I'm compiling a 32 bit binary but want to embed some 64 bit assembly in it.
void method() {
asm("...64 bit assembly...");
}
当然我编译时获得有关指不好的寄存器错误,因为寄存器是64位。
Of course when I compile I get errors about referring to bad registers because the registers are 64 bit.
evil.c:92: Error: bad register name `%rax'
是否有可能增加一些注释,以便将gcc的过程中使用的64位汇编程序,而不是ASM部分。我有一个解决方法是在PROT_EXEC页面单独编译地图| PROT_WRITE,在我的code复制,但这是非常尴尬的。
Is it possible to add some annotations so gcc will process the asm sections using the 64bit assembler instead. I have a workaround which is compile separately, map in a page with PROT_EXEC|PROT_WRITE and copy in my code but this is very awkward.
推荐答案
没有,这是不可能的。不能从一个32位二进制运行64位组件,作为处理器不会在长模式同时运行程序。
No, this isn't possible. You can't run 64-bit assembly from a 32-bit binary, as the processor will not be in long mode while running your program.
复制64位code到一个可执行的页面将导致code是间preTED的错误的32位code,这将有联合国predictable的不良后果。
Copying 64-bit code to an executable page will result in that code being interpreted incorrectly as 32-bit code, which will have unpredictable and undesirable results.
这篇关于在32位GCC C程序内嵌64位汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!