c++ - 程序集中无法访问的代码

标签 c++ c gcc assembly x86

我正在调试 Linux 中的崩溃,并且正在检查函数 cxa_finalize 的汇编

崩溃发生在似乎无法访问的源代码行上:

cmp    %edx,%esi             // f >= &funcs->fns[0]
jae    0xb6e17b88            // enter for loop
jmp    0xb6e17c08            // exit for loop
lea    0x0(%esi,%eiz,1),%esi // crashes here - how do we even get here since there is a 
                             // jmp above us, and nothing jumps to here
cmp    %edi,0xc(%esi)        // d == f->func.cxa.dso_handle (jumped to from below)

稍后在此方法中,还有另一个 lea 0x0(%esi,%eiz,1),%esi jmp 之后出现的指令和 nop这似乎也无法到达。在这种情况下,jmp也正在退出 for 循环。

这里是否有一些范例会放入无法访问的指令?

编辑:事实证明它没有在 lea 上崩溃指令,但在 cmp在它之后的指令,当访问 esi 处的内存时.

最佳答案

我找到了答案 here

Sometimes GCC inserts NOP instructions into the code stream to ensure proper alignment and stuff like that. The NOP instruction takes one byte, so you would think that you could just add as many as needed. But according to Ian Lance Taylor, it’s faster for the chip to execute one long instruction than many short instructions. So rather than inserting seven NOP instructions, they instead use one bizarro LEA, which uses up seven bytes and is semantically equivalent to a NOP

关于c++ - 程序集中无法访问的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37448848/

相关文章:

c++ - std::string 到 uint64_t

c - 新手在编译c代码时出现预期的表达式错误

c - 如何解决链接描述文件中的错误?

c - 如何将标准输入中的字符读入c中的数组?

c++ - 访问类型成员

c++ - 初始化 C++ 线程并稍后运行

c++ - 如何在 Windows 上构建 paho mqtt c++

c - 如何从 c 头文件中提取函数原型(prototype)以实现自动完成功能

c - 如何创建函数,在 C 中没有 typedef 的情况下返回指向另一个函数的指针?

CMAKE/MAKEFILE :/usr/bin/x86_64-linux-gnu-ld : Cannot find -lfftw3f