CMake project generation for VLD

Jan 4, 2012 at 4:07 PM

Hello.

I would like to build VLD from source with CMake, as a piece of a larger project.

Problem is, the resulting dll does not work when built with CMake, but one built from the VLD bundled vcxproj file works as intended. I'm using Visual Studio 2010 on Windows 7.

I'm getting errors like:

First-chance exception at 0x0322937b (vld.dll) in test.exe: 0xC00000FD: Stack overflow.
First-chance exception at 0x03229356 (vld.dll) in test.exe: 0xC0000005: Access violation writing location 0x00320ff8.
Unhandled exception at 0x03229356 (vld.dll) in test.exe: 0xC0000005: Access violation writing location 0x00320ff8.
The program '[8388] test.exe: Native' has exited with code -1073741819 (0xc0000005).

and the call stack fills up with

vld.dll!VisualLeakDetector::_HeapAlloc(void * heap=0x03530000, unsigned long flags=8, unsigned long size=21920)  Line 1540 + 0x14 bytes    C++
vld.dll!VisualLeakDetector::_HeapAlloc(void * heap=0x03530000, unsigned long flags=8, unsigned long size=21920)  Line 1538 + 0x6 bytes    C++
...
vld.dll!VisualLeakDetector::_HeapAlloc(void * heap=0x03530000, unsigned long flags=8, unsigned long size=21920)  Line 1540 + 0x14 bytes    C++
The maximum number of stack frames supported by Visual Studio has been exceeded.   

 

I'm guessing this could be due to some compiler or linker flags the I've missed.

This is my CMakeLists.txt, with the flags I've come up with this far:

cmake_minimum_required(VERSION 2.8.6)
file(GLOB_RECURSE LIST_OF_FILES "../*.cpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GF- /Gm- /EHsc /RTC1 /MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /BASE:0x03200000 /DYNAMICBASE:NO")
include_directories(..)
add_definitions(-DUNICODE -D_UNICODE -D_DEBUG -D_USRDLL -DWIN32 -D_WIN32_WINNT=0x0502)                                  
add_library(vld SHARED ${LIST_OF_FILES})

 

Does anyone have any hits or clues of what could be missing?

Thanks.

Jul 3, 2013 at 11:31 AM
Hello.

If I remember right, CMake file actually worked for me in Visual Studio 2008. Your post has motivated me to actually start looking at the source of VLD and to then go ahead and add some features I needed for my own projects:
https://vld.codeplex.com/SourceControl/network/forks/SchoenleAndi/vldwithcheckpoints
If you are still interested, maybe we can go ahead and add the test targets together?

Best,
Andreas
Jul 3, 2013 at 7:38 PM
Hello. Again.

I just encountered the same problem with my 64bit cmake build and found out the reason. With the cmake file above you have been building "vld.dll" instead of "vld_x86.dll" or "vld_x64.dll". This is fine except when patching loaded modules, vld checks for its own module name (which is hardcoded) to avoid patching itself.
So with the above configuration this fails and hence the infinite recursion. The cmake files in my branch should work fine now.

Best,
Andreas