In my vtable i found a method that simply returns ecx. Now im confused as to what this tries to accomplish ? Is this a known useful sequence ?
3 Answers
The C++ compiler of Visual Studio uses ecx
as the default register for this
pointer, a virtual method which returns ecx
then actually returns this
or *this
. For example, you can test the following code:
class A
{
public:
virtual A getmyself() { return *this; }
virtual A* getmyselfpointer() { return this; }
}
The generated assembly code for getmyself
(the same for getmyselfpointer
) is
getmyself:
mov eax, ecx
retn
This detail is not true for clang
or gcc
since they do not use ecx
as default register for this
.
It could be a method that at a high-level is intended to return a covariant object pointer.
If it would be ARM I'd say that it is constructor or destructor (see this answer for more details). As a part of more general pattern I had seen such a things in a multi-platform applications where the main code of the function was #ifdef
'ed out and only return value was left for compatibility with other platforms/build configurations.
Did you see calls to this function?