以下内联程序集有什么问题
What is wrong with the following inline assembly?
当我尝试编译以下内容时,gcc 失败
错误:"ASM"中的操作数约束不一致"
不幸的是,当我将函数拉入独立文件时,它可以很好地编译,所以我真的不确定问题是什么。该函数背后的想法是围绕在汇编中编写的函数提供一个包装器,该包装器将强制实施预期的调用约定,而不考虑目标平台。
int wrap(int(*asmfn)(int,int,int,int), int param1, int param2, int param3, int param4) {
int x;
asm ( "push %1;" //save the input operand so it's not clobbered
"push %5;" //push the params RTL
"push %4;"
"push %3;"
"push %2;"
"call *%1;" //call the function
"pop %2;" //caller cleanup / restore the param operands so they are not clobbered
"pop %3;"
"pop %4;"
"pop %5;"
"pop %1;" //restore the other operand so it's not clobbered
"mov %%eax, %0;" //save the retval to a local
: "=X" (x)
: "c" (asmfn), "d" (param1), "b" (param2), "S" (param3), "D" (param4)
: "cc", "memory", "%eax" );
return x;
}
我尝试将输出操作数约束到仅内存或寄存器中,甚至将其专门约束到eax
并从 clobber 列表中删除"%eax",但无论哪种方式我都遇到相同的错误。我错过了什么?
经过多次实验,我意识到了这个问题以及为什么它在独立时不会导致错误:这是在代码中被编译成共享对象,因此启用了"-fPIC"。这导致 gcc 使用 ebx
在函数入口处存储当前eip
,以便它可以通过函数的相对偏移量(在编译时已知)找到 GOT,以便代码可以独立于位置。因此,PIC 中任何使用 ebx
作为操作数的内联程序集都会给出这个完全不透明的错误。
相关文章:
- 警告处理为错误这里有什么问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 当我尝试添加 2 个大字符串时,我无法弄清楚出了什么问题
- 违反const正确性:我应该现实地期待什么问题
- 这个带有模板<类 Vector 的C++代码片段有什么问题>
- 我的逻辑反转字符串中的元音有什么问题?
- 需要以下代码的帮助,下面的代码有什么问题
- 常量公共成员有什么问题?
- 以下代码中的函数模板有什么问题?
- 这个返回元素位置的基于循环的函数有什么问题?
- creat_list2功能有什么问题?
- 格式说明符C++有什么问题
- 任何人都可以告诉我我的 C++ 代码出了什么问题?
- 从 argv[1] 转换为字符 * 字符串后有什么问题?
- 我的堆栈和库存清单程序的结构有什么问题?
- 此工厂功能有什么问题?
- 以下 C++ 代码有什么问题?
- 数组为此合并排序函数提供了正确的输出,但向量给出了不正确的输出.出了什么问题?
- reinterpret_cast,只读访问,简单的可复制类型,会出什么问题?
- 它解决了什么问题,对于非真空初始化,生命周期在初始化之前就开始了