海湾合作委员会NOP指令被编译程 [英] GCC NOPs being compiled away
问题描述
走出去我平时VC ++境界到GCC(通过MINGW32)的世界。试图创建一个Windows PE是由大量的NOP指令,鼻翼:
Venturing out of my usual VC++ realm into the world of GCC (via MINGW32). Trying to create a Windows PE that consists largely of NOPs, ala:
for(i = 0; i < 1000; i++)
{
asm("nop");
}
但无论我使用了错误的语法或编译器是通过它们的优化,因为这些NOP指令没有生存的编译过程。
But either I'm using the wrong syntax or the compiler is optimising through them because those NOPs don't survive the compilation process.
我使用-O0标志,否则默认值。我如何能哄编译任何想法到离开的NOP完好?
I'm using the -O0 flag, otherwise defaults. Any ideas on how I can coax the compiler into leaving the NOPs intact?
推荐答案
您希望它展开循环在1000 NOP
S'我做了一个快速测试与 GCC
,我没有看到(一个) NOP
消失:
Are you expecting it to unroll the loop in to 1000 nop
s? I did a quick test with gcc
and I don't see the (one) nop
disappear:
xorl %eax, %eax
.p2align 4,,7
.L2:
#APP
nop
#NO_APP
addl $1, %eax
cmpl $1000, %eax
jne .L2
使用的gcc -S -O3 -funroll-全循环
我看到它展开循环8次(8因而 NOP
),但我认为如果你想在1000这将是最容易做的:
With gcc -S -O3 -funroll-all-loops
I see it unroll the loop 8 times (thus 8 nop
) but I think if you want 1000 it's going to be easiest to do:
#define NOP10() asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop")
然后用 NOP10(); ...
这篇关于海湾合作委员会NOP指令被编译程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!