Discussion:
[CMake] CMake, Mingw-w64 32 bit exception handling.
Arne Kjetil Andersen
2017-08-23 08:55:55 UTC
Permalink
Greetings.

I'm a developer on a fairly large project where I'm using CMake version
3.9.1

I primarily work on linux, but also cross compiles for windows using
Mingw-w64 on my linux box.

I have encountered an issue which I'm having some trouble figuring out.
Running through some of my tests where an exception is thrown (on purpose)
the 32 bit version compiled with Mingw-w64-g++ version 7.1.1 just calls
terminate even though there are try catch blocks. Now mind you, this all
works fine on the native linux compiled version of my tests, and also the
64 bit windows version compiled with Mingw-w64-g++ version 7.1.1.

Going through all the projects CMakeLists.txt I could not find any reason
for this behavior, but tried to add -fexceptions as a compiler option in
the top most CMakeLists.txt file for the 32 bit mingw-w64 compiler.
Unfortunately this made no difference.

So investigating some more I took a look at the linklibs.rsp file generated
for that particular test executable, and noticed this entry:
-lgcc_eh -lgcc_eh

(yes it's twice, but that is not the issue, although that might be a cmake
bug?).
(also note - this option is also present for the 64 bit build files for
mingw-w64, but there it works as expected).

Now, removing those two library link options from the linklibs.rsp file
makes the 32 bit windows version of test application work as expected. I am
not sure what libgcc_eh.a actually does (tried searching for some
information, but had little luck actually figuring that out), but clearly
it has something to do with exception handling.

Now I figured I would create a small minimal example that would reproduce
this issue outside my projects source tree. So basically created a small
program that throws an exception, and catches that. Created a
CMakeLists.txt file with the same general options as my farily large
project, and had cmake generate the build files for 32 bit mingw-w64.
Inspecting the linklibs.rsp file I was surprised to see that "-lgcc_eh"
were nowhere to be found, and as such the 32 bit version of this test
worked fine.

So, my question is, does anyone know under which circumstances cmake will
add -lgcc_eh to linklibs.rsp, and is there any way I can prevent cmake from
doing so for the 32 bit mingw-w64 compiler?

Also, maybe I'm going about this issue the wrong way, and that my findings
mentioned above is not a good way of handling this. Or maybe this might be
a bug with the 32 bit mingw-w64 compiler?

I should probably also mention that the 32 bit version of Mingw-w64 uses
the sjlj exception handling mechanism.

Any help and pointers would be greatly appreciated - cause adding a step in
the developer documentation to go into the linklibs.rsp file to remove
-lgcc_eh is kind of a last resort.

Thanks for any input on this matter, and please let me know if attaching
CMakeOutput.log or other files would be beneficial.

Best Regards,
Arne Kjetil Andersen
Robert Maynard
2017-08-23 19:57:51 UTC
Permalink
A quick scan of CMake source code shows that we don't have any
references to gcc_eh anywhere. I way this could be occurring is
through CMake detection of the implicit libraries that a compiler
requires for each language. In particular it could be that C code for
mingw by default uses gcc_eh while C++ doesn't. The culprit could also
be a FindPackage* you are using.
Post by Arne Kjetil Andersen
Greetings.
I'm a developer on a fairly large project where I'm using CMake version
3.9.1
I primarily work on linux, but also cross compiles for windows using
Mingw-w64 on my linux box.
I have encountered an issue which I'm having some trouble figuring out.
Running through some of my tests where an exception is thrown (on purpose)
the 32 bit version compiled with Mingw-w64-g++ version 7.1.1 just calls
terminate even though there are try catch blocks. Now mind you, this all
works fine on the native linux compiled version of my tests, and also the 64
bit windows version compiled with Mingw-w64-g++ version 7.1.1.
Going through all the projects CMakeLists.txt I could not find any reason
for this behavior, but tried to add -fexceptions as a compiler option in the
top most CMakeLists.txt file for the 32 bit mingw-w64 compiler.
Unfortunately this made no difference.
So investigating some more I took a look at the linklibs.rsp file generated
-lgcc_eh -lgcc_eh
(yes it's twice, but that is not the issue, although that might be a cmake
bug?).
(also note - this option is also present for the 64 bit build files for
mingw-w64, but there it works as expected).
Now, removing those two library link options from the linklibs.rsp file
makes the 32 bit windows version of test application work as expected. I am
not sure what libgcc_eh.a actually does (tried searching for some
information, but had little luck actually figuring that out), but clearly it
has something to do with exception handling.
Now I figured I would create a small minimal example that would reproduce
this issue outside my projects source tree. So basically created a small
program that throws an exception, and catches that. Created a CMakeLists.txt
file with the same general options as my farily large project, and had cmake
generate the build files for 32 bit mingw-w64. Inspecting the linklibs.rsp
file I was surprised to see that "-lgcc_eh" were nowhere to be found, and as
such the 32 bit version of this test worked fine.
So, my question is, does anyone know under which circumstances cmake will
add -lgcc_eh to linklibs.rsp, and is there any way I can prevent cmake from
doing so for the 32 bit mingw-w64 compiler?
Also, maybe I'm going about this issue the wrong way, and that my findings
mentioned above is not a good way of handling this. Or maybe this might be a
bug with the 32 bit mingw-w64 compiler?
I should probably also mention that the 32 bit version of Mingw-w64 uses the
sjlj exception handling mechanism.
Any help and pointers would be greatly appreciated - cause adding a step in
the developer documentation to go into the linklibs.rsp file to remove
-lgcc_eh is kind of a last resort.
Thanks for any input on this matter, and please let me know if attaching
CMakeOutput.log or other files would be beneficial.
Best Regards,
Arne Kjetil Andersen
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://public.kitware.com/mailman/listinfo/cmake
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Arne Kjetil Andersen
2017-08-24 08:13:55 UTC
Permalink
Post by Robert Maynard
A quick scan of CMake source code shows that we don't have any
references to gcc_eh anywhere. I way this could be occurring is
through CMake detection of the implicit libraries that a compiler
requires for each language. In particular it could be that C code for
mingw by default uses gcc_eh while C++ doesn't. The culprit could also
be a FindPackage* you are using.
Hi Robert and thanks for your reply. Yes I also did a scan of the cmake
source code before sending the mail to the mailing list, and found no
reference to gcc_eh. But I do find reference to that in the CMakeOutput.log
file, and it seems to come from detection of implicit libraries. So based
on this i started by removing all 3rd party libraries in my project and
thought of adding one by one until the -lgcc_eh appeared in the
linklibs.rsp, and you are right, adding proj.4 3rd party library to the
build system seems to result in -lgcc_eh being added... Now to figure out
how to prevent that from occurring in linklibs.rsp file for the test
application that does not even use that particular 3rd party library.

Thanks again for pointing me in the right direction.

Best Regards,
Arne Kjetil Andersen
Post by Robert Maynard
Post by Arne Kjetil Andersen
Greetings.
I'm a developer on a fairly large project where I'm using CMake version
3.9.1
I primarily work on linux, but also cross compiles for windows using
Mingw-w64 on my linux box.
I have encountered an issue which I'm having some trouble figuring out.
Running through some of my tests where an exception is thrown (on
purpose)
Post by Arne Kjetil Andersen
the 32 bit version compiled with Mingw-w64-g++ version 7.1.1 just calls
terminate even though there are try catch blocks. Now mind you, this all
works fine on the native linux compiled version of my tests, and also
the 64
Post by Arne Kjetil Andersen
bit windows version compiled with Mingw-w64-g++ version 7.1.1.
Going through all the projects CMakeLists.txt I could not find any reason
for this behavior, but tried to add -fexceptions as a compiler option in
the
Post by Arne Kjetil Andersen
top most CMakeLists.txt file for the 32 bit mingw-w64 compiler.
Unfortunately this made no difference.
So investigating some more I took a look at the linklibs.rsp file
generated
Post by Arne Kjetil Andersen
-lgcc_eh -lgcc_eh
(yes it's twice, but that is not the issue, although that might be a
cmake
Post by Arne Kjetil Andersen
bug?).
(also note - this option is also present for the 64 bit build files for
mingw-w64, but there it works as expected).
Now, removing those two library link options from the linklibs.rsp file
makes the 32 bit windows version of test application work as expected. I
am
Post by Arne Kjetil Andersen
not sure what libgcc_eh.a actually does (tried searching for some
information, but had little luck actually figuring that out), but
clearly it
Post by Arne Kjetil Andersen
has something to do with exception handling.
Now I figured I would create a small minimal example that would reproduce
this issue outside my projects source tree. So basically created a small
program that throws an exception, and catches that. Created a
CMakeLists.txt
Post by Arne Kjetil Andersen
file with the same general options as my farily large project, and had
cmake
Post by Arne Kjetil Andersen
generate the build files for 32 bit mingw-w64. Inspecting the
linklibs.rsp
Post by Arne Kjetil Andersen
file I was surprised to see that "-lgcc_eh" were nowhere to be found,
and as
Post by Arne Kjetil Andersen
such the 32 bit version of this test worked fine.
So, my question is, does anyone know under which circumstances cmake will
add -lgcc_eh to linklibs.rsp, and is there any way I can prevent cmake
from
Post by Arne Kjetil Andersen
doing so for the 32 bit mingw-w64 compiler?
Also, maybe I'm going about this issue the wrong way, and that my
findings
Post by Arne Kjetil Andersen
mentioned above is not a good way of handling this. Or maybe this might
be a
Post by Arne Kjetil Andersen
bug with the 32 bit mingw-w64 compiler?
I should probably also mention that the 32 bit version of Mingw-w64 uses
the
Post by Arne Kjetil Andersen
sjlj exception handling mechanism.
Any help and pointers would be greatly appreciated - cause adding a step
in
Post by Arne Kjetil Andersen
the developer documentation to go into the linklibs.rsp file to remove
-lgcc_eh is kind of a last resort.
Thanks for any input on this matter, and please let me know if attaching
CMakeOutput.log or other files would be beneficial.
Best Regards,
Arne Kjetil Andersen
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://public.kitware.com/mailman/listinfo/cmake
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
Brad King
2017-11-06 19:59:38 UTC
Permalink
Post by Arne Kjetil Andersen
result in -lgcc_eh being added...
The cause has been identified and reported here:

https://gitlab.kitware.com/cmake/cmake/issues/17436

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...