简体   繁体   English

汇编中无法访问的代码

[英]Unreachable code in assembly

I'm debugging a crash in linux, and am going through the assembly of the function cxa_finalize 我正在调试linux中的崩溃,正在通过cxa_finalize函数的汇编

The crash happens on a source line that appears unreachable: 崩溃发生在看起来无法访问的源代码行上:

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)

later on in this method, there is another lea 0x0(%esi,%eiz,1),%esi instruction that appears after a jmp and nop that also appears unreachable. 在此方法的后续步骤中,在jmpnop之后出现了另一个lea 0x0(%esi,%eiz,1),%esi指令,该指令也似乎无法访问。 In that case, the jmp is also exiting a for loop. 在这种情况下, jmp也将退出for循环。

Is there some paradigm going on here that puts in unreachable instructions? 这里是否存在一些无法实现的指令范式?

Edit: Turns out it wasn't crashing on the lea instruction, but on the cmp instruction after it, when accessing the memory at esi . 编辑:事实证明,当访问esi的内存时,它不会在lea指令上崩溃,而是在它之后的cmp指令上崩溃。

I found the answer here 我在这里找到答案

Sometimes GCC inserts NOP instructions into the code stream to ensure proper alignment and stuff like that. 有时,GCC会将NOP指令插入代码流中,以确保正确的对齐方式和类似的东西。 The NOP instruction takes one byte, so you would think that you could just add as many as needed. NOP指令占用一个字节,因此您会认为可以根据需要添加任意数量。 But according to Ian Lance Taylor, it's faster for the chip to execute one long instruction than many short instructions. 但是根据Ian Lance Taylor的说法,芯片执行一条长指令的速度比许多短指令的速度快。 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 因此,与其插入七个NOP指令,不如使用一个bizarro LEA,它占用七个字节,并且在语义上等效于NOP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM