Visual Studio 2010 optimized code bug
-
Hi, Using the GetProcAdress I wanted to get the exported address of a function When it returned zero I double checked with depends.exe to ensure the function was exported I then went to assembly mode to see what happens and noticed that after the call statement a value was returned in the RAX register but there wasn't any code to move the RAX register value to my FARPROC data member I then turned optimization off #pragma optimize("",off) and the same code generated "mov FARPROC,rax" am I missing some compiler to flag to make this happen without turning optimization off Thanks Thanks
-
Hi, Using the GetProcAdress I wanted to get the exported address of a function When it returned zero I double checked with depends.exe to ensure the function was exported I then went to assembly mode to see what happens and noticed that after the call statement a value was returned in the RAX register but there wasn't any code to move the RAX register value to my FARPROC data member I then turned optimization off #pragma optimize("",off) and the same code generated "mov FARPROC,rax" am I missing some compiler to flag to make this happen without turning optimization off Thanks Thanks
It would help if you could post the code in your function and some of the generated assembly code.
«_Superman_» _I love work. It gives me something to do between weekends.
-
It would help if you could post the code in your function and some of the generated assembly code.
«_Superman_» _I love work. It gives me something to do between weekends.
Here it is HMODULE hutil_module; FARPROC hercgui_addr; hutil_module = GetModuleHandle("HENGINE"); With #pragma optimize("",off) hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 000000005178D4BC lea rdx,[string "hercgui_proc" (518672B0h)] 000000005178D4C3 mov rcx,qword ptr [rsp+0E0h] 000000005178D4CB call qword ptr [__imp_GetProcAddress (5184A050h)] 000000005178D4D1 mov qword ptr [rsp+0C0h],rax with optimization on hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 00000000514CD44B lea rdx,[string "hercgui_proc" (515A42B0h)] 00000000514CD452 mov rcx,rax 00000000514CD455 call qword ptr [__imp_GetProcAddress (51587050h)] Thanks
-
Here it is HMODULE hutil_module; FARPROC hercgui_addr; hutil_module = GetModuleHandle("HENGINE"); With #pragma optimize("",off) hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 000000005178D4BC lea rdx,[string "hercgui_proc" (518672B0h)] 000000005178D4C3 mov rcx,qword ptr [rsp+0E0h] 000000005178D4CB call qword ptr [__imp_GetProcAddress (5184A050h)] 000000005178D4D1 mov qword ptr [rsp+0C0h],rax with optimization on hercgui_addr = GetProcAddress(hutil_module,"hercgui_proc"); 00000000514CD44B lea rdx,[string "hercgui_proc" (515A42B0h)] 00000000514CD452 mov rcx,rax 00000000514CD455 call qword ptr [__imp_GetProcAddress (51587050h)] Thanks
Do you actually use
hercgui_addr
later in the code? I find that if I'm looking at optimized assembly output that if I don't actually use the value for something, the extra processing code can get discarded. At a minimum, you can dump the value to console or screen to make sure the code remains in the optimized assembly output.
-
Do you actually use
hercgui_addr
later in the code? I find that if I'm looking at optimized assembly output that if I don't actually use the value for something, the extra processing code can get discarded. At a minimum, you can dump the value to console or screen to make sure the code remains in the optimized assembly output.
This is the next statement strncpy(&herc_parm[0],&hercgui_addr,8); I am running X64 I send thid address to child process
return\_code = CreateProcess((LPCSTR) &herc\_command\[0\], // command (LPCSTR) &herc\_parm\[0\], // paramter (LPCSTR) &sa, NULL, TRUE, (DWORD) NULL, NULL, NULL, &si, &pi);
Later in the child process I Create a Remote thread with the parent
snap_shot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
process32.dwSize = sizeof(PROCESSENTRY32);
return_cde = Process32First(snap_shot,&process32);
pid = GetCurrentProcessId(); // Get Current process id
while(pid != process32.th32ProcessID)
{
return_cde = Process32Next(snap_shot,&process32);
}herc_process = process32.th32ParentProcessID;
my_herc = OpenProcess(PROCESS_ALL_ACCESS,FALSE,herc_process); // Get a Handle to
if (my_herc == NULL)
errcd= GetLastError();SECURITY_ATTRIBUTES sa;
LPVOID lparam;
DWORD threadid;sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; lparam = NULL; CreateRemoteThread(my\_herc, &sa, NULL, (LPTHREAD\_START\_ROUTINE) hercgui, lparam, NULL, &threadid);
-
Hi, Using the GetProcAdress I wanted to get the exported address of a function When it returned zero I double checked with depends.exe to ensure the function was exported I then went to assembly mode to see what happens and noticed that after the call statement a value was returned in the RAX register but there wasn't any code to move the RAX register value to my FARPROC data member I then turned optimization off #pragma optimize("",off) and the same code generated "mov FARPROC,rax" am I missing some compiler to flag to make this happen without turning optimization off Thanks Thanks
-
ForNow wrote:
When it returned zero I double checked with depends.exe to ensure the function was exported
Did you actually check what error was being generated, as described in the function's documentation[^]?
Richard look at what happens When I turn optimazation off and check for an error no code is generated for the if (hercgui_addr = NULL) one wierd complier On aonther issue my assignment at work I was able to resolve the 800A30EC I think thats it by Doing app.GetActiveWorkBook however txt file wasn't displayed in the workbook in fact a worksheet wasn't loaded I was under the impression that OpenText loads a worksheet as well Thanks
hercgui\_addr = GetProcAddress(hutil\_module,"hercgui\_proc");
00000000013FD44B lea rdx,[string "hercgui_proc" (14D42B0h)]
00000000013FD452 mov rcx,rax
00000000013FD455 call qword ptr [__imp_GetProcAddress (14B7050h)]if (hercgui\_addr = NULL) errcd = GetLastError();
-
Richard look at what happens When I turn optimazation off and check for an error no code is generated for the if (hercgui_addr = NULL) one wierd complier On aonther issue my assignment at work I was able to resolve the 800A30EC I think thats it by Doing app.GetActiveWorkBook however txt file wasn't displayed in the workbook in fact a worksheet wasn't loaded I was under the impression that OpenText loads a worksheet as well Thanks
hercgui\_addr = GetProcAddress(hutil\_module,"hercgui\_proc");
00000000013FD44B lea rdx,[string "hercgui_proc" (14D42B0h)]
00000000013FD452 mov rcx,rax
00000000013FD455 call qword ptr [__imp_GetProcAddress (14B7050h)]if (hercgui\_addr = NULL) errcd = GetLastError();
-
if (hercgui_addr = NULL)
This sets the value of
hercgui_addr
toNULL
, so it is little wonder that the generated code does not look correct.