New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMAKE] cmake.exe v3.5 crashes when building opencv #6370

Closed
amroamroamro opened this Issue Apr 6, 2016 · 3 comments

Comments

4 participants
@amroamroamro
Contributor

amroamroamro commented Apr 6, 2016

I discovered a bug in latest CMake 3.5 that affects OpenCV.

In the file cmake\cl2cpp.cmake, the code attempts to strip comments from *.cl files using some regular expressions.

This was working fine in 3.4.3, until I tried to build OpenCV using the latest CMake 3.5.1... Something must have changed between 3.4.x and 3.5.x, and now cmake itself crashes during the process! It occurs when it reaches the bioinspired module when processing the retina_kernel.cl file.

This was confirmed with cmake 3.5.1, opencv/opencv_contrib 3.1.0, windows 10 (the cmake compilers/generators don't matter). It only manifests on Windows platforms.

After a chat on #cmake, I tracked the issue using the --trace flag to this line:

  string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" ""   lines "${lines}") # multiline comments

Apparently CMake regex-matching is implemented recursively, and that pattern on certain inputs ends up with a call depth too deep running out of stack space and crashing..

To give an example, here is minimal test case that triggers the bug (happens on Windows, Linux cmake didn't crash):

file(READ "C:/opencv_contrib/modules/bioinspired/src/opencl/retina_kernel.cl" lines)
string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}")
file(WRITE out.txt "${lines}")
C:\> cmake -P strip.cmake

Parsing C/C++ code this way using regexps is usually a bad idea. Ideally a proper parser or comment-stripping tool should be used for this task...

For now and as a workaround, we could delete comment lines like //**************** from that file. It makes it easier to regex-match that way, and avoid the recursion error for the moment. :)

amroamroamro added a commit to amroamroamro/opencv that referenced this issue Apr 6, 2016

[CI] update to Octave 4.0.1 builds
This use the included gcc 4.9.3 compiler to compile OpenCV.
Also revert to previous CMake release 3.4.x due to a bug in CMake 3.5.x
that cause it to crash:
opencv#6370

amroamroamro added a commit to amroamroamro/opencv_contrib that referenced this issue Apr 6, 2016

@alalek

This comment has been minimized.

Show comment
Hide comment
@alalek

alalek Apr 7, 2016

Contributor

Actually we trying to minimize a set of 3rdparty dependencies. So I'm not sure that we will use some cross-platform comments stripping tool in the near future.
Thanks for workaround again!

Contributor

alalek commented Apr 7, 2016

Actually we trying to minimize a set of 3rdparty dependencies. So I'm not sure that we will use some cross-platform comments stripping tool in the near future.
Thanks for workaround again!

@alalek alalek closed this Apr 7, 2016

amroamroamro added a commit to amroamroamro/opencv that referenced this issue Apr 7, 2016

[CI] update to Octave 4.0.1 builds
We use MinGW GCC 4.9.3 bundled with Octave to compile OpenCV.

Also revert to CMake 3.4.x due to a bug in CMake 3.5.x
(see opencv/opencv#6370)
@seanlis

This comment has been minimized.

Show comment
Hide comment
@seanlis

seanlis Oct 18, 2016

Contributor

I got the same issue with cmake 3.6.2 under windows.

Contributor

seanlis commented Oct 18, 2016

I got the same issue with cmake 3.6.2 under windows.

@alalek

This comment has been minimized.

Show comment
Hide comment
@alalek

alalek Oct 18, 2016

Contributor

This should be workarounded in upstream.

Contributor

alalek commented Oct 18, 2016

This should be workarounded in upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment