I'm writing some low level code and I noticed some unnecessary level of indirection of a function call and I simply don't get what's the reason for that indirection. Here's dummy code that reveals that behavior:
__declspec(noinline) int get_alignment(void * ptr)
{
return 1;
}
__declspec(noinline) int test123()
{
char buf[123];
return get_alignment(buf);
}
Then, when I step through the code inside function test() in debugger in asm mode (Ctrl+F11) I see this:
__declspec(noinline) int test123() { 0041FA70 sub esp,7Ch char buf[123]; return get_alignment(buf); 0041FA73 lea eax,[esp] 0041FA76 push eax 0041FA77 call get_alignment (40A38Fh) } ... get_alignment: 0040A38F jmp get_alignment (41FA60h) ... __declspec(noinline) int get_alignment(void * ptr) { return 1; 0041FA60 mov eax,1 }
So, the question is about that extra level of indirection: get_alignment: 0040A38F jmp get_alignment (41FA60h)
WTF is that about?! I just don't get it, it's not imported function from dll, it's a local function defined in executable. This executable compiled with all kinds of optimizations (except link time code generation).
If I add static
to the declaration of that get_alignment, then that extra indirection disappears. But I'm not looking for a "fix", I just wanted to understand why is that extra jump is there at all!
In my real app I actually use a function written in .asm file and I just don't get why there is extra jump generated. It seems that If I compile my code in C-mode (not C++) then I don't see that level of indirection anymore...
anybody can shed some light on that weird behavior?
Thank you!