0

In order to get the length of functions, I'm using empty functions to mark where each function ends, like so:

void f()
{
    printf("ooga\n");
}
__declspec(noinline, naked) void f_end() { __asm { nop } };

To get the length of f, I just subtract f_end - f, decrementing for any INT3 used as padding.

But if I add another function:

void g()
{
    printf("booga\n");
}
__declspec(noinline, naked) void g_end() { __asm { nop } };

the f_end() and g_end() appears to be merged into one single function (verified by looking at the disassembly in OllyDbg). If I make each function unique it won't happen, but I'll be needing a ton of these.

Is there any optimization switch I can flick to prevent this from happening?

I've skimmed through the settings available in the Visual Studio menus (had to set /OPT:NOREF in order for the f_end and g_end to not be skipped altogether) and tried optimize("", off) to no avail.

Thanks

4

2 回答 2

2

/OPT:NOICF可能是您正在寻找的设置。它告诉编译器不要折叠(合并)相同的comdat。

于 2013-06-09T21:10:53.840 回答
1

这是一种使事情变得更容易的方法,而无需担心编译器:

#define FUNC_END(funcname)                             \
__declspec(noinline, naked) void funcname ## _end () { \
    funcname ## _end();                                \
}
于 2013-06-09T20:22:40.543 回答