I have been "reverse engineering" some of my own libraries to learn more about compiler optimizations. I have seen one of my simplest class constructors (a 4-D vector) get compiled to the following:
fldz ; push +0.0 to FPU stack
mov eax, ecx ; set eax to this (ecx)
mov dword ptr [eax], offset data_??_7vector_t@data@@6B@ ; what is this doing?
fst dword ptr [eax+4] ; assign this->first
fst dword ptr [eax+8] ; assign this->second
fst dword ptr [eax+0Ch] ; assign this->third
fstp dword ptr [eax+10h] ; assign this->fourth, pop FPU stack
retn ; return this (eax)
On the third line, I have no clue what this is doing. I originally thought it might be some kind of optimization that is referencing some hard coded block of constant data.
In order to determine what it might be, I loaded the DLL into a container process and then attached a debugger and viewed the data at the location of data??_7vector_t@data@@6B@
, but it was just db offset unk??_7vector_t@data2@@6B@
. I followed that second label and there was a region of data which didn't correspond to anything I recognized in my project, even after converting the first 8 bytes into a double.
The compiler I'm using is MSVC++ with Visual Studio 2013 with full optimization without any advanced instruction sets (SSE, etc is turned off).
What C++ code would generate the instruction in question?
有问题的行是为正在构造的对象分配一个vtable指针。
Looks to me like it is applying a constructor to the uninitialized storage at ECX.
The steps of that would insert a vtable pointer in its first slot, and zero the 4d vector you say your application uses.
Not sure where the data_
prefix comes from, but the ?
is the standard marker of decorated (mangled) names and you can use the undname
tool to decipher them:
>undname ??_7vector_t@data@@6B@
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.
Undecoration of :- "??_7vector_t@data@@6B@"
is :- "const data::vector_t::`vftable'"
So yes, it's just initializing the vtable pointer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.